40 template <
typename ResultT,
typename ArgT>
41 auto from_any_state(ArgT&& s)
42 -> estd::enable_if_t<std::is_same<estd::decay_t<ArgT>, any_state>{},
43 estd::decay_t<ResultT> >
45 return std::forward<ArgT>(s).
template as<ResultT>();
48 template <
typename ResultT,
typename ArgT>
49 auto from_any_state(ArgT&& s)
50 -> estd::enable_if_t<!std::is_same<estd::decay_t<ArgT>, any_state>{},
53 return std::forward<ArgT>(s);
58 template <
typename ReducingFnT,
60 typename ...InputRangeTs>
61 auto reduce(ReducingFnT&& step, StateT&& state, InputRangeTs&& ...ranges)
62 -> estd::decay_t<StateT>
65 return detail::from_any_state<StateT>(
66 xform::detail::is_non_empty(ranges...)
68 xform::detail::reduce_nested_non_empty(
69 std::forward<ReducingFnT>(step),
70 std::forward<StateT>(state),
71 std::forward<InputRangeTs>(ranges)...))
72 :
std::forward<StateT>(state));
73 }
catch (reduce_aborted_error<estd::decay_t<StateT> >& err) {
74 return std::move(err.result);
75 }
catch (reduce_aborted_error<any_state>& err) {
76 return std::move(err.result).as<StateT>();
C++ amazing templates and reusable implementations awesomeness.