mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
add index_tuple/*
This commit is contained in:
parent
c6bd230ee4
commit
84956034ad
10 changed files with 259 additions and 205 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/index_tuple/detail/make_indexes_helper.hpp>
|
||||
#include <sprout/container/container_construct_traits.hpp>
|
||||
|
||||
namespace sprout {
|
||||
|
@ -12,7 +13,7 @@ namespace sprout {
|
|||
//
|
||||
template<typename Container>
|
||||
struct container_indexes
|
||||
: public sprout::detail::make_index_tuple_helper<
|
||||
: public sprout::detail::make_indexes_helper<
|
||||
sprout::index_range<0, sprout::container_traits<Container>::static_size>
|
||||
>
|
||||
{};
|
||||
|
|
|
@ -1,202 +1,11 @@
|
|||
#ifndef SPROUT_INDEX_TUPLE_HPP
|
||||
#define SPROUT_INDEX_TUPLE_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// index_t
|
||||
//
|
||||
typedef std::ptrdiff_t index_t;
|
||||
|
||||
//
|
||||
// index_tuple
|
||||
//
|
||||
template<sprout::index_t... Indexes>
|
||||
struct index_tuple {
|
||||
public:
|
||||
typedef index_tuple type;
|
||||
};
|
||||
|
||||
//
|
||||
// make_indexes
|
||||
//
|
||||
template<typename IndexTupleType>
|
||||
inline SPROUT_CONSTEXPR typename IndexTupleType::type make_indexes() {
|
||||
return typename IndexTupleType::type();
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template<typename IndexTupleType>
|
||||
struct make_index_tuple_helper {
|
||||
public:
|
||||
typedef typename IndexTupleType::type type;
|
||||
public:
|
||||
static SPROUT_CONSTEXPR type make() {
|
||||
return type();
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// index_range
|
||||
//
|
||||
namespace detail {
|
||||
template<typename IndexTuple, sprout::index_t Next>
|
||||
struct index_range_next;
|
||||
template<sprout::index_t... Indexes, sprout::index_t Next>
|
||||
struct index_range_next<sprout::index_tuple<Indexes...>, Next> {
|
||||
public:
|
||||
typedef sprout::index_tuple<Indexes..., (Indexes + Next)...> type;
|
||||
};
|
||||
|
||||
template<typename IndexTuple, sprout::index_t Next, sprout::index_t Tail>
|
||||
struct index_range_next2;
|
||||
template<sprout::index_t... Indexes, sprout::index_t Next, sprout::index_t Tail>
|
||||
struct index_range_next2<sprout::index_tuple<Indexes...>, Next, Tail> {
|
||||
public:
|
||||
typedef sprout::index_tuple<Indexes..., (Indexes + Next)..., Tail> type;
|
||||
};
|
||||
|
||||
template<sprout::index_t First, sprout::index_t Step, std::size_t N, typename Enable = void>
|
||||
struct index_range_impl;
|
||||
template<sprout::index_t First, sprout::index_t Step, std::size_t N>
|
||||
struct index_range_impl<
|
||||
First,
|
||||
Step,
|
||||
N,
|
||||
typename std::enable_if<(N == 0)>::type
|
||||
> {
|
||||
public:
|
||||
typedef sprout::index_tuple<> type;
|
||||
};
|
||||
template<sprout::index_t First, sprout::index_t Step, std::size_t N>
|
||||
struct index_range_impl<
|
||||
First,
|
||||
Step,
|
||||
N,
|
||||
typename std::enable_if<(N == 1)>::type
|
||||
> {
|
||||
public:
|
||||
typedef sprout::index_tuple<First> type;
|
||||
};
|
||||
template<sprout::index_t First, sprout::index_t Step, std::size_t N>
|
||||
struct index_range_impl<
|
||||
First,
|
||||
Step,
|
||||
N,
|
||||
typename std::enable_if<(N > 1 && N % 2 == 0)>::type
|
||||
>
|
||||
: public sprout::detail::index_range_next<
|
||||
typename sprout::detail::index_range_impl<First, Step, N / 2>::type,
|
||||
First + N / 2 * Step
|
||||
>
|
||||
{};
|
||||
template<sprout::index_t First, sprout::index_t Step, std::size_t N>
|
||||
struct index_range_impl<
|
||||
First,
|
||||
Step,
|
||||
N,
|
||||
typename std::enable_if<(N > 1 && N % 2 == 1)>::type
|
||||
>
|
||||
: public sprout::detail::index_range_next2<
|
||||
typename sprout::detail::index_range_impl<First, Step, N / 2>::type,
|
||||
First + N / 2 * Step,
|
||||
First + (N - 1) * Step
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
template<sprout::index_t First, sprout::index_t Last, sprout::index_t Step = 1>
|
||||
struct index_range
|
||||
: public sprout::detail::make_index_tuple_helper<
|
||||
sprout::detail::index_range_impl<
|
||||
First,
|
||||
Step,
|
||||
((Last - First) + (Step - 1)) / Step
|
||||
>
|
||||
>
|
||||
{};
|
||||
|
||||
//
|
||||
// index_n
|
||||
//
|
||||
namespace detail {
|
||||
template<typename IndexTuple>
|
||||
struct index_n_next;
|
||||
template<sprout::index_t... Indexes>
|
||||
struct index_n_next<sprout::index_tuple<Indexes...>> {
|
||||
public:
|
||||
typedef sprout::index_tuple<Indexes..., Indexes...> type;
|
||||
};
|
||||
|
||||
template<typename IndexTuple, sprout::index_t Tail>
|
||||
struct index_n_next2;
|
||||
template<sprout::index_t... Indexes, sprout::index_t Tail>
|
||||
struct index_n_next2<sprout::index_tuple<Indexes...>, Tail> {
|
||||
public:
|
||||
typedef sprout::index_tuple<Indexes..., Indexes..., Tail> type;
|
||||
};
|
||||
|
||||
template<sprout::index_t I, std::size_t N, typename Enable = void>
|
||||
struct index_n_impl;
|
||||
template<sprout::index_t I, std::size_t N>
|
||||
struct index_n_impl<
|
||||
I,
|
||||
N,
|
||||
typename std::enable_if<(N == 0)>::type
|
||||
> {
|
||||
public:
|
||||
typedef sprout::index_tuple<> type;
|
||||
};
|
||||
template<sprout::index_t I, std::size_t N>
|
||||
struct index_n_impl<
|
||||
I,
|
||||
N,
|
||||
typename std::enable_if<(N == 1)>::type
|
||||
> {
|
||||
public:
|
||||
typedef sprout::index_tuple<I> type;
|
||||
};
|
||||
template<sprout::index_t I, std::size_t N>
|
||||
struct index_n_impl<
|
||||
I,
|
||||
N,
|
||||
typename std::enable_if<(N > 1 && N % 2 == 0)>::type
|
||||
>
|
||||
: public sprout::detail::index_n_next<
|
||||
typename sprout::detail::index_n_impl<I, N / 2>::type
|
||||
>
|
||||
{};
|
||||
template<sprout::index_t I, std::size_t N>
|
||||
struct index_n_impl<
|
||||
I,
|
||||
N,
|
||||
typename std::enable_if<(N > 1 && N % 2 == 1)>::type
|
||||
>
|
||||
: public sprout::detail::index_n_next2<
|
||||
typename sprout::detail::index_n_impl<I, N / 2>::type,
|
||||
I
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
template<sprout::index_t I, std::size_t N>
|
||||
struct index_n
|
||||
: public sprout::detail::make_index_tuple_helper<
|
||||
sprout::detail::index_n_impl<I, N>
|
||||
>
|
||||
{};
|
||||
|
||||
//
|
||||
// pack_indexes
|
||||
//
|
||||
template<typename... Args>
|
||||
struct pack_indexes
|
||||
: public sprout::detail::make_index_tuple_helper<
|
||||
sprout::index_range<0, sizeof...(Args)>
|
||||
>
|
||||
{};
|
||||
} // namespace sprout
|
||||
#include <sprout/index_tuple/index_tuple.hpp>
|
||||
#include <sprout/index_tuple/make_indexes.hpp>
|
||||
#include <sprout/index_tuple/index_range.hpp>
|
||||
#include <sprout/index_tuple/index_n.hpp>
|
||||
#include <sprout/index_tuple/pack_indexes.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_INDEX_TUPLE_HPP
|
||||
|
|
20
sprout/index_tuple/detail/make_indexes_helper.hpp
Normal file
20
sprout/index_tuple/detail/make_indexes_helper.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef SPROUT_INDEX_TUPLE_DETAIL_MAKE_INDEXES_HELPER_HPP
|
||||
#define SPROUT_INDEX_TUPLE_DETAIL_MAKE_INDEXES_HELPER_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename IndexTupleType>
|
||||
struct make_indexes_helper {
|
||||
public:
|
||||
typedef typename IndexTupleType::type type;
|
||||
public:
|
||||
static SPROUT_CONSTEXPR type make() {
|
||||
return type();
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_INDEX_TUPLE_DETAIL_MAKE_INDEXES_HELPER_HPP
|
81
sprout/index_tuple/index_n.hpp
Normal file
81
sprout/index_tuple/index_n.hpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
#ifndef SPROUT_INDEX_TUPLE_INDEX_N_HPP
|
||||
#define SPROUT_INDEX_TUPLE_INDEX_N_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple/index_tuple.hpp>
|
||||
#include <sprout/index_tuple/detail/make_indexes_helper.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// index_n
|
||||
//
|
||||
namespace detail {
|
||||
template<typename IndexTuple>
|
||||
struct index_n_next;
|
||||
template<sprout::index_t... Indexes>
|
||||
struct index_n_next<sprout::index_tuple<Indexes...>> {
|
||||
public:
|
||||
typedef sprout::index_tuple<Indexes..., Indexes...> type;
|
||||
};
|
||||
|
||||
template<typename IndexTuple, sprout::index_t Tail>
|
||||
struct index_n_next2;
|
||||
template<sprout::index_t... Indexes, sprout::index_t Tail>
|
||||
struct index_n_next2<sprout::index_tuple<Indexes...>, Tail> {
|
||||
public:
|
||||
typedef sprout::index_tuple<Indexes..., Indexes..., Tail> type;
|
||||
};
|
||||
|
||||
template<sprout::index_t I, std::size_t N, typename Enable = void>
|
||||
struct index_n_impl;
|
||||
template<sprout::index_t I, std::size_t N>
|
||||
struct index_n_impl<
|
||||
I,
|
||||
N,
|
||||
typename std::enable_if<(N == 0)>::type
|
||||
> {
|
||||
public:
|
||||
typedef sprout::index_tuple<> type;
|
||||
};
|
||||
template<sprout::index_t I, std::size_t N>
|
||||
struct index_n_impl<
|
||||
I,
|
||||
N,
|
||||
typename std::enable_if<(N == 1)>::type
|
||||
> {
|
||||
public:
|
||||
typedef sprout::index_tuple<I> type;
|
||||
};
|
||||
template<sprout::index_t I, std::size_t N>
|
||||
struct index_n_impl<
|
||||
I,
|
||||
N,
|
||||
typename std::enable_if<(N > 1 && N % 2 == 0)>::type
|
||||
>
|
||||
: public sprout::detail::index_n_next<
|
||||
typename sprout::detail::index_n_impl<I, N / 2>::type
|
||||
>
|
||||
{};
|
||||
template<sprout::index_t I, std::size_t N>
|
||||
struct index_n_impl<
|
||||
I,
|
||||
N,
|
||||
typename std::enable_if<(N > 1 && N % 2 == 1)>::type
|
||||
>
|
||||
: public sprout::detail::index_n_next2<
|
||||
typename sprout::detail::index_n_impl<I, N / 2>::type,
|
||||
I
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
template<sprout::index_t I, std::size_t N>
|
||||
struct index_n
|
||||
: public sprout::detail::make_indexes_helper<
|
||||
sprout::detail::index_n_impl<I, N>
|
||||
>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_N_HPP
|
91
sprout/index_tuple/index_range.hpp
Normal file
91
sprout/index_tuple/index_range.hpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
#ifndef SPROUT_INDEX_TUPLE_INDEX_RANGE_HPP
|
||||
#define SPROUT_INDEX_TUPLE_INDEX_RANGE_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple/index_tuple.hpp>
|
||||
#include <sprout/index_tuple/detail/make_indexes_helper.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// index_range
|
||||
//
|
||||
namespace detail {
|
||||
template<typename IndexTuple, sprout::index_t Next>
|
||||
struct index_range_next;
|
||||
template<sprout::index_t... Indexes, sprout::index_t Next>
|
||||
struct index_range_next<sprout::index_tuple<Indexes...>, Next> {
|
||||
public:
|
||||
typedef sprout::index_tuple<Indexes..., (Indexes + Next)...> type;
|
||||
};
|
||||
|
||||
template<typename IndexTuple, sprout::index_t Next, sprout::index_t Tail>
|
||||
struct index_range_next2;
|
||||
template<sprout::index_t... Indexes, sprout::index_t Next, sprout::index_t Tail>
|
||||
struct index_range_next2<sprout::index_tuple<Indexes...>, Next, Tail> {
|
||||
public:
|
||||
typedef sprout::index_tuple<Indexes..., (Indexes + Next)..., Tail> type;
|
||||
};
|
||||
|
||||
template<sprout::index_t First, sprout::index_t Step, std::size_t N, typename Enable = void>
|
||||
struct index_range_impl;
|
||||
template<sprout::index_t First, sprout::index_t Step, std::size_t N>
|
||||
struct index_range_impl<
|
||||
First,
|
||||
Step,
|
||||
N,
|
||||
typename std::enable_if<(N == 0)>::type
|
||||
> {
|
||||
public:
|
||||
typedef sprout::index_tuple<> type;
|
||||
};
|
||||
template<sprout::index_t First, sprout::index_t Step, std::size_t N>
|
||||
struct index_range_impl<
|
||||
First,
|
||||
Step,
|
||||
N,
|
||||
typename std::enable_if<(N == 1)>::type
|
||||
> {
|
||||
public:
|
||||
typedef sprout::index_tuple<First> type;
|
||||
};
|
||||
template<sprout::index_t First, sprout::index_t Step, std::size_t N>
|
||||
struct index_range_impl<
|
||||
First,
|
||||
Step,
|
||||
N,
|
||||
typename std::enable_if<(N > 1 && N % 2 == 0)>::type
|
||||
>
|
||||
: public sprout::detail::index_range_next<
|
||||
typename sprout::detail::index_range_impl<First, Step, N / 2>::type,
|
||||
First + N / 2 * Step
|
||||
>
|
||||
{};
|
||||
template<sprout::index_t First, sprout::index_t Step, std::size_t N>
|
||||
struct index_range_impl<
|
||||
First,
|
||||
Step,
|
||||
N,
|
||||
typename std::enable_if<(N > 1 && N % 2 == 1)>::type
|
||||
>
|
||||
: public sprout::detail::index_range_next2<
|
||||
typename sprout::detail::index_range_impl<First, Step, N / 2>::type,
|
||||
First + N / 2 * Step,
|
||||
First + (N - 1) * Step
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
template<sprout::index_t First, sprout::index_t Last, sprout::index_t Step = 1>
|
||||
struct index_range
|
||||
: public sprout::detail::make_indexes_helper<
|
||||
sprout::detail::index_range_impl<
|
||||
First,
|
||||
Step,
|
||||
((Last - First) + (Step - 1)) / Step
|
||||
>
|
||||
>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_RANGE_HPP
|
23
sprout/index_tuple/index_tuple.hpp
Normal file
23
sprout/index_tuple/index_tuple.hpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef SPROUT_INDEX_TUPLE_INDEX_TUPLE_HPP
|
||||
#define SPROUT_INDEX_TUPLE_INDEX_TUPLE_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// index_t
|
||||
//
|
||||
typedef std::ptrdiff_t index_t;
|
||||
|
||||
//
|
||||
// index_tuple
|
||||
//
|
||||
template<sprout::index_t... Indexes>
|
||||
struct index_tuple {
|
||||
public:
|
||||
typedef index_tuple type;
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_TUPLE_HPP
|
16
sprout/index_tuple/make_indexes.hpp
Normal file
16
sprout/index_tuple/make_indexes.hpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef SPROUT_INDEX_TUPLE_MAKE_INDEXES_HPP
|
||||
#define SPROUT_INDEX_TUPLE_MAKE_INDEXES_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// make_indexes
|
||||
//
|
||||
template<typename IndexTupleType>
|
||||
inline SPROUT_CONSTEXPR typename IndexTupleType::type make_indexes() {
|
||||
return typename IndexTupleType::type();
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_INDEX_TUPLE_MAKE_INDEXES_HPP
|
19
sprout/index_tuple/pack_indexes.hpp
Normal file
19
sprout/index_tuple/pack_indexes.hpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef SPROUT_INDEX_TUPLE_PACK_INDEXES_HPP
|
||||
#define SPROUT_INDEX_TUPLE_PACK_INDEXES_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple/detail/make_indexes_helper.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// pack_indexes
|
||||
//
|
||||
template<typename... Args>
|
||||
struct pack_indexes
|
||||
: public sprout::detail::make_indexes_helper<
|
||||
sprout::index_range<0, sizeof...(Args)>
|
||||
>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_INDEX_TUPLE_PACK_INDEXES_HPP
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/index_tuple/detail/make_indexes_helper.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
|
||||
namespace sprout {
|
||||
|
@ -12,7 +13,7 @@ namespace sprout {
|
|||
//
|
||||
template<typename Tuple>
|
||||
struct tuple_indexes
|
||||
: public sprout::detail::make_index_tuple_helper<
|
||||
: public sprout::detail::make_indexes_helper<
|
||||
sprout::index_range<0, sprout::tuples::tuple_size<Tuple>::value>
|
||||
>
|
||||
{};
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
|
||||
//#define SPROUT_CONFIG_DISABLE_CONSTEXPR
|
||||
//#define SPROUT_CONFIG_DISABLE_NOEXCEPT
|
||||
//#define SPROUT_CONFIG_DISABLE_TEMPLATE_ALIASES
|
||||
//#define SPROUT_CONFIG_USE_SSCRISK_CEL
|
||||
//#define SPROUT_CONFIG_DISABLE_SUPPORT_TEMPORARY_CONTAINER_ITERATION
|
||||
//#define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION
|
Loading…
Reference in a new issue