Skip to content

Instantly share code, notes, and snippets.

@dgodfrey206
Created January 29, 2016 18:16
Show Gist options
  • Save dgodfrey206/1147471ec984d84211d5 to your computer and use it in GitHub Desktop.
Save dgodfrey206/1147471ec984d84211d5 to your computer and use it in GitHub Desktop.
#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