From 331aaa3559e17f616aa8ef1d69cf67d1e981c0ca Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sun, 31 Mar 2013 13:39:26 +0900 Subject: [PATCH] add index_tuple/integer_seq --- sprout/index_tuple.hpp | 8 ++- sprout/index_tuple/index_n.hpp | 71 +++++------------------ sprout/index_tuple/index_range.hpp | 76 +++++-------------------- sprout/index_tuple/index_tuple.hpp | 36 ++++++++---- sprout/index_tuple/integer_n.hpp | 73 ++++++++++++++++++++++++ sprout/index_tuple/integer_range.hpp | 76 +++++++++++++++++++++++++ sprout/index_tuple/integer_seq.hpp | 32 +++++++++++ sprout/index_tuple/make_index_tuple.hpp | 33 +++++++++++ sprout/index_tuple/make_indexes.hpp | 6 +- sprout/index_tuple/make_integer_seq.hpp | 20 +++++++ sprout/index_tuple/pack_indexes.hpp | 20 ------- sprout/index_tuple/tuple.hpp | 44 +++++++++++--- sprout/string/alias.hpp | 12 +--- sprout/utility/string_ref/alias.hpp | 31 +++++++--- 14 files changed, 358 insertions(+), 180 deletions(-) create mode 100644 sprout/index_tuple/integer_n.hpp create mode 100644 sprout/index_tuple/integer_range.hpp create mode 100644 sprout/index_tuple/integer_seq.hpp create mode 100644 sprout/index_tuple/make_index_tuple.hpp create mode 100644 sprout/index_tuple/make_integer_seq.hpp delete mode 100644 sprout/index_tuple/pack_indexes.hpp diff --git a/sprout/index_tuple.hpp b/sprout/index_tuple.hpp index 19bc2b92..f62b3236 100644 --- a/sprout/index_tuple.hpp +++ b/sprout/index_tuple.hpp @@ -2,11 +2,15 @@ #define SPROUT_INDEX_TUPLE_HPP #include +#include #include #include -#include +#include +#include +#include #include +#include #include -#include +#include #endif // #ifndef SPROUT_INDEX_TUPLE_HPP diff --git a/sprout/index_tuple/index_n.hpp b/sprout/index_tuple/index_n.hpp index cf284bf8..19eea94d 100644 --- a/sprout/index_tuple/index_n.hpp +++ b/sprout/index_tuple/index_n.hpp @@ -2,74 +2,29 @@ #define SPROUT_INDEX_TUPLE_INDEX_N_HPP #include -#include #include -#include +#include #include namespace sprout { // // index_n // - namespace detail { - template - struct index_n_next; - template - struct index_n_next> { - public: - typedef sprout::index_tuple type; - }; - - template - struct index_n_next2; - template - struct index_n_next2, Tail> { - public: - typedef sprout::index_tuple type; - }; - - template - struct index_n_impl; - template - struct index_n_impl< - I, N, - typename std::enable_if<(N == 0)>::type - > { - public: - typedef sprout::index_tuple<> type; - }; - template - struct index_n_impl< - I, N, - typename std::enable_if<(N == 1)>::type - > { - public: - typedef sprout::index_tuple type; - }; - template - 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::type - > - {}; - template - 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::type, - I - > - {}; - } // namespace detail template struct index_n : public sprout::detail::make_indexes_helper< - sprout::detail::index_n_impl + typename sprout::integer_n::type + ::template transfer >::type + > + {}; + // + // uindex_n + // + template + struct uindex_n + : public sprout::detail::make_indexes_helper< + typename sprout::integer_n::type + ::template transfer >::type > {}; } // namespace sprout diff --git a/sprout/index_tuple/index_range.hpp b/sprout/index_tuple/index_range.hpp index 4fb1c63b..723bcd5d 100644 --- a/sprout/index_tuple/index_range.hpp +++ b/sprout/index_tuple/index_range.hpp @@ -2,78 +2,30 @@ #define SPROUT_INDEX_TUPLE_INDEX_RANGE_HPP #include -#include #include #include +#include #include namespace sprout { // // index_range // - namespace detail { - template - struct index_range_next; - template - struct index_range_next, Next> { - public: - typedef sprout::index_tuple type; - }; - - template - struct index_range_next2; - template - struct index_range_next2, Next, Tail> { - public: - typedef sprout::index_tuple type; - }; - - template - struct index_range_impl; - template - struct index_range_impl< - First, Step, N, - typename std::enable_if<(N == 0)>::type - > { - public: - typedef sprout::index_tuple<> type; - }; - template - struct index_range_impl< - First, Step, N, - typename std::enable_if<(N == 1)>::type - > { - public: - typedef sprout::index_tuple type; - }; - template - 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::type, - First + N / 2 * Step - > - {}; - template - 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::type, - First + N / 2 * Step, - First + (N - 1) * Step - > - {}; - } // namespace detail - template + template struct index_range : public sprout::detail::make_indexes_helper< - sprout::detail::index_range_impl< - First, Step, ((Last - First) + (Step - 1)) / Step - > + typename sprout::integer_range::type + ::template transfer >::type + > + {}; + // + // uindex_range + // + template + struct uindex_range + : public sprout::detail::make_indexes_helper< + typename sprout::integer_range::type + ::template transfer >::type > {}; } // namespace sprout diff --git a/sprout/index_tuple/index_tuple.hpp b/sprout/index_tuple/index_tuple.hpp index 69138ef3..6590f904 100644 --- a/sprout/index_tuple/index_tuple.hpp +++ b/sprout/index_tuple/index_tuple.hpp @@ -3,26 +3,42 @@ #include #include +#include namespace sprout { // // index_t - // - typedef std::ptrdiff_t index_t; - - // // index_tuple // + typedef std::ptrdiff_t index_t; template - struct index_tuple { + struct index_tuple + : public sprout::integer_seq + { public: typedef index_tuple type; - typedef sprout::index_t value_type; - public: - SPROUT_STATIC_CONSTEXPR std::size_t size = sizeof...(Indexes); + template + struct rebind + : public index_tuple + {}; + }; + + // + // uindex_t + // uindex_tuple + // + typedef std::size_t uindex_t; + template + struct uindex_tuple + : public sprout::integer_seq + { + public: + typedef uindex_tuple type; + template + struct rebind + : public uindex_tuple + {}; }; - template - SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::index_tuple::size; } // namespace sprout #endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_TUPLE_HPP diff --git a/sprout/index_tuple/integer_n.hpp b/sprout/index_tuple/integer_n.hpp new file mode 100644 index 00000000..43a5a91d --- /dev/null +++ b/sprout/index_tuple/integer_n.hpp @@ -0,0 +1,73 @@ +#ifndef SPROUT_INDEX_TUPLE_INTEGER_N_HPP +#define SPROUT_INDEX_TUPLE_INTEGER_N_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + // + // integer_n + // + namespace detail { + template + struct integer_n_next_even; + template + struct integer_n_next_even > + : public sprout::integer_seq + {}; + + template + struct integer_n_next_even_odd; + template + struct integer_n_next_even_odd, Tail> + : public sprout::integer_seq + {}; + + template + struct integer_n_impl; + template + struct integer_n_impl< + T, I, N, + typename std::enable_if<(N == 0)>::type + > + : public sprout::integer_seq + {}; + template + struct integer_n_impl< + T, I, N, + typename std::enable_if<(N == 1)>::type + > + : public sprout::integer_seq + {}; + template + 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::type + > + {}; + template + 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::type, + I + > + {}; + } // namespace detail + template + struct integer_n + : public sprout::detail::make_indexes_helper< + sprout::detail::integer_n_impl + > + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_INDEX_TUPLE_INTEGER_N_HPP diff --git a/sprout/index_tuple/integer_range.hpp b/sprout/index_tuple/integer_range.hpp new file mode 100644 index 00000000..44053d1f --- /dev/null +++ b/sprout/index_tuple/integer_range.hpp @@ -0,0 +1,76 @@ +#ifndef SPROUT_INDEX_TUPLE_INTEGER_RANGE_HPP +#define SPROUT_INDEX_TUPLE_INTEGER_RANGE_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + // + // integer_range + // + namespace detail { + template + struct integer_range_next_even; + template + struct integer_range_next_even, Next> + : public sprout::integer_seq + {}; + + template + struct integer_range_next_odd; + template + struct integer_range_next_odd, Next, Tail> + : public sprout::integer_seq + {}; + + template + struct integer_range_impl; + template + struct integer_range_impl< + T, First, Step, N, + typename std::enable_if<(N == 0)>::type + > + : public sprout::integer_seq + {}; + template + struct integer_range_impl< + T, First, Step, N, + typename std::enable_if<(N == 1)>::type + > + : public sprout::integer_seq + {}; + template + struct integer_range_impl< + 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, + First + N / 2 * Step + > + {}; + template + struct integer_range_impl< + 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, + First + N / 2 * Step, First + (N - 1) * Step + > + {}; + } // namespace detail + template + struct integer_range + : public sprout::detail::make_indexes_helper< + sprout::detail::integer_range_impl< + T, First, Step, ((Last - First) + (Step - 1)) / Step + > + > + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_INDEX_TUPLE_INTEGER_RANGE_HPP diff --git a/sprout/index_tuple/integer_seq.hpp b/sprout/index_tuple/integer_seq.hpp new file mode 100644 index 00000000..002843f8 --- /dev/null +++ b/sprout/index_tuple/integer_seq.hpp @@ -0,0 +1,32 @@ +#ifndef SPROUT_INDEX_TUPLE_INTEGER_SEQ_HPP +#define SPROUT_INDEX_TUPLE_INTEGER_SEQ_HPP + +#include +#include + +namespace sprout { + // + // integer_seq + // + template + struct integer_seq { + public: + typedef integer_seq type; + template + struct rebind + : public integer_seq + {}; + public: + typedef T value_type; + template + struct transfer + : public Seq::template rebind + {}; + public: + SPROUT_STATIC_CONSTEXPR std::size_t size = sizeof...(Is); + }; + template + SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::integer_seq::size; +} // namespace sprout + +#endif // #ifndef SPROUT_INDEX_TUPLE_INTEGER_SEQ_HPP diff --git a/sprout/index_tuple/make_index_tuple.hpp b/sprout/index_tuple/make_index_tuple.hpp new file mode 100644 index 00000000..056af9c8 --- /dev/null +++ b/sprout/index_tuple/make_index_tuple.hpp @@ -0,0 +1,33 @@ +#ifndef SPROUT_INDEX_TUPLE_MAKE_INDEX_TUPLE_HPP +#define SPROUT_INDEX_TUPLE_MAKE_INDEX_TUPLE_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + // + // make_index_tuple + // + template + struct make_index_tuple + : public sprout::detail::make_indexes_helper< + typename sprout::make_integer_seq::type + ::template transfer >::type + > + {}; + // + // make_uindex_tuple + // + template + struct make_uindex_tuple + : public sprout::detail::make_indexes_helper< + typename sprout::make_integer_seq::type + ::template transfer >::type + > + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_INDEX_TUPLE_MAKE_INDEX_TUPLE_HPP diff --git a/sprout/index_tuple/make_indexes.hpp b/sprout/index_tuple/make_indexes.hpp index 21cd51c5..13069326 100644 --- a/sprout/index_tuple/make_indexes.hpp +++ b/sprout/index_tuple/make_indexes.hpp @@ -7,10 +7,10 @@ namespace sprout { // // make_indexes // - template - inline SPROUT_CONSTEXPR typename IndexTupleType::type + template + inline SPROUT_CONSTEXPR typename Seq::type make_indexes() { - return typename IndexTupleType::type(); + return typename Seq::type(); } } // namespace sprout diff --git a/sprout/index_tuple/make_integer_seq.hpp b/sprout/index_tuple/make_integer_seq.hpp new file mode 100644 index 00000000..2d3519eb --- /dev/null +++ b/sprout/index_tuple/make_integer_seq.hpp @@ -0,0 +1,20 @@ +#ifndef SPROUT_INDEX_TUPLE_MAKE_INTEGER_SEQ_HPP +#define SPROUT_INDEX_TUPLE_MAKE_INTEGER_SEQ_HPP + +#include +#include +#include + +namespace sprout { + // + // make_integer_seq + // + template + struct make_integer_seq + : public sprout::detail::make_indexes_helper< + sprout::integer_range + > + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_INDEX_TUPLE_MAKE_INTEGER_SEQ_HPP diff --git a/sprout/index_tuple/pack_indexes.hpp b/sprout/index_tuple/pack_indexes.hpp deleted file mode 100644 index a6e6bfa1..00000000 --- a/sprout/index_tuple/pack_indexes.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef SPROUT_INDEX_TUPLE_PACK_INDEXES_HPP -#define SPROUT_INDEX_TUPLE_PACK_INDEXES_HPP - -#include -#include -#include - -namespace sprout { - // - // pack_indexes - // - template - 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 diff --git a/sprout/index_tuple/tuple.hpp b/sprout/index_tuple/tuple.hpp index 99c3456d..ca6c2ae4 100644 --- a/sprout/index_tuple/tuple.hpp +++ b/sprout/index_tuple/tuple.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace std { @@ -12,23 +13,52 @@ namespace std { # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wmismatched-tags" #endif + // + // tuple_size + // + template + struct tuple_size > + : public std::integral_constant + {}; + // + // tuple_element + // + template + struct tuple_element > { + static_assert(I < sizeof...(Is), "tuple_element<>: index out of range"); + public: + typedef T type; + }; + // // tuple_size // template struct tuple_size > - : public std::integral_constant + : public std::tuple_size > {}; - // // tuple_element // template - struct tuple_element > { - static_assert(I < sizeof...(Indexes), "tuple_element<>: index out of range"); - public: - typedef sprout::index_t type; - }; + struct tuple_element > + : public std::tuple_element > + {}; + + // + // tuple_size + // + template + struct tuple_size > + : public std::tuple_size > + {}; + // + // tuple_element + // + template + struct tuple_element > + : public std::tuple_element > + {}; #if defined(__clang__) # pragma clang diagnostic pop #endif diff --git a/sprout/string/alias.hpp b/sprout/string/alias.hpp index 9344530d..85005816 100644 --- a/sprout/string/alias.hpp +++ b/sprout/string/alias.hpp @@ -11,22 +11,16 @@ namespace sprout { #if SPROUT_USE_TEMPLATE_ALIASES // // string + // wstring + // u16string + // u32string // template using string = sprout::basic_string; - // - // wstring - // template using wstring = sprout::basic_string; - // - // u16string - // template using u16string = sprout::basic_string; - // - // u32string - // template using u32string = sprout::basic_string; #endif // #if SPROUT_USE_TEMPLATE_ALIASES diff --git a/sprout/utility/string_ref/alias.hpp b/sprout/utility/string_ref/alias.hpp index 3fdf1274..dcfe695b 100644 --- a/sprout/utility/string_ref/alias.hpp +++ b/sprout/utility/string_ref/alias.hpp @@ -2,25 +2,38 @@ #define SPROUT_UTILITY_STRING_REF_ALIAS_HPP #include +#include #include namespace sprout { // // string_ref - // - typedef sprout::basic_string_ref string_ref; - // // wstring_ref - // - typedef sprout::basic_string_ref wstring_ref; - // // u16string_ref - // - typedef sprout::basic_string_ref u16string_ref; - // // u32string_ref // + typedef sprout::basic_string_ref string_ref; + typedef sprout::basic_string_ref wstring_ref; + typedef sprout::basic_string_ref u16string_ref; typedef sprout::basic_string_ref u32string_ref; + // + // string_view + // wstring_view + // u16string_view + // u32string_view + // + typedef sprout::basic_string_ref string_view; + typedef sprout::basic_string_ref wstring_view; + typedef sprout::basic_string_ref u16string_view; + typedef sprout::basic_string_ref u32string_view; + +#if SPROUT_USE_TEMPLATE_ALIASES + // + // basic_string_view + // + template > + using basic_string_view = sprout::basic_string_ref; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace sprout #endif // #ifndef SPROUT_UTILITY_STRING_REF_ALIAS_HPP