2012-05-31 13:28:58 +00:00
|
|
|
#ifndef SPROUT_TUPLE_FUSED_HPP
|
|
|
|
#define SPROUT_TUPLE_FUSED_HPP
|
|
|
|
|
2012-07-18 13:15:59 +00:00
|
|
|
#include <utility>
|
2012-05-31 13:28:58 +00:00
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/index_tuple.hpp>
|
2013-02-07 15:49:47 +00:00
|
|
|
#include <sprout/tuple/tuple/tuple.hpp>
|
|
|
|
#include <sprout/tuple/tuple/get.hpp>
|
2012-05-31 13:28:58 +00:00
|
|
|
#include <sprout/utility/forward.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace tuples {
|
|
|
|
//
|
|
|
|
// fused
|
|
|
|
//
|
|
|
|
template<typename F>
|
|
|
|
class fused {
|
|
|
|
public:
|
|
|
|
typedef F functor_type;
|
2012-07-18 13:15:59 +00:00
|
|
|
private:
|
|
|
|
template<typename Tuple, typename IndexTuple>
|
|
|
|
struct result_impl;
|
|
|
|
template<typename Tuple, sprout::index_t... Indexes>
|
|
|
|
struct result_impl<Tuple, sprout::index_tuple<Indexes...> > {
|
|
|
|
public:
|
|
|
|
typedef decltype(
|
|
|
|
std::declval<functor_type const&>()(
|
|
|
|
sprout::tuples::get<Indexes>(std::declval<Tuple>())...
|
|
|
|
)
|
|
|
|
) type;
|
|
|
|
};
|
|
|
|
public:
|
|
|
|
template<typename Tuple>
|
|
|
|
struct result
|
|
|
|
: public result_impl<
|
|
|
|
Tuple,
|
|
|
|
typename sprout::index_range<0, sprout::tuples::tuple_size<typename std::remove_reference<Tuple>::type>::value>::type
|
|
|
|
>
|
|
|
|
{};
|
2012-05-31 13:28:58 +00:00
|
|
|
private:
|
|
|
|
functor_type f_;
|
|
|
|
private:
|
2012-07-18 13:15:59 +00:00
|
|
|
template<typename Result, typename Tuple, sprout::index_t... Indexes>
|
|
|
|
SPROUT_CONSTEXPR Result
|
|
|
|
call(Tuple&& t, sprout::index_tuple<Indexes...>) const {
|
2012-05-31 13:28:58 +00:00
|
|
|
return f_(sprout::tuples::get<Indexes>(sprout::forward<Tuple>(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<typename Tuple>
|
2012-07-18 13:15:59 +00:00
|
|
|
SPROUT_CONSTEXPR typename result<Tuple>::type
|
|
|
|
operator()(Tuple&& t) const {
|
|
|
|
return call<typename result<Tuple>::type>(
|
2012-05-31 13:28:58 +00:00
|
|
|
sprout::forward<Tuple>(t),
|
2012-07-18 13:15:59 +00:00
|
|
|
sprout::index_range<0, sprout::tuples::tuple_size<typename std::remove_reference<Tuple>::type>::value>::make()
|
2012-05-31 13:28:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// make_fused
|
|
|
|
//
|
|
|
|
template<typename F>
|
|
|
|
inline SPROUT_CONSTEXPR sprout::tuples::fused<F>
|
|
|
|
make_fused(F const& f) {
|
|
|
|
return sprout::tuples::fused<F>(f);
|
|
|
|
}
|
|
|
|
} // namespace tuples
|
|
|
|
|
|
|
|
using sprout::tuples::fused;
|
|
|
|
using sprout::tuples::make_fused;
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_TUPLE_FUSED_HPP
|