2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2015-01-10 10:13:57 +00:00
|
|
|
Copyright (c) 2011-2015 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
2013-03-31 04:39:26 +00:00
|
|
|
#ifndef SPROUT_INDEX_TUPLE_INTEGER_N_HPP
|
|
|
|
#define SPROUT_INDEX_TUPLE_INTEGER_N_HPP
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
2014-04-30 07:30:26 +00:00
|
|
|
#include <sprout/workaround/std/cstddef.hpp>
|
2013-05-10 10:52:39 +00:00
|
|
|
#include <sprout/index_tuple/integer_sequence.hpp>
|
2013-04-06 04:06:51 +00:00
|
|
|
#include <sprout/index_tuple/enable_make_indexes.hpp>
|
2013-03-31 04:39:26 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
//
|
|
|
|
// integer_n
|
|
|
|
//
|
|
|
|
namespace detail {
|
|
|
|
template<typename T, typename Seq>
|
|
|
|
struct integer_n_next_even;
|
|
|
|
template<typename T, T... Is>
|
2013-05-10 10:52:39 +00:00
|
|
|
struct integer_n_next_even<T, sprout::integer_sequence<T, Is...> >
|
|
|
|
: public sprout::integer_sequence<T, Is..., Is...>
|
2013-03-31 04:39:26 +00:00
|
|
|
{};
|
|
|
|
|
|
|
|
template<typename T, typename Seq, T Tail>
|
|
|
|
struct integer_n_next_even_odd;
|
|
|
|
template<typename T, T... Is, T Tail>
|
2013-05-10 10:52:39 +00:00
|
|
|
struct integer_n_next_even_odd<T, sprout::integer_sequence<T, Is...>, Tail>
|
|
|
|
: public sprout::integer_sequence<T, Is..., Is..., Tail>
|
2013-03-31 04:39:26 +00:00
|
|
|
{};
|
|
|
|
|
|
|
|
template<typename T, T I, std::size_t N, typename Enable = void>
|
|
|
|
struct integer_n_impl;
|
|
|
|
template<typename T, T I, std::size_t N>
|
|
|
|
struct integer_n_impl<
|
|
|
|
T, I, N,
|
|
|
|
typename std::enable_if<(N == 0)>::type
|
|
|
|
>
|
2013-05-10 10:52:39 +00:00
|
|
|
: public sprout::integer_sequence<T>
|
2013-03-31 04:39:26 +00:00
|
|
|
{};
|
|
|
|
template<typename T, T I, std::size_t N>
|
|
|
|
struct integer_n_impl<
|
|
|
|
T, I, N,
|
|
|
|
typename std::enable_if<(N == 1)>::type
|
|
|
|
>
|
2013-05-10 10:52:39 +00:00
|
|
|
: public sprout::integer_sequence<T, I>
|
2013-03-31 04:39:26 +00:00
|
|
|
{};
|
|
|
|
template<typename T, T I, std::size_t N>
|
|
|
|
struct integer_n_impl<
|
|
|
|
T, I, N,
|
|
|
|
typename std::enable_if<(N > 1 && N % 2 == 0)>::type
|
|
|
|
>
|
|
|
|
: public sprout::detail::integer_n_next_even<
|
|
|
|
T, typename sprout::detail::integer_n_impl<T, I, N / 2>::type
|
|
|
|
>
|
|
|
|
{};
|
|
|
|
template<typename T, T I, std::size_t N>
|
|
|
|
struct integer_n_impl<
|
|
|
|
T, I, N,
|
|
|
|
typename std::enable_if<(N > 1 && N % 2 == 1)>::type
|
|
|
|
>
|
|
|
|
: public sprout::detail::integer_n_next_even_odd<
|
|
|
|
T, typename sprout::detail::integer_n_impl<T, I, N / 2>::type,
|
|
|
|
I
|
|
|
|
>
|
|
|
|
{};
|
2013-05-12 02:05:31 +00:00
|
|
|
|
|
|
|
template<typename T, T I, std::size_t N>
|
|
|
|
struct integer_n
|
|
|
|
: public sprout::enable_make_indexes<
|
|
|
|
sprout::detail::integer_n_impl<T, I, N>
|
|
|
|
>
|
|
|
|
{};
|
2013-03-31 04:39:26 +00:00
|
|
|
} // namespace detail
|
2013-05-12 02:05:31 +00:00
|
|
|
//
|
|
|
|
// integer_range
|
|
|
|
//
|
2014-03-07 10:49:30 +00:00
|
|
|
#if SPROUT_USE_TEMPLATE_ALIASES && !defined(SPROUT_WORKAROUND_NO_TEMPLATE_ARGUMENT_DEDUCTION_WITH_ALIASES)
|
2013-05-12 02:05:31 +00:00
|
|
|
template<typename T, T I, std::size_t N>
|
|
|
|
using integer_n = typename sprout::detail::integer_n<T, I, N>::type;
|
2014-03-07 10:49:30 +00:00
|
|
|
#else // #if SPROUT_USE_TEMPLATE_ALIASES && !defined(SPROUT_WORKAROUND_NO_TEMPLATE_ARGUMENT_DEDUCTION_WITH_ALIASES)
|
2013-03-31 04:39:26 +00:00
|
|
|
template<typename T, T I, std::size_t N>
|
|
|
|
struct integer_n
|
2013-05-12 02:05:31 +00:00
|
|
|
: public sprout::detail::integer_n<T, I, N>
|
2013-03-31 04:39:26 +00:00
|
|
|
{};
|
2014-03-07 10:49:30 +00:00
|
|
|
#endif // #if SPROUT_USE_TEMPLATE_ALIASES && !defined(SPROUT_WORKAROUND_NO_TEMPLATE_ARGUMENT_DEDUCTION_WITH_ALIASES)
|
2013-03-31 04:39:26 +00:00
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_INDEX_TUPLE_INTEGER_N_HPP
|