mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
fix tuple/fused
This commit is contained in:
parent
d94684c1d6
commit
9069a110e9
2 changed files with 28 additions and 114 deletions
|
@ -1,6 +1,7 @@
|
|||
#ifndef SPROUT_TUPLE_FUSED_HPP
|
||||
#define SPROUT_TUPLE_FUSED_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
|
@ -16,14 +17,32 @@ namespace sprout {
|
|||
class fused {
|
||||
public:
|
||||
typedef F functor_type;
|
||||
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
|
||||
>
|
||||
{};
|
||||
private:
|
||||
functor_type f_;
|
||||
private:
|
||||
template<typename Tuple, sprout::index_t... Indexes>
|
||||
SPROUT_CONSTEXPR auto
|
||||
call(Tuple&& t, sprout::index_tuple<Indexes...>) const
|
||||
-> decltype(f_(sprout::tuples::get<Indexes>(sprout::forward<Tuple>(t))...))
|
||||
{
|
||||
template<typename Result, typename Tuple, sprout::index_t... Indexes>
|
||||
SPROUT_CONSTEXPR Result
|
||||
call(Tuple&& t, sprout::index_tuple<Indexes...>) const {
|
||||
return f_(sprout::tuples::get<Indexes>(sprout::forward<Tuple>(t))...);
|
||||
}
|
||||
public:
|
||||
|
@ -36,16 +55,11 @@ namespace sprout {
|
|||
return f_;
|
||||
}
|
||||
template<typename Tuple>
|
||||
SPROUT_CONSTEXPR auto
|
||||
operator()(Tuple&& t) const
|
||||
-> decltype(this->call(
|
||||
SPROUT_CONSTEXPR typename result<Tuple>::type
|
||||
operator()(Tuple&& t) const {
|
||||
return call<typename result<Tuple>::type>(
|
||||
sprout::forward<Tuple>(t),
|
||||
sprout::index_range<0, sprout::tuples::tuple_size<typename std::decay<Tuple>::type>::value>::make()
|
||||
))
|
||||
{
|
||||
return call(
|
||||
sprout::forward<Tuple>(t),
|
||||
sprout::index_range<0, sprout::tuples::tuple_size<typename std::decay<Tuple>::type>::value>::make()
|
||||
sprout::index_range<0, sprout::tuples::tuple_size<typename std::remove_reference<Tuple>::type>::value>::make()
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -9,109 +9,9 @@
|
|||
|
||||
namespace sprout {
|
||||
namespace types {
|
||||
// template<typename Tuple, std::ptrdiff_t Index>
|
||||
// struct index_iterator;
|
||||
//
|
||||
// namespace detail {
|
||||
// //
|
||||
// // index_iterator_impl
|
||||
// //
|
||||
// template<typename Tuple, std::ptrdiff_t Index, typename = void>
|
||||
// struct index_iterator_impl;
|
||||
// template<typename Tuple, std::ptrdiff_t Index>
|
||||
// struct index_iterator_impl<
|
||||
// Tuple,
|
||||
// Index,
|
||||
// typename std::enable_if<
|
||||
// sprout::types::tuple_size<Tuple>::value == 0
|
||||
// || (Index < 0)
|
||||
// || (Index > sprout::types::tuple_size<Tuple>::value)
|
||||
// >::type
|
||||
// > {
|
||||
// public:
|
||||
// typedef sprout::types::void_ type;
|
||||
// typedef sprout::types::void_ next;
|
||||
// typedef sprout::types::void_ prev;
|
||||
// public:
|
||||
// template<std::ptrdiff_t Disatnce>
|
||||
// struct advance {
|
||||
// public:
|
||||
// typedef sprout::types::index_iterator<Tuple, Index + Disatnce> type;
|
||||
// };
|
||||
// };
|
||||
// template<typename Tuple, std::ptrdiff_t Index>
|
||||
// struct index_iterator_impl<
|
||||
// Tuple,
|
||||
// Index,
|
||||
// typename std::enable_if<
|
||||
// sprout::types::tuple_size<Tuple>::value != 0
|
||||
// && Index == 0
|
||||
// >::type
|
||||
// > {
|
||||
// public:
|
||||
// typedef typename sprout::types::tuple_element<Index, Tuple>::type type;
|
||||
// typedef sprout::types::index_iterator<Tuple, Index + 1> next;
|
||||
// typedef sprout::types::void_ prev;
|
||||
// public:
|
||||
// template<std::ptrdiff_t Disatnce>
|
||||
// struct advance {
|
||||
// public:
|
||||
// typedef sprout::types::index_iterator<Tuple, Index + Disatnce> type;
|
||||
// };
|
||||
// };
|
||||
// template<typename Tuple, std::ptrdiff_t Index>
|
||||
// struct index_iterator_impl<
|
||||
// Tuple,
|
||||
// Index,
|
||||
// typename std::enable_if<
|
||||
// sprout::types::tuple_size<Tuple>::value != 0
|
||||
// && Index == sprout::types::tuple_size<Tuple>::value
|
||||
// >::type
|
||||
// > {
|
||||
// public:
|
||||
// typedef sprout::types::void_ type;
|
||||
// typedef sprout::types::void_ next;
|
||||
// typedef sprout::types::index_iterator<Tuple, sprout::types::tuple_size<Tuple>::value - 1> prev;
|
||||
// public:
|
||||
// template<std::ptrdiff_t Disatnce>
|
||||
// struct advance {
|
||||
// public:
|
||||
// typedef sprout::types::index_iterator<Tuple, Index + Disatnce> type;
|
||||
// };
|
||||
// };
|
||||
// template<typename Tuple, std::ptrdiff_t Index>
|
||||
// struct index_iterator_impl<
|
||||
// Tuple,
|
||||
// Index,
|
||||
// typename std::enable_if<
|
||||
// sprout::types::tuple_size<Tuple>::value != 0
|
||||
// && (Index > 0)
|
||||
// && (Index < sprout::types::tuple_size<Tuple>::value)
|
||||
// >::type
|
||||
// > {
|
||||
// public:
|
||||
// typedef typename sprout::types::tuple_element<Index, Tuple>::type type;
|
||||
// typedef sprout::types::index_iterator<Tuple, Index + 1> next;
|
||||
// typedef sprout::types::index_iterator<Tuple, Index - 1> prev;
|
||||
// public:
|
||||
// template<std::ptrdiff_t Disatnce>
|
||||
// struct advance {
|
||||
// public:
|
||||
// typedef sprout::types::index_iterator<Tuple, Index + Disatnce> type;
|
||||
// };
|
||||
// };
|
||||
// } // namespace detail
|
||||
//
|
||||
// index_iterator
|
||||
//
|
||||
// template<typename Tuple, std::ptrdiff_t Index>
|
||||
// struct index_iterator
|
||||
// : public sprout::types::detail::index_iterator_impl<Tuple, Index>
|
||||
// , public std::integral_constant<std::ptrdiff_t, Index>
|
||||
// {
|
||||
// public:
|
||||
// typedef typename sprout::types::detail::index_iterator_impl<Tuple, Index>::type type;
|
||||
// };
|
||||
template<typename Tuple, std::ptrdiff_t Index>
|
||||
struct index_iterator
|
||||
: public std::integral_constant<std::ptrdiff_t, Index>
|
||||
|
|
Loading…
Reference in a new issue