mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
index_n 再実装
This commit is contained in:
parent
8ad87d104d
commit
3078d76ceb
1 changed files with 55 additions and 17 deletions
|
@ -98,32 +98,70 @@ namespace sprout {
|
||||||
// index_n
|
// index_n
|
||||||
//
|
//
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<
|
template<typename IndexTuple>
|
||||||
sprout::index_t I,
|
struct index_n_next;
|
||||||
std::size_t N,
|
template<sprout::index_t... Indexes>
|
||||||
typename Acc,
|
struct index_n_next<sprout::index_tuple<Indexes...>> {
|
||||||
bool Break = (N == 0)
|
|
||||||
>
|
|
||||||
struct index_n_impl {
|
|
||||||
public:
|
public:
|
||||||
typedef Acc type;
|
typedef sprout::index_tuple<Indexes..., Indexes...> type;
|
||||||
};
|
};
|
||||||
template<
|
|
||||||
sprout::index_t I,
|
template<typename IndexTuple, sprout::index_t Tail>
|
||||||
std::size_t N,
|
struct index_n_next2;
|
||||||
sprout::index_t... Indexes
|
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
|
||||||
>
|
>
|
||||||
struct index_n_impl<I, N, sprout::index_tuple<Indexes...>, false>
|
|
||||||
: public sprout::detail::index_n_impl<I, N - 1, sprout::index_tuple<Indexes..., I> >
|
|
||||||
{};
|
{};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
template<
|
template<
|
||||||
sprout::index_t I,
|
sprout::index_t I,
|
||||||
std::size_t N,
|
std::size_t N
|
||||||
typename Acc = sprout::index_tuple<>
|
|
||||||
>
|
>
|
||||||
struct index_n
|
struct index_n
|
||||||
: public sprout::detail::index_n_impl<I, N, Acc>
|
: public sprout::detail::index_n_impl<I, N>
|
||||||
{};
|
{};
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue