Created
January 29, 2016 18:16
-
-
Save dgodfrey206/1147471ec984d84211d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <utility> | |
#include <tuple> | |
namespace detail { | |
template<class... Args> | |
struct stream_bump { | |
std::tuple<Args...> args; | |
template<class F> | |
void operator->*(F&& f) && { | |
call_impl(std::forward<F>(f), std::make_index_sequence<sizeof...(Args)>{}); | |
} | |
private: | |
template<class F, std::size_t... Is> | |
void call_impl(F&& f, std::index_sequence<Is...>) { | |
using ints=int[]; | |
(void)ints{0, | |
(std::forward<F>(f)(std::get<Is>(args)), void(), 0)... | |
}; | |
} | |
}; | |
} | |
template<class... Args> | |
detail::stream_bump<std::decay_t<Args>...> stream_bumper(Args&&... args) { | |
return {std::make_tuple(std::forward<Args>(args)...)}; | |
} | |
int main() { | |
stream_bumper(1, 2, 3) ->* [&](auto x) { std::cout << x << " "; }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment