From c71502f6b6500a7483947c862ced793c3a9c5e57 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sun, 12 May 2013 11:05:31 +0900 Subject: [PATCH] fix: index_tuple metafunctions as index_tuple aliases (if Template-aliases enabled) --- sprout/detail/sizeof.hpp | 17 ++++++ sprout/index_tuple/index_n.hpp | 13 ++--- sprout/index_tuple/index_range.hpp | 13 ++--- sprout/index_tuple/index_sequence_for.hpp | 5 ++ sprout/index_tuple/index_tuple.hpp | 8 +++ sprout/index_tuple/integer_n.hpp | 19 +++++-- sprout/index_tuple/integer_pack.hpp | 6 +++ sprout/index_tuple/integer_range.hpp | 54 +++++++++++++------- sprout/index_tuple/integer_sequence.hpp | 6 ++- sprout/index_tuple/make_index_sequence.hpp | 5 ++ sprout/index_tuple/make_integer_sequence.hpp | 10 ++-- 11 files changed, 111 insertions(+), 45 deletions(-) create mode 100644 sprout/detail/sizeof.hpp diff --git a/sprout/detail/sizeof.hpp b/sprout/detail/sizeof.hpp new file mode 100644 index 00000000..bcb7b902 --- /dev/null +++ b/sprout/detail/sizeof.hpp @@ -0,0 +1,17 @@ +#ifndef SPROUT_DETAIL_SIZEOF_HPP +#define SPROUT_DETAIL_SIZEOF_HPP + +#include +#include +#include + +namespace sprout { + namespace detail { + template + struct sizeof_pack + : public std::integral_constant + {}; + } // namespace detail +} // namespace sprout + +#endif // #ifndef SPROUT_DETAIL_SIZEOF_HPP diff --git a/sprout/index_tuple/index_n.hpp b/sprout/index_tuple/index_n.hpp index 37129a6a..6385be6e 100644 --- a/sprout/index_tuple/index_n.hpp +++ b/sprout/index_tuple/index_n.hpp @@ -5,7 +5,6 @@ #include #include #include -#include namespace sprout { // @@ -21,18 +20,14 @@ namespace sprout { #else // #if SPROUT_USE_TEMPLATE_ALIASES template struct index_n - : public sprout::enable_make_indexes< - typename sprout::integer_n::type - ::template transfer > - > + : public typename sprout::integer_n::type + ::template transfer > {}; template struct uindex_n - : public sprout::enable_make_indexes< - typename sprout::integer_n::type - ::template transfer > - > + : public typename sprout::integer_n::type + ::template transfer > {}; #endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace sprout diff --git a/sprout/index_tuple/index_range.hpp b/sprout/index_tuple/index_range.hpp index 2b9f479b..24ba9f10 100644 --- a/sprout/index_tuple/index_range.hpp +++ b/sprout/index_tuple/index_range.hpp @@ -4,7 +4,6 @@ #include #include #include -#include namespace sprout { // @@ -29,10 +28,8 @@ namespace sprout { typename std::make_signed::type Step = sprout::detail::integer_range_default_step::value > struct index_range - : public sprout::enable_make_indexes< - typename sprout::integer_range::type - ::template transfer > - > + : public typename sprout::integer_range::type + ::template transfer > {}; template< @@ -40,10 +37,8 @@ namespace sprout { typename std::make_signed::type Step = sprout::detail::integer_range_default_step::value > struct uindex_range - : public sprout::enable_make_indexes< - typename sprout::integer_range::type - ::template transfer > - > + : public typename sprout::integer_range::type + ::template transfer > {}; #endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace sprout diff --git a/sprout/index_tuple/index_sequence_for.hpp b/sprout/index_tuple/index_sequence_for.hpp index 9020caa3..2a251ceb 100644 --- a/sprout/index_tuple/index_sequence_for.hpp +++ b/sprout/index_tuple/index_sequence_for.hpp @@ -8,10 +8,15 @@ namespace sprout { // // index_sequence_for // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using index_sequence_for = sprout::uindex_pack; +#else // #if SPROUT_USE_TEMPLATE_ALIASES template struct index_sequence_for : public sprout::uindex_pack {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace sprout #endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_SEQUENCE_FOR_HPP diff --git a/sprout/index_tuple/index_tuple.hpp b/sprout/index_tuple/index_tuple.hpp index bf958169..d350552f 100644 --- a/sprout/index_tuple/index_tuple.hpp +++ b/sprout/index_tuple/index_tuple.hpp @@ -27,6 +27,10 @@ namespace sprout { struct rebind : public index_tuple {}; + public: + static SPROUT_CONSTEXPR type make() SPROUT_NOEXCEPT { + return type(); + } }; template @@ -39,6 +43,10 @@ namespace sprout { struct rebind : public uindex_tuple {}; + public: + static SPROUT_CONSTEXPR type make() SPROUT_NOEXCEPT { + return type(); + } }; #endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace sprout diff --git a/sprout/index_tuple/integer_n.hpp b/sprout/index_tuple/integer_n.hpp index 014d5e85..d4c2a8df 100644 --- a/sprout/index_tuple/integer_n.hpp +++ b/sprout/index_tuple/integer_n.hpp @@ -61,13 +61,26 @@ namespace sprout { I > {}; + + template + struct integer_n + : public sprout::enable_make_indexes< + sprout::detail::integer_n_impl + > + {}; } // namespace detail + // + // integer_range + // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using integer_n = typename sprout::detail::integer_n::type; +#else // #if SPROUT_USE_TEMPLATE_ALIASES template struct integer_n - : public sprout::enable_make_indexes< - sprout::detail::integer_n_impl - > + : public sprout::detail::integer_n {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace sprout #endif // #ifndef SPROUT_INDEX_TUPLE_INTEGER_N_HPP diff --git a/sprout/index_tuple/integer_pack.hpp b/sprout/index_tuple/integer_pack.hpp index 44dd495d..a651e29d 100644 --- a/sprout/index_tuple/integer_pack.hpp +++ b/sprout/index_tuple/integer_pack.hpp @@ -2,16 +2,22 @@ #define SPROUT_INDEX_TUPLE_INTEGER_PACK_HPP #include +#include #include namespace sprout { // // integer_pack // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using integer_pack = sprout::make_integer_sequence::value>; +#else // #if SPROUT_USE_TEMPLATE_ALIASES template struct integer_pack : public sprout::make_integer_sequence {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace sprout #endif // #ifndef SPROUT_INDEX_TUPLE_INTEGER_PACK_HPP diff --git a/sprout/index_tuple/integer_range.hpp b/sprout/index_tuple/integer_range.hpp index 2d035761..2a61e6fa 100644 --- a/sprout/index_tuple/integer_range.hpp +++ b/sprout/index_tuple/integer_range.hpp @@ -30,71 +30,87 @@ namespace sprout { {}; template::type Step, typename std::make_unsigned::type N, typename Enable = void> - struct integer_range_impl; + struct integer_range_dispatch; template::type Step, typename std::make_unsigned::type N> - struct integer_range_impl< + struct integer_range_dispatch< T, First, Step, N, typename std::enable_if<(N == 0)>::type > : public sprout::integer_sequence {}; template::type Step, typename std::make_unsigned::type N> - struct integer_range_impl< + struct integer_range_dispatch< T, First, Step, N, typename std::enable_if<(N == 1)>::type > : public sprout::integer_sequence {}; template::type Step, typename std::make_unsigned::type N> - struct integer_range_impl< + struct integer_range_dispatch< T, First, Step, N, typename std::enable_if<(N > 1 && N % 2 == 0)>::type > : public sprout::detail::integer_range_next_even< - T, typename sprout::detail::integer_range_impl::type, + T, typename sprout::detail::integer_range_dispatch::type, N / 2 * Step > {}; template::type Step, typename std::make_unsigned::type N> - struct integer_range_impl< + struct integer_range_dispatch< T, First, Step, N, typename std::enable_if<(N > 1 && N % 2 == 1)>::type > : public sprout::detail::integer_range_next_odd< - T, typename sprout::detail::integer_range_impl::type, + T, typename sprout::detail::integer_range_dispatch::type, N / 2 * Step, First + (N - 1) * Step > {}; template::type Step, typename Enable = void> - struct integer_range {}; + struct integer_range_impl {}; template::type Step> - struct integer_range< + struct integer_range_impl< T, First, Last, Step, typename std::enable_if<((First < Last && Step > 0) || (First > Last && Step < 0) || (First == Last))>::type > - : public sprout::detail::integer_range_impl< + : public sprout::detail::integer_range_dispatch< T, First, Step, (static_cast::type>(Last - First) + (Step > 0 ? Step - 1 : Step + 1)) / Step > {}; + + template< + typename T, T First, T Last, + typename std::make_signed::type Step + > + struct integer_range + : public sprout::enable_make_indexes< + sprout::detail::integer_range_impl + > + { + static_assert( + (First < Last && Step > 0) || (First > Last && Step < 0) || (First == Last), + "(First < Last && Step > 0) || (First > Last && Step < 0) || (First == Last)" + ); + }; } // namespace detail // // integer_range // +#if SPROUT_USE_TEMPLATE_ALIASES + template< + typename T, T First, T Last, + typename std::make_signed::type Step = sprout::detail::integer_range_default_step::value + > + using integer_range = typename sprout::detail::integer_range::type; +#else // #if SPROUT_USE_TEMPLATE_ALIASES template< typename T, T First, T Last, typename std::make_signed::type Step = sprout::detail::integer_range_default_step::value > struct integer_range - : public sprout::enable_make_indexes< - sprout::detail::integer_range - > - { - static_assert( - (First < Last && Step > 0) || (First > Last && Step < 0) || (First == Last), - "(First < Last && Step > 0) || (First > Last && Step < 0) || (First == Last)" - ); - }; + : public sprout::detail::integer_range + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace sprout #endif // #ifndef SPROUT_INDEX_TUPLE_INTEGER_RANGE_HPP diff --git a/sprout/index_tuple/integer_sequence.hpp b/sprout/index_tuple/integer_sequence.hpp index f2c65a51..55d09242 100644 --- a/sprout/index_tuple/integer_sequence.hpp +++ b/sprout/index_tuple/integer_sequence.hpp @@ -16,6 +16,10 @@ namespace sprout { struct rebind : public integer_sequence {}; + public: + static SPROUT_CONSTEXPR type make() SPROUT_NOEXCEPT { + return type(); + } public: typedef T value_type; template @@ -25,7 +29,7 @@ namespace sprout { public: SPROUT_STATIC_CONSTEXPR std::size_t static_size = sizeof...(Is); public: - static SPROUT_CONSTEXPR size_t size() noexcept { + static SPROUT_CONSTEXPR size_t size() SPROUT_NOEXCEPT { return static_size; } }; diff --git a/sprout/index_tuple/make_index_sequence.hpp b/sprout/index_tuple/make_index_sequence.hpp index 6267e1f3..0c1a890d 100644 --- a/sprout/index_tuple/make_index_sequence.hpp +++ b/sprout/index_tuple/make_index_sequence.hpp @@ -9,10 +9,15 @@ namespace sprout { // // make_index_sequence // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using make_index_sequence = sprout::make_uindex_tuple; +#else // #if SPROUT_USE_TEMPLATE_ALIASES template struct make_index_sequence : public sprout::make_uindex_tuple {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace sprout #endif // #ifndef SPROUT_INDEX_TUPLE_MAKE_INDEX_SEQUENCE_HPP diff --git a/sprout/index_tuple/make_integer_sequence.hpp b/sprout/index_tuple/make_integer_sequence.hpp index cc85b227..8cb699e9 100644 --- a/sprout/index_tuple/make_integer_sequence.hpp +++ b/sprout/index_tuple/make_integer_sequence.hpp @@ -3,18 +3,20 @@ #include #include -#include namespace sprout { // // make_integer_sequence // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using make_integer_sequence = sprout::integer_range; +#else // #if SPROUT_USE_TEMPLATE_ALIASES template struct make_integer_sequence - : public sprout::enable_make_indexes< - sprout::integer_range - > + : public sprout::integer_range {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace sprout #endif // #ifndef SPROUT_INDEX_TUPLE_MAKE_INTEGER_SEQUENCE_HPP