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
|
#ifndef SPROUT_TUPLE_FUSED_HPP
|
||||||
#define SPROUT_TUPLE_FUSED_HPP
|
#define SPROUT_TUPLE_FUSED_HPP
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
#include <sprout/index_tuple.hpp>
|
#include <sprout/index_tuple.hpp>
|
||||||
|
@ -16,14 +17,32 @@ namespace sprout {
|
||||||
class fused {
|
class fused {
|
||||||
public:
|
public:
|
||||||
typedef F functor_type;
|
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:
|
private:
|
||||||
functor_type f_;
|
functor_type f_;
|
||||||
private:
|
private:
|
||||||
template<typename Tuple, sprout::index_t... Indexes>
|
template<typename Result, typename Tuple, sprout::index_t... Indexes>
|
||||||
SPROUT_CONSTEXPR auto
|
SPROUT_CONSTEXPR Result
|
||||||
call(Tuple&& t, sprout::index_tuple<Indexes...>) const
|
call(Tuple&& t, sprout::index_tuple<Indexes...>) const {
|
||||||
-> decltype(f_(sprout::tuples::get<Indexes>(sprout::forward<Tuple>(t))...))
|
|
||||||
{
|
|
||||||
return f_(sprout::tuples::get<Indexes>(sprout::forward<Tuple>(t))...);
|
return f_(sprout::tuples::get<Indexes>(sprout::forward<Tuple>(t))...);
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
|
@ -36,16 +55,11 @@ namespace sprout {
|
||||||
return f_;
|
return f_;
|
||||||
}
|
}
|
||||||
template<typename Tuple>
|
template<typename Tuple>
|
||||||
SPROUT_CONSTEXPR auto
|
SPROUT_CONSTEXPR typename result<Tuple>::type
|
||||||
operator()(Tuple&& t) const
|
operator()(Tuple&& t) const {
|
||||||
-> decltype(this->call(
|
return call<typename result<Tuple>::type>(
|
||||||
sprout::forward<Tuple>(t),
|
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()
|
||||||
))
|
|
||||||
{
|
|
||||||
return call(
|
|
||||||
sprout::forward<Tuple>(t),
|
|
||||||
sprout::index_range<0, sprout::tuples::tuple_size<typename std::decay<Tuple>::type>::value>::make()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,109 +9,9 @@
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
namespace types {
|
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
|
// 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>
|
template<typename Tuple, std::ptrdiff_t Index>
|
||||||
struct index_iterator
|
struct index_iterator
|
||||||
: public std::integral_constant<std::ptrdiff_t, Index>
|
: public std::integral_constant<std::ptrdiff_t, Index>
|
||||||
|
|
Loading…
Reference in a new issue