fix index_tuple implementation: template aliases (if compiler supported)

This commit is contained in:
bolero-MURAKAMI 2013-05-10 21:53:53 +09:00
parent bb36ef6e8b
commit 3ff1ffb4d9
8 changed files with 78 additions and 21 deletions

View file

@ -2,6 +2,7 @@
#define SPROUT_INDEX_TUPLE_CLASS_HPP
#include <sprout/config.hpp>
#include <sprout/index_tuple/index_t.hpp>
#include <sprout/index_tuple/integer_sequence.hpp>
#include <sprout/index_tuple/index_tuple.hpp>
#include <sprout/index_tuple/index_sequence.hpp>

View file

@ -10,7 +10,15 @@
namespace sprout {
//
// index_n
// uindex_n
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<sprout::index_t I, std::size_t N>
using index_n = sprout::integer_n<sprout::index_t, I, N>;
template<sprout::uindex_t I, std::size_t N>
using uindex_n = sprout::integer_n<sprout::uindex_t, I, N>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<sprout::index_t I, std::size_t N>
struct index_n
: public sprout::enable_make_indexes<
@ -18,9 +26,7 @@ namespace sprout {
::template transfer<sprout::index_tuple<> >
>
{};
//
// uindex_n
//
template<sprout::uindex_t I, std::size_t N>
struct uindex_n
: public sprout::enable_make_indexes<
@ -28,6 +34,7 @@ namespace sprout {
::template transfer<sprout::uindex_tuple<> >
>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_N_HPP

View file

@ -9,7 +9,15 @@
namespace sprout {
//
// index_pack
// uindex_pack
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename... Ts>
using index_pack = sprout::integer_pack<sprout::index_t, Ts...>;
template<typename... Ts>
using uindex_pack = sprout::integer_pack<sprout::uindex_t, Ts...>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<typename... Ts>
struct index_pack
: public sprout::enable_make_indexes<
@ -17,9 +25,7 @@ namespace sprout {
::template transfer<sprout::index_tuple<> >
>
{};
//
// uindex_pack
//
template<typename... Ts>
struct uindex_pack
: public sprout::enable_make_indexes<
@ -27,6 +33,7 @@ namespace sprout {
::template transfer<sprout::uindex_tuple<> >
>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_PACK_HPP

View file

@ -9,7 +9,21 @@
namespace sprout {
//
// index_range
// uindex_range
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<
sprout::index_t First, sprout::index_t Last,
typename std::make_signed<sprout::index_t>::type Step = sprout::detail::integer_range_default_step<sprout::index_t, First, Last>::value
>
using index_range = sprout::integer_range<sprout::index_t, First, Last, Step>;
template<
sprout::uindex_t First, sprout::uindex_t Last,
typename std::make_signed<sprout::uindex_t>::type Step = sprout::detail::integer_range_default_step<sprout::uindex_t, First, Last>::value
>
using uindex_range = sprout::integer_range<sprout::uindex_t, First, Last, Step>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<
sprout::index_t First, sprout::index_t Last,
typename std::make_signed<sprout::index_t>::type Step = sprout::detail::integer_range_default_step<sprout::index_t, First, Last>::value
@ -20,9 +34,7 @@ namespace sprout {
::template transfer<sprout::index_tuple<> >
>
{};
//
// uindex_range
//
template<
sprout::uindex_t First, sprout::uindex_t Last,
typename std::make_signed<sprout::uindex_t>::type Step = sprout::detail::integer_range_default_step<sprout::uindex_t, First, Last>::value
@ -33,6 +45,7 @@ namespace sprout {
::template transfer<sprout::uindex_tuple<> >
>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_RANGE_HPP

View file

@ -0,0 +1,16 @@
#ifndef SPROUT_INDEX_TUPLE_INDEX_T_HPP
#define SPROUT_INDEX_TUPLE_INDEX_T_HPP
#include <cstddef>
#include <sprout/config.hpp>
namespace sprout {
//
// index_t
// uindex_t
//
typedef std::ptrdiff_t index_t;
typedef std::size_t uindex_t;
} // namespace sprout
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_T_HPP

View file

@ -1,16 +1,22 @@
#ifndef SPROUT_INDEX_TUPLE_INDEX_TUPLE_HPP
#define SPROUT_INDEX_TUPLE_INDEX_TUPLE_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/index_tuple/index_t.hpp>
#include <sprout/index_tuple/integer_sequence.hpp>
namespace sprout {
//
// index_t
// index_tuple
// uindex_tuple
//
typedef std::ptrdiff_t index_t;
#if SPROUT_USE_TEMPLATE_ALIASES
template<sprout::index_t... Indexes>
using index_tuple = sprout::integer_sequence<sprout::index_t, Indexes...>;
template<sprout::uindex_t... Indexes>
using uindex_tuple = sprout::integer_sequence<sprout::uindex_t, Indexes...>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<sprout::index_t... Indexes>
struct index_tuple
: public sprout::integer_sequence<sprout::index_t, Indexes...>
@ -23,11 +29,6 @@ namespace sprout {
{};
};
//
// uindex_t
// uindex_tuple
//
typedef std::size_t uindex_t;
template<sprout::uindex_t... Indexes>
struct uindex_tuple
: public sprout::integer_sequence<sprout::uindex_t, Indexes...>
@ -39,6 +40,7 @@ namespace sprout {
: public uindex_tuple<J...>
{};
};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_TUPLE_HPP

View file

@ -1,7 +1,6 @@
#ifndef SPROUT_INDEX_TUPLE_MAKE_INDEX_TUPLE_HPP
#define SPROUT_INDEX_TUPLE_MAKE_INDEX_TUPLE_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/index_tuple/index_tuple.hpp>
#include <sprout/index_tuple/make_integer_sequence.hpp>
@ -10,7 +9,15 @@
namespace sprout {
//
// make_index_tuple
// make_uindex_tuple
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<sprout::index_t N>
using make_index_tuple = sprout::make_integer_sequence<sprout::index_t, N>;
template<sprout::uindex_t N>
using make_uindex_tuple = sprout::make_integer_sequence<sprout::uindex_t, N>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<sprout::index_t N>
struct make_index_tuple
: public sprout::enable_make_indexes<
@ -18,9 +25,7 @@ namespace sprout {
::template transfer<sprout::index_tuple<> >::type
>
{};
//
// make_uindex_tuple
//
template<sprout::uindex_t N>
struct make_uindex_tuple
: public sprout::enable_make_indexes<
@ -28,6 +33,7 @@ namespace sprout {
::template transfer<sprout::uindex_tuple<> >::type
>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout
#endif // #ifndef SPROUT_INDEX_TUPLE_MAKE_INDEX_TUPLE_HPP

View file

@ -31,6 +31,7 @@ namespace std {
typedef typename sprout::tppack_c_at<I, T, Is...>::type type;
};
#if !SPROUT_USE_TEMPLATE_ALIASES
//
// tuple_size
//
@ -60,6 +61,8 @@ namespace std {
struct tuple_element<I, sprout::uindex_tuple<Indexes...> >
: public std::tuple_element<I, sprout::integer_sequence<sprout::uindex_t, Indexes...> >
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
#if defined(__clang__)
# pragma clang diagnostic pop
#endif
@ -77,6 +80,7 @@ namespace sprout {
return type();
}
#if !SPROUT_USE_TEMPLATE_ALIASES
//
// tuple_get
//
@ -98,6 +102,7 @@ namespace sprout {
typedef typename std::tuple_element<I, sprout::uindex_tuple<Indexes...> >::type type;
return type();
}
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout
#endif // #ifndef SPROUT_INDEX_TUPLE_TUPLE_HPP