#ifndef SPROUT_TUPLE_FUSED_HPP #define SPROUT_TUPLE_FUSED_HPP #include #include #include #include #include #include namespace sprout { namespace tuples { // // fused // template class fused { public: typedef F functor_type; private: template struct result_impl; template struct result_impl > { public: typedef decltype( std::declval()( sprout::tuples::get(std::declval())... ) ) type; }; public: template struct result : public result_impl< Tuple, typename sprout::index_range<0, sprout::tuples::tuple_size::type>::value>::type > {}; private: functor_type f_; private: template SPROUT_CONSTEXPR Result call(Tuple&& t, sprout::index_tuple) const { return f_(sprout::tuples::get(sprout::forward(t))...); } public: fused() = default; fused(fused const&) = default; explicit SPROUT_CONSTEXPR fused(F f) : f_(f) {} SPROUT_CONSTEXPR functor_type functor() const { return f_; } template SPROUT_CONSTEXPR typename result::type operator()(Tuple&& t) const { return call::type>( sprout::forward(t), sprout::index_range<0, sprout::tuples::tuple_size::type>::value>::make() ); } }; // // make_fused // template inline SPROUT_CONSTEXPR sprout::tuples::fused make_fused(F const& f) { return sprout::tuples::fused(f); } } // namespace tuples using sprout::tuples::fused; using sprout::tuples::make_fused; } // namespace sprout #endif // #ifndef SPROUT_TUPLE_FUSED_HPP