Skip to content

Instantly share code, notes, and snippets.

@picanumber
Last active March 22, 2016 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save picanumber/ef63a1848c5189274fea to your computer and use it in GitHub Desktop.
Save picanumber/ef63a1848c5189274fea to your computer and use it in GitHub Desktop.
template <class F, class... Ts>
struct O_Om
{
std::tuple<Ts...> nodes;
gut::member_result_t<F, decltype(std::get<1>(nodes).clone()),
decltype(std::get<0>(nodes).clone())> state;
template <class A, class... Us>
constexpr O_Om(A&& state, Us&&... args)
: nodes{fw(args)...}, state{fw(state)}
{
}
/* nested iterator type here */
iterator begin() { return iterator(state, 0, nodes); }
iterator end() { return iterator(state, sizeof...(Ts), nodes); }
constexpr decltype(auto) yield()
{
for (std::size_t i(1); i < sizeof...(Ts); ++i)
{
state = vtu::call_with_tuple_element_first(
F{}, nodes, i, state);
}
return state;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment