From c15de6136b0866cde23367f1f76db20039d2ff83 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Thu, 29 May 2014 00:25:37 +0900 Subject: [PATCH] fix tuple_element: support SFINAE-friendly --- sprout/array/tuple.hpp | 11 +- sprout/bit/flipbitsge.hpp | 2 +- sprout/bit/flipbitsle.hpp | 2 +- sprout/bit/rstbitsge.hpp | 2 +- sprout/bit/rstbitsle.hpp | 2 +- sprout/bit/setbitsge.hpp | 2 +- sprout/bit/setbitsle.hpp | 2 +- sprout/detail/nil_base.hpp | 19 ++++ sprout/endian_traits.hpp | 30 ++++- sprout/index_tuple/tuple.hpp | 8 +- sprout/pit/tuple.hpp | 3 +- sprout/random/random_result.hpp | 37 +++--- sprout/string/tuple.hpp | 10 +- sprout/sub_array/tuple.hpp | 3 +- sprout/tuple/sscrisk/cel/utility.hpp | 20 ++-- sprout/tuple/tuple/tuple_element.hpp | 48 ++++++-- sprout/type/algorithm.hpp | 5 + sprout/type/algorithm/accumulate.hpp | 32 ++++++ sprout/type/algorithm/contains.hpp | 41 +++++++ sprout/type/algorithm/find_index.hpp | 10 ++ sprout/type/algorithm/find_index_if.hpp | 10 ++ sprout/type/algorithm/fold.hpp | 53 +++++++++ sprout/type/algorithm/lower_bound_index.hpp | 10 ++ sprout/type/algorithm/partial_sum.hpp | 65 +++++++++++ sprout/type/algorithm/transform.hpp | 72 ++++++++++++ sprout/type/algorithm/upper_bound_index.hpp | 10 ++ .../type/boost/mpl/detail/tuple_element.hpp | 34 ++++++ sprout/type/boost/mpl/string.hpp | 6 +- sprout/type/boost/mpl/v_iter.hpp | 3 +- sprout/type/boost/mpl/vector.hpp | 6 +- sprout/type/boost/mpl/vector_c.hpp | 6 +- sprout/type/functional.hpp | 1 + sprout/type/functional/less.hpp | 5 + sprout/type/functional/plus.hpp | 56 +++++++++ sprout/type/integral_array.hpp | 2 +- sprout/type/iterator/advance.hpp | 6 + sprout/type/iterator/deref.hpp | 5 + sprout/type/iterator/distance.hpp | 10 ++ sprout/type/iterator/next.hpp | 5 + sprout/type/iterator/prev.hpp | 5 + sprout/type/operation.hpp | 5 + sprout/type/operation/append_back.hpp | 5 + sprout/type/operation/append_front.hpp | 5 + sprout/type/operation/at.hpp | 32 ++++++ sprout/type/operation/back.hpp | 32 ++++++ sprout/type/operation/empty.hpp | 35 ++++++ sprout/type/operation/front.hpp | 31 +++++ sprout/type/operation/pop_back.hpp | 5 + sprout/type/operation/pop_front.hpp | 5 + sprout/type/operation/push_back.hpp | 6 +- sprout/type/operation/push_front.hpp | 6 +- sprout/type/operation/size.hpp | 32 ++++++ sprout/type/seq/algorithm/find.hpp | 5 + sprout/type/seq/algorithm/find_if.hpp | 5 + sprout/type/string/string.hpp | 2 +- sprout/type/tuple.hpp | 18 ++- sprout/type/type_tuple.hpp | 107 ++++++++++++++++-- sprout/type/uniform_types.hpp | 11 +- sprout/utility.hpp | 1 + sprout/utility/pack.hpp | 11 +- sprout/utility/pair/tuple.hpp | 20 ++-- sprout/utility/use_default.hpp | 37 ++++++ sprout/uuid/tuple.hpp | 19 ++-- sprout/variant/tuple.hpp | 3 +- 64 files changed, 984 insertions(+), 113 deletions(-) create mode 100644 sprout/detail/nil_base.hpp create mode 100644 sprout/type/algorithm/accumulate.hpp create mode 100644 sprout/type/algorithm/contains.hpp create mode 100644 sprout/type/algorithm/fold.hpp create mode 100644 sprout/type/algorithm/partial_sum.hpp create mode 100644 sprout/type/algorithm/transform.hpp create mode 100644 sprout/type/boost/mpl/detail/tuple_element.hpp create mode 100644 sprout/type/functional/plus.hpp create mode 100644 sprout/type/operation/at.hpp create mode 100644 sprout/type/operation/back.hpp create mode 100644 sprout/type/operation/empty.hpp create mode 100644 sprout/type/operation/front.hpp create mode 100644 sprout/type/operation/size.hpp create mode 100644 sprout/utility/use_default.hpp diff --git a/sprout/array/tuple.hpp b/sprout/array/tuple.hpp index 0a4a9b87..7eae34d7 100644 --- a/sprout/array/tuple.hpp +++ b/sprout/array/tuple.hpp @@ -8,6 +8,7 @@ #ifndef SPROUT_ARRAY_TUPLE_HPP #define SPROUT_ARRAY_TUPLE_HPP +#include #include #include #include @@ -15,6 +16,8 @@ #include #include #include +#include +#include namespace sprout { // @@ -56,11 +59,9 @@ namespace std { // tuple_element // template - struct tuple_element > { - static_assert(I < N, "tuple_element<>: index out of range"); - public: - typedef T type; - }; + struct tuple_element > + : public std::conditional<(I < N), sprout::identity, sprout::detail::nil_base>::type + {}; #if defined(__clang__) # pragma clang diagnostic pop #endif diff --git a/sprout/bit/flipbitsge.hpp b/sprout/bit/flipbitsge.hpp index 47440cc8..ec3bc92f 100644 --- a/sprout/bit/flipbitsge.hpp +++ b/sprout/bit/flipbitsge.hpp @@ -21,7 +21,7 @@ namespace sprout { Integral >::type flipbitsge(Integral x, int b) SPROUT_NOEXCEPT { - return x ^ ~((Integral(1) << b)-1); + return x ^ ~((Integral(1) << b) - 1); } } // namespace sprout diff --git a/sprout/bit/flipbitsle.hpp b/sprout/bit/flipbitsle.hpp index 435f3880..55578958 100644 --- a/sprout/bit/flipbitsle.hpp +++ b/sprout/bit/flipbitsle.hpp @@ -21,7 +21,7 @@ namespace sprout { Integral >::type flipbitsle(Integral x, int b) SPROUT_NOEXCEPT { - return x ^ ((Integral(1) << (b+1))-1); + return x ^ ((Integral(1) << (b + 1)) - 1); } } // namespace sprout diff --git a/sprout/bit/rstbitsge.hpp b/sprout/bit/rstbitsge.hpp index 2b3886f0..9e3515b3 100644 --- a/sprout/bit/rstbitsge.hpp +++ b/sprout/bit/rstbitsge.hpp @@ -21,7 +21,7 @@ namespace sprout { Integral >::type rstbitsge(Integral x, int b) SPROUT_NOEXCEPT { - return x & ((Integral(1) << b)-1); + return x & ((Integral(1) << b) - 1); } } // namespace sprout diff --git a/sprout/bit/rstbitsle.hpp b/sprout/bit/rstbitsle.hpp index 7b266a7c..fcd9f9d0 100644 --- a/sprout/bit/rstbitsle.hpp +++ b/sprout/bit/rstbitsle.hpp @@ -21,7 +21,7 @@ namespace sprout { Integral >::type rstbitsle(Integral x, int b) SPROUT_NOEXCEPT { - return x & ~((Integral(1) << (b+1))-1); + return x & ~((Integral(1) << (b + 1)) - 1); } } // namespace sprout diff --git a/sprout/bit/setbitsge.hpp b/sprout/bit/setbitsge.hpp index d07c5bd0..ed91f1d3 100644 --- a/sprout/bit/setbitsge.hpp +++ b/sprout/bit/setbitsge.hpp @@ -21,7 +21,7 @@ namespace sprout { Integral >::type setbitsge(Integral x, int b) SPROUT_NOEXCEPT { - return x | ~((Integral(1) << b)-1); + return x | ~((Integral(1) << b) - 1); } } // namespace sprout diff --git a/sprout/bit/setbitsle.hpp b/sprout/bit/setbitsle.hpp index 694aa543..f6dd7f01 100644 --- a/sprout/bit/setbitsle.hpp +++ b/sprout/bit/setbitsle.hpp @@ -21,7 +21,7 @@ namespace sprout { Integral >::type setbitsle(Integral x, int b) SPROUT_NOEXCEPT { - return x | ((Integral(1) << (b+1))-1); + return x | ((Integral(1) << (b + 1)) - 1); } } // namespace sprout diff --git a/sprout/detail/nil_base.hpp b/sprout/detail/nil_base.hpp new file mode 100644 index 00000000..079372b1 --- /dev/null +++ b/sprout/detail/nil_base.hpp @@ -0,0 +1,19 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_DETAIL_NIL_BASE_HPP +#define SPROUT_DETAIL_NIL_BASE_HPP + +#include + +namespace sprout { + namespace detail { + struct nil_base {}; + } // namespace detail +} // namespace sprout + +#endif // #ifndef SPROUT_DETAIL_NIL_BASE_HPP diff --git a/sprout/endian_traits.hpp b/sprout/endian_traits.hpp index eb1a950a..fd2b34c1 100644 --- a/sprout/endian_traits.hpp +++ b/sprout/endian_traits.hpp @@ -25,12 +25,18 @@ namespace sprout { public: typedef T type; public: - static SPROUT_CONSTEXPR std::size_t size() { + static SPROUT_CONSTEXPR std::size_t + size() { return sizeof(type); } - static SPROUT_CONSTEXPR unsigned char get_byte(type const& t, std::size_t) { + static SPROUT_CONSTEXPR unsigned char + get_byte(type const& t, std::size_t) { return static_cast(t); } + static SPROUT_CXX14_CONSTEXPR void + set_byte(type& t, std::size_t, unsigned char value) { + t = static_cast(value); + } }; template class default_big_endian_traits< @@ -40,15 +46,22 @@ namespace sprout { public: typedef T type; public: - static SPROUT_CONSTEXPR std::size_t size() { + static SPROUT_CONSTEXPR std::size_t + size() { return sizeof(type); } - static SPROUT_CONSTEXPR unsigned char get_byte(type const& t, std::size_t i) { + static SPROUT_CONSTEXPR unsigned char + get_byte(type const& t, std::size_t i) { return static_cast( (t & (UCHAR_MAX << CHAR_BIT * ((size() - 1) - i))) >> CHAR_BIT * ((size() - 1) - i) ); } + static SPROUT_CXX14_CONSTEXPR void + set_byte(type& t, std::size_t i, unsigned char value) { + t &= ~(UCHAR_MAX << CHAR_BIT * ((size() - 1) - i)); + t |= (value << CHAR_BIT * ((size() - 1) - i)); + } }; template @@ -67,6 +80,10 @@ namespace sprout { static SPROUT_CONSTEXPR unsigned char get_byte(type const& t, std::size_t) { return static_cast(t); } + static SPROUT_CXX14_CONSTEXPR void + set_byte(type& t, std::size_t, unsigned char value) { + t = static_cast(value); + } }; template class default_little_endian_traits< @@ -85,6 +102,11 @@ namespace sprout { >> CHAR_BIT * i ); } + static SPROUT_CXX14_CONSTEXPR void + set_byte(type& t, std::size_t i, unsigned char value) { + t &= ~(UCHAR_MAX << CHAR_BIT * i); + t |= (value << CHAR_BIT * i); + } }; } // namespace detail diff --git a/sprout/index_tuple/tuple.hpp b/sprout/index_tuple/tuple.hpp index 71af5e0d..52c5a192 100644 --- a/sprout/index_tuple/tuple.hpp +++ b/sprout/index_tuple/tuple.hpp @@ -32,11 +32,9 @@ namespace std { // tuple_element // template - struct tuple_element > { - static_assert(I < sizeof...(Is), "tuple_element<>: index out of range"); - public: - typedef typename sprout::pack_element_c::type type; - }; + struct tuple_element > + : public sprout::pack_element_c + {}; #if !(SPROUT_USE_TEMPLATE_ALIASES && !defined(SPROUT_WORKAROUND_NO_TEMPLATE_ARGUMENT_DEDUCTION_WITH_ALIASES)) // diff --git a/sprout/pit/tuple.hpp b/sprout/pit/tuple.hpp index dca73cd7..11baee47 100644 --- a/sprout/pit/tuple.hpp +++ b/sprout/pit/tuple.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace sprout { @@ -59,7 +60,7 @@ namespace std { // template struct tuple_element > - : public std::tuple_element + : public sprout::tuples::tuple_element {}; #if defined(__clang__) # pragma clang diagnostic pop diff --git a/sprout/random/random_result.hpp b/sprout/random/random_result.hpp index 070fe84f..b5f99bfa 100644 --- a/sprout/random/random_result.hpp +++ b/sprout/random/random_result.hpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include namespace sprout { namespace random { @@ -65,14 +67,12 @@ namespace sprout { generator_type generator_; public: SPROUT_CONSTEXPR random_result() - : result_() - , generator_() + : result_(), generator_() {} random_result(random_result const&) = default; SPROUT_CONSTEXPR random_result( result_type result, - engine_type const& engine, - distribution_type const& distribution + engine_type const& engine, distribution_type const& distribution ) : result_(result) , generator_(engine, distribution) @@ -199,16 +199,11 @@ namespace sprout { generator_type generator_; public: SPROUT_CONSTEXPR random_result() - : result_() - , generator_() + : result_(), generator_() {} random_result(random_result const&) = default; - SPROUT_CONSTEXPR random_result( - result_type result, - engine_type const& engine - ) - : result_(result) - , generator_(engine) + SPROUT_CONSTEXPR random_result(result_type result, engine_type const& engine) + : result_(result), generator_(engine) {} SPROUT_CONSTEXPR random_result operator()() const { return generator_(); @@ -316,16 +311,18 @@ namespace sprout { namespace detail { template struct tuple_element_impl; + template + struct tuple_element_impl > + : public sprout::detail::nil_base + {}; template - struct tuple_element_impl<0, sprout::random::random_result > { - public: - typedef typename sprout::random::random_result::result_type type; - }; + struct tuple_element_impl<0, sprout::random::random_result > + : public sprout::identity::result_type> + {}; template - struct tuple_element_impl<1, sprout::random::random_result > { - public: - typedef typename sprout::random::random_result::generator_type type; - }; + struct tuple_element_impl<1, sprout::random::random_result > + : public sprout::identity::generator_type> + {}; template struct get_impl; diff --git a/sprout/string/tuple.hpp b/sprout/string/tuple.hpp index 3b851a02..3a7ebe97 100644 --- a/sprout/string/tuple.hpp +++ b/sprout/string/tuple.hpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include namespace sprout { // @@ -56,11 +58,9 @@ namespace std { // tuple_element // template - struct tuple_element > { - static_assert(I < N, "tuple_element<>: index out of range"); - public: - typedef T type; - }; + struct tuple_element > + : public std::conditional<(I < N), sprout::identity, sprout::detail::nil_base>::type + {}; #if defined(__clang__) # pragma clang diagnostic pop #endif diff --git a/sprout/sub_array/tuple.hpp b/sprout/sub_array/tuple.hpp index 3ebaabb5..7145e6f4 100644 --- a/sprout/sub_array/tuple.hpp +++ b/sprout/sub_array/tuple.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include namespace sprout { @@ -66,7 +67,7 @@ namespace std { // template struct tuple_element > - : public std::tuple_element::type> + : public sprout::tuples::tuple_element::type> {}; #if defined(__clang__) # pragma clang diagnostic pop diff --git a/sprout/tuple/sscrisk/cel/utility.hpp b/sprout/tuple/sscrisk/cel/utility.hpp index 0b7e167b..798987d5 100644 --- a/sprout/tuple/sscrisk/cel/utility.hpp +++ b/sprout/tuple/sscrisk/cel/utility.hpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include namespace sprout { namespace tuples { @@ -28,16 +30,18 @@ namespace sprout { namespace detail { template struct tuple_element_impl; + template + struct tuple_element_impl > + : public sprout::detail::nil_base + {}; template - struct tuple_element_impl<0, sscrisk::cel::pair > { - public: - typedef T1 type; - }; + struct tuple_element_impl<0, sscrisk::cel::pair > + : public sprout::identity + {}; template - struct tuple_element_impl<1, sscrisk::cel::pair > { - public: - typedef T2 type; - }; + struct tuple_element_impl<1, sscrisk::cel::pair > + : public sprout::identity + {}; } // namespace detail // // tuple_element diff --git a/sprout/tuple/tuple/tuple_element.hpp b/sprout/tuple/tuple/tuple_element.hpp index 83a1c666..f077626c 100644 --- a/sprout/tuple/tuple/tuple_element.hpp +++ b/sprout/tuple/tuple/tuple_element.hpp @@ -12,33 +12,61 @@ #include #include #include +#include namespace sprout { namespace tuples { // // tuple_element // + namespace detail { + template::value)> + struct tuple_element_default; + template + struct tuple_element_default + : public sprout::detail::nil_base + {}; + template + struct tuple_element_default + : public std::tuple_element + {}; + } // namespace detail template struct tuple_element - : public std::tuple_element + : public sprout::tuples::detail::tuple_element_default {}; + + namespace detail { + template + struct tuple_element_default + : public std::add_const< + typename sprout::tuples::tuple_element::type + > + {}; + template + struct tuple_element_default + : public std::add_volatile< + typename sprout::tuples::tuple_element::type + > + {}; + template + struct tuple_element_default + : public std::add_cv< + typename sprout::tuples::tuple_element::type + > + {}; + } // namespace detail template struct tuple_element - : public std::add_const< - typename sprout::tuples::tuple_element::type - > + : public sprout::tuples::detail::tuple_element_default {}; template struct tuple_element - : public std::add_volatile< - typename sprout::tuples::tuple_element::type - > + : public sprout::tuples::detail::tuple_element_default {}; template struct tuple_element - : public std::add_cv< - typename sprout::tuples::tuple_element::type - > + : public sprout::tuples::detail::tuple_element_default {}; } // namespace tuples diff --git a/sprout/type/algorithm.hpp b/sprout/type/algorithm.hpp index 5344d64c..57d9b699 100644 --- a/sprout/type/algorithm.hpp +++ b/sprout/type/algorithm.hpp @@ -13,5 +13,10 @@ #include #include #include +#include +#include +#include +#include +#include #endif // #ifndef SPROUT_TYPE_ALGORITHM_HPP diff --git a/sprout/type/algorithm/accumulate.hpp b/sprout/type/algorithm/accumulate.hpp new file mode 100644 index 00000000..377aaac2 --- /dev/null +++ b/sprout/type/algorithm/accumulate.hpp @@ -0,0 +1,32 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_ALGORITHM_ACCUMLATE_HPP +#define SPROUT_TYPE_ALGORITHM_ACCUMLATE_HPP + +#include +#include +#include + +namespace sprout { + namespace types { + // + // accumulate + // + template + struct accumulate + : public sprout::types::fold + {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using accumulate_t = typename sprout::types::accumulate::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_ALGORITHM_ACCUMLATE_HPP diff --git a/sprout/type/algorithm/contains.hpp b/sprout/type/algorithm/contains.hpp new file mode 100644 index 00000000..768190a8 --- /dev/null +++ b/sprout/type/algorithm/contains.hpp @@ -0,0 +1,41 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_ALGORITHM_CONTAINTS_HPP +#define SPROUT_TYPE_ALGORITHM_CONTAINTS_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace types { + // + // contains + // + template + struct contains + : public sprout::integral_constant< + bool, + sprout::types::find_index::value != sprout::types::tuple_size::value + > + {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using contains_t = typename sprout::types::contains::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool contains_v = sprout::types::contains::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_ALGORITHM_CONTAINTS_HPP diff --git a/sprout/type/algorithm/find_index.hpp b/sprout/type/algorithm/find_index.hpp index 24e8ac1c..73844a54 100644 --- a/sprout/type/algorithm/find_index.hpp +++ b/sprout/type/algorithm/find_index.hpp @@ -47,6 +47,16 @@ namespace sprout { struct find_index : public sprout::types::detail::find_index_impl {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using find_index_t = typename sprout::types::find_index::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR std::size_t find_index_v = sprout::types::find_index::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace types } // namespace sprout diff --git a/sprout/type/algorithm/find_index_if.hpp b/sprout/type/algorithm/find_index_if.hpp index 4e5892ef..bea9cf64 100644 --- a/sprout/type/algorithm/find_index_if.hpp +++ b/sprout/type/algorithm/find_index_if.hpp @@ -47,6 +47,16 @@ namespace sprout { struct find_index_if : public sprout::types::detail::find_index_if_impl {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using find_index_if_t = typename sprout::types::find_index_if::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR std::size_t find_index_if_v = sprout::types::find_index_if::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace types } // namespace sprout diff --git a/sprout/type/algorithm/fold.hpp b/sprout/type/algorithm/fold.hpp new file mode 100644 index 00000000..0d1e8f02 --- /dev/null +++ b/sprout/type/algorithm/fold.hpp @@ -0,0 +1,53 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_ALGORITHM_FOLD_HPP +#define SPROUT_TYPE_ALGORITHM_FOLD_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace types { + namespace detail { + template< + typename Tuple, typename T, typename BinaryOp, std::size_t I, + bool = (I == sprout::types::tuple_size::value) + > + struct fold_impl; + template + struct fold_impl + : public sprout::identity + {}; + template + struct fold_impl + : public sprout::types::detail::fold_impl< + Tuple, + typename BinaryOp::template apply::type>::type, + BinaryOp, + I + 1 + > + {}; + } // namespace detail + // + // fold + // + template + struct fold + : public sprout::types::detail::fold_impl + {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using fold_t = typename sprout::types::fold::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_ALGORITHM_FOLD_HPP diff --git a/sprout/type/algorithm/lower_bound_index.hpp b/sprout/type/algorithm/lower_bound_index.hpp index 801eeb0e..2ffbc980 100644 --- a/sprout/type/algorithm/lower_bound_index.hpp +++ b/sprout/type/algorithm/lower_bound_index.hpp @@ -63,6 +63,16 @@ namespace sprout { struct lower_bound_index : public sprout::types::detail::lower_bound_index_impl::value> {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using lower_bound_index_t = typename sprout::types::lower_bound_index::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR std::size_t lower_bound_index_v = sprout::types::lower_bound_index::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace types } // namespace sprout diff --git a/sprout/type/algorithm/partial_sum.hpp b/sprout/type/algorithm/partial_sum.hpp new file mode 100644 index 00000000..16e39c87 --- /dev/null +++ b/sprout/type/algorithm/partial_sum.hpp @@ -0,0 +1,65 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_ALGORITHM_PARTIAL_SUM_HPP +#define SPROUT_TYPE_ALGORITHM_PARTIAL_SUM_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace types { + namespace detail { + template< + typename Tuple, typename BinaryOp, std::size_t I, std::size_t N, typename T, typename... Types + > + struct partial_sum_impl + : public sprout::types::detail::partial_sum_impl< + Tuple, BinaryOp, I + 1, N - 1, + typename BinaryOp::template apply::type>::type, + Types..., T + > + {}; + template + struct partial_sum_impl + : public sprout::types::rebind_types< + Tuple + >::template apply< + Types..., T + > + {}; + + template + struct partial_sum + : public sprout::types::detail::partial_sum_impl::type> + {}; + template + struct partial_sum + : public sprout::types::rebind_types< + Tuple + >::template apply<> + {}; + } // namespace detail + // + // partial_sum + // + template + struct partial_sum + : public sprout::types::detail::partial_sum::value> + {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using partial_sum_t = typename sprout::types::partial_sum::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_ALGORITHM_PARTIAL_SUM_HPP diff --git a/sprout/type/algorithm/transform.hpp b/sprout/type/algorithm/transform.hpp new file mode 100644 index 00000000..a91a8434 --- /dev/null +++ b/sprout/type/algorithm/transform.hpp @@ -0,0 +1,72 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_ALGORITHM_TRANSFORM_HPP +#define SPROUT_TYPE_ALGORITHM_TRANSFORM_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace types { + namespace detail { + template + struct transform_impl; + template + struct transform_impl > + : public sprout::types::rebind_types< + Tuple + >::template apply< + typename UnaryOp::template apply< + typename sprout::types::tuple_element::type + >::type... + > + {}; + + template + struct transform2_impl; + template + struct transform2_impl > + : public sprout::types::rebind_types< + Tuple1 + >::template apply< + typename BinaryOp::template apply< + typename sprout::types::tuple_element::type, + typename sprout::types::tuple_element::type + >::type... + > + {}; + } // namespace detail + // + // transform + // + template + struct transform + : public sprout::types::detail::transform2_impl< + Tuple, Tuple2OrUnaryOp, BinaryOp, + typename sprout::tuple_indexes::type + > + {}; + template + struct transform + : public sprout::types::detail::transform_impl< + Tuple, UnaryOp, + typename sprout::tuple_indexes::type + > + {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using transform_t = typename sprout::types::transform::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_ALGORITHM_TRANSFORM_HPP diff --git a/sprout/type/algorithm/upper_bound_index.hpp b/sprout/type/algorithm/upper_bound_index.hpp index 5710f27e..90d39e95 100644 --- a/sprout/type/algorithm/upper_bound_index.hpp +++ b/sprout/type/algorithm/upper_bound_index.hpp @@ -63,6 +63,16 @@ namespace sprout { struct upper_bound_index : public sprout::types::detail::upper_bound_index_impl::value> {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using upper_bound_index_t = typename sprout::types::upper_bound_index::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR std::size_t upper_bound_index_v = sprout::types::upper_bound_index::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace types } // namespace sprout diff --git a/sprout/type/boost/mpl/detail/tuple_element.hpp b/sprout/type/boost/mpl/detail/tuple_element.hpp new file mode 100644 index 00000000..dbf6789f --- /dev/null +++ b/sprout/type/boost/mpl/detail/tuple_element.hpp @@ -0,0 +1,34 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_BOOST_MPL_DETAIL_TUPLE_ELEMENT_HPP +#define SPROUT_TYPE_BOOST_MPL_DETAIL_TUPLE_ELEMENT_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace types { + namespace detail { + template::value)> + struct mpl_tuple_element; + template + struct mpl_tuple_element + : public sprout::detail::nil_base + {}; + template + struct mpl_tuple_element + : public boost::mpl::at_c + {}; + } // namespace detail + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_BOOST_MPL_DETAIL_TUPLE_ELEMENT_HPP diff --git a/sprout/type/boost/mpl/string.hpp b/sprout/type/boost/mpl/string.hpp index 3e30758a..678b789c 100644 --- a/sprout/type/boost/mpl/string.hpp +++ b/sprout/type/boost/mpl/string.hpp @@ -8,18 +8,20 @@ #ifndef SPROUT_TYPE_BOOST_MPL_STRING_HPP #define SPROUT_TYPE_BOOST_MPL_STRING_HPP -#include #include #include #include #include #include #include +#include +#include #include #include #include #include #include +#include namespace sprout { namespace types { @@ -50,7 +52,7 @@ namespace sprout { // template struct tuple_element > - : public boost::mpl::at_c, I> + : public sprout::types::detail::mpl_tuple_element > {}; // diff --git a/sprout/type/boost/mpl/v_iter.hpp b/sprout/type/boost/mpl/v_iter.hpp index 18bbaefd..92fdfa7b 100644 --- a/sprout/type/boost/mpl/v_iter.hpp +++ b/sprout/type/boost/mpl/v_iter.hpp @@ -8,10 +8,11 @@ #ifndef SPROUT_TYPE_BOOST_MPL_V_ITER_HPP #define SPROUT_TYPE_BOOST_MPL_V_ITER_HPP -#include #include #include #include +#include +#include #include #include #include diff --git a/sprout/type/boost/mpl/vector.hpp b/sprout/type/boost/mpl/vector.hpp index 0c51d9f9..4f382ad7 100644 --- a/sprout/type/boost/mpl/vector.hpp +++ b/sprout/type/boost/mpl/vector.hpp @@ -8,12 +8,14 @@ #ifndef SPROUT_TYPE_BOOST_MPL_VECTOR_HPP #define SPROUT_TYPE_BOOST_MPL_VECTOR_HPP -#include #include #include #include +#include +#include #include #include +#include namespace sprout { namespace types { @@ -44,7 +46,7 @@ namespace sprout { // template struct tuple_element > - : public boost::mpl::at_c, I> + : public sprout::types::detail::mpl_tuple_element > {}; } // namespace types } // namespace sprout diff --git a/sprout/type/boost/mpl/vector_c.hpp b/sprout/type/boost/mpl/vector_c.hpp index 67fc71e1..2fd21eca 100644 --- a/sprout/type/boost/mpl/vector_c.hpp +++ b/sprout/type/boost/mpl/vector_c.hpp @@ -8,12 +8,14 @@ #ifndef SPROUT_TYPE_BOOST_MPL_VECTOR_C_HPP #define SPROUT_TYPE_BOOST_MPL_VECTOR_C_HPP -#include #include #include #include +#include +#include #include #include +#include namespace sprout { namespace types { @@ -44,7 +46,7 @@ namespace sprout { // template struct tuple_element > - : public boost::mpl::at_c, I> + : public sprout::types::detail::mpl_tuple_element > {}; } // namespace types } // namespace sprout diff --git a/sprout/type/functional.hpp b/sprout/type/functional.hpp index 5202ec81..50c2ba4f 100644 --- a/sprout/type/functional.hpp +++ b/sprout/type/functional.hpp @@ -10,5 +10,6 @@ #include #include +#include #endif // #ifndef SPROUT_TYPE_FUNCTIONAL_HPP diff --git a/sprout/type/functional/less.hpp b/sprout/type/functional/less.hpp index 1a38a1f9..c5173ffe 100644 --- a/sprout/type/functional/less.hpp +++ b/sprout/type/functional/less.hpp @@ -31,6 +31,11 @@ namespace sprout { : public sprout::types::less {}; }; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool less_v = sprout::types::less::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace types } // namespace sprout diff --git a/sprout/type/functional/plus.hpp b/sprout/type/functional/plus.hpp new file mode 100644 index 00000000..df99bd0b --- /dev/null +++ b/sprout/type/functional/plus.hpp @@ -0,0 +1,56 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_FUNCTIONAL_PLUS_HPP +#define SPROUT_TYPE_FUNCTIONAL_PLUS_HPP + +#include +#include +#include + +namespace sprout { + namespace types { + // + // plus + // + template + struct plus + : public sprout::integral_constant + {}; + template + struct plus + : public sprout::integral_constant< + typename sprout::common_decay::type, + (T::value + U::value) + > + {}; + + // + // plus_mf + // + template + struct plus_mf { + public: + template + struct apply + : public sprout::types::plus + {}; + }; + + // + // plus_ + // + typedef sprout::types::plus_mf<> plus_; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR typename sprout::types::plus::value_type plus_v = sprout::types::plus::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_PLUS_HPP diff --git a/sprout/type/integral_array.hpp b/sprout/type/integral_array.hpp index a72c2a43..d0ada070 100644 --- a/sprout/type/integral_array.hpp +++ b/sprout/type/integral_array.hpp @@ -50,7 +50,7 @@ namespace std { // template struct tuple_element > - : public std::tuple_element...> > + : public sprout::types::tuple_element...> > {}; #if defined(__clang__) # pragma clang diagnostic pop diff --git a/sprout/type/iterator/advance.hpp b/sprout/type/iterator/advance.hpp index 690ce7f6..5542c87b 100644 --- a/sprout/type/iterator/advance.hpp +++ b/sprout/type/iterator/advance.hpp @@ -9,6 +9,7 @@ #define SPROUT_TYPE_ITERATOR_ADVANCE_HPP #include +#include namespace sprout { namespace types { @@ -32,6 +33,11 @@ namespace sprout { struct advance : public sprout::types::advance {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using advance_t = typename sprout::types::advance::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace types } // namespace sprout diff --git a/sprout/type/iterator/deref.hpp b/sprout/type/iterator/deref.hpp index dce59f2f..7d99e44f 100644 --- a/sprout/type/iterator/deref.hpp +++ b/sprout/type/iterator/deref.hpp @@ -19,6 +19,11 @@ namespace sprout { struct deref : public Iterator {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using deref_t = typename sprout::types::deref::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace types } // namespace sprout diff --git a/sprout/type/iterator/distance.hpp b/sprout/type/iterator/distance.hpp index 5fe36ac6..9508695d 100644 --- a/sprout/type/iterator/distance.hpp +++ b/sprout/type/iterator/distance.hpp @@ -53,6 +53,16 @@ namespace sprout { struct distance : public sprout::types::detail::distance_impl {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using distance_t = typename sprout::types::distance::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR std::size_t distance_v = sprout::types::distance::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace types } // namespace sprout diff --git a/sprout/type/iterator/next.hpp b/sprout/type/iterator/next.hpp index 87c80b2f..0e5e2693 100644 --- a/sprout/type/iterator/next.hpp +++ b/sprout/type/iterator/next.hpp @@ -33,6 +33,11 @@ namespace sprout { struct next : public sprout::types::next {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using next_t = typename sprout::types::next::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace types } // namespace sprout diff --git a/sprout/type/iterator/prev.hpp b/sprout/type/iterator/prev.hpp index 5c73af2c..700325e2 100644 --- a/sprout/type/iterator/prev.hpp +++ b/sprout/type/iterator/prev.hpp @@ -33,6 +33,11 @@ namespace sprout { struct prev : public sprout::types::prev {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using prev_t = typename sprout::types::prev::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace types } // namespace sprout diff --git a/sprout/type/operation.hpp b/sprout/type/operation.hpp index 26a88135..ccc7c5d8 100644 --- a/sprout/type/operation.hpp +++ b/sprout/type/operation.hpp @@ -9,6 +9,11 @@ #define SPROUT_TYPE_OPERATION_HPP #include +#include +#include +#include +#include +#include #include #include #include diff --git a/sprout/type/operation/append_back.hpp b/sprout/type/operation/append_back.hpp index dbd67bac..5b7502f9 100644 --- a/sprout/type/operation/append_back.hpp +++ b/sprout/type/operation/append_back.hpp @@ -39,6 +39,11 @@ namespace sprout { typename sprout::tuple_indexes::type >::type type; }; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using append_back_t = typename sprout::types::append_back::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace types } // namespace sprout diff --git a/sprout/type/operation/append_front.hpp b/sprout/type/operation/append_front.hpp index fdc41f80..e51e59d8 100644 --- a/sprout/type/operation/append_front.hpp +++ b/sprout/type/operation/append_front.hpp @@ -39,6 +39,11 @@ namespace sprout { typename sprout::tuple_indexes::type >::type type; }; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using append_front_t = typename sprout::types::append_front::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace types } // namespace sprout diff --git a/sprout/type/operation/at.hpp b/sprout/type/operation/at.hpp new file mode 100644 index 00000000..ca0d3f66 --- /dev/null +++ b/sprout/type/operation/at.hpp @@ -0,0 +1,32 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_OPERATION_AT_HPP +#define SPROUT_TYPE_OPERATION_AT_HPP + +#include +#include +#include + +namespace sprout { + namespace types { + // + // at + // + template + struct at + : public sprout::types::tuple_element + {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using at_t = typename sprout::types::at::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_OPERATION_AT_HPP diff --git a/sprout/type/operation/back.hpp b/sprout/type/operation/back.hpp new file mode 100644 index 00000000..932a6514 --- /dev/null +++ b/sprout/type/operation/back.hpp @@ -0,0 +1,32 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_OPERATION_BACK_HPP +#define SPROUT_TYPE_OPERATION_BACK_HPP + +#include +#include +#include + +namespace sprout { + namespace types { + // + // back + // + template + struct back + : public sprout::types::at::value - 1)> + {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using back_t = typename sprout::types::back::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_OPERATION_BACK_HPP diff --git a/sprout/type/operation/empty.hpp b/sprout/type/operation/empty.hpp new file mode 100644 index 00000000..fe2df245 --- /dev/null +++ b/sprout/type/operation/empty.hpp @@ -0,0 +1,35 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_OPERATION_EMPTY_HPP +#define SPROUT_TYPE_OPERATION_EMPTY_HPP + +#include +#include +#include + +namespace sprout { + namespace types { + // + // empty + // + template + struct empty + : public sprout::integral_constant< + bool, + (sprout::types::tuple_size::value == 0) + > + {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool empty_v = sprout::types::empty::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_OPERATION_EMPTY_HPP diff --git a/sprout/type/operation/front.hpp b/sprout/type/operation/front.hpp new file mode 100644 index 00000000..681ba91b --- /dev/null +++ b/sprout/type/operation/front.hpp @@ -0,0 +1,31 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_OPERATION_FRONT_HPP +#define SPROUT_TYPE_OPERATION_FRONT_HPP + +#include +#include + +namespace sprout { + namespace types { + // + // front + // + template + struct front + : public sprout::types::at + {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using front_t = typename sprout::types::front::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_OPERATION_FRONT_HPP diff --git a/sprout/type/operation/pop_back.hpp b/sprout/type/operation/pop_back.hpp index 20510eb8..b930016b 100644 --- a/sprout/type/operation/pop_back.hpp +++ b/sprout/type/operation/pop_back.hpp @@ -36,6 +36,11 @@ namespace sprout { typename sprout::make_index_tuple::value - 1>::type >::type type; }; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using pop_back_t = typename sprout::types::pop_back::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace types } // namespace sprout diff --git a/sprout/type/operation/pop_front.hpp b/sprout/type/operation/pop_front.hpp index dae12354..e92de1fb 100644 --- a/sprout/type/operation/pop_front.hpp +++ b/sprout/type/operation/pop_front.hpp @@ -36,6 +36,11 @@ namespace sprout { typename sprout::index_range<1, sprout::types::tuple_size::value>::type >::type type; }; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using pop_front_t = typename sprout::types::pop_front::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace types } // namespace sprout diff --git a/sprout/type/operation/push_back.hpp b/sprout/type/operation/push_back.hpp index 85b23ff5..1cbb0d6a 100644 --- a/sprout/type/operation/push_back.hpp +++ b/sprout/type/operation/push_back.hpp @@ -21,7 +21,6 @@ namespace sprout { // template struct push_back { - static_assert(sizeof...(Ts) >= 1, "sizeof...(Ts) >= 1"); private: template struct apply_impl; @@ -39,6 +38,11 @@ namespace sprout { typename sprout::tuple_indexes::type >::type type; }; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using push_back_t = typename sprout::types::push_back::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace types } // namespace sprout diff --git a/sprout/type/operation/push_front.hpp b/sprout/type/operation/push_front.hpp index 9076e5bf..34bc4396 100644 --- a/sprout/type/operation/push_front.hpp +++ b/sprout/type/operation/push_front.hpp @@ -21,7 +21,6 @@ namespace sprout { // template struct push_front { - static_assert(sizeof...(Ts) >= 1, "sizeof...(Ts) >= 1"); private: template struct apply_impl; @@ -39,6 +38,11 @@ namespace sprout { typename sprout::tuple_indexes::type >::type type; }; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using push_front_t = typename sprout::types::push_front::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace types } // namespace sprout diff --git a/sprout/type/operation/size.hpp b/sprout/type/operation/size.hpp new file mode 100644 index 00000000..f9a5b3b0 --- /dev/null +++ b/sprout/type/operation/size.hpp @@ -0,0 +1,32 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_OPERATION_SIZE_HPP +#define SPROUT_TYPE_OPERATION_SIZE_HPP + +#include +#include +#include + +namespace sprout { + namespace types { + // + // size + // + template + struct size + : public sprout::types::tuple_size + {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR std::size_t size_v = sprout::types::size::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_OPERATION_SIZE_HPP diff --git a/sprout/type/seq/algorithm/find.hpp b/sprout/type/seq/algorithm/find.hpp index 4deff0ba..a8bb3d0e 100644 --- a/sprout/type/seq/algorithm/find.hpp +++ b/sprout/type/seq/algorithm/find.hpp @@ -76,6 +76,11 @@ namespace sprout { T > {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using find_t = typename sprout::types::seq::find::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace seq } // namespace types } // namespace sprout diff --git a/sprout/type/seq/algorithm/find_if.hpp b/sprout/type/seq/algorithm/find_if.hpp index fb7cb808..7cf255de 100644 --- a/sprout/type/seq/algorithm/find_if.hpp +++ b/sprout/type/seq/algorithm/find_if.hpp @@ -76,6 +76,11 @@ namespace sprout { Predicate > {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using find_if_t = typename sprout::types::seq::find_if::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES } // namespace seq } // namespace types } // namespace sprout diff --git a/sprout/type/string/string.hpp b/sprout/type/string/string.hpp index 5f7dcc4d..457eaa70 100644 --- a/sprout/type/string/string.hpp +++ b/sprout/type/string/string.hpp @@ -48,7 +48,7 @@ namespace std { // template struct tuple_element > - : public std::tuple_element > + : public sprout::types::tuple_element > {}; #if defined(__clang__) # pragma clang diagnostic pop diff --git a/sprout/type/tuple.hpp b/sprout/type/tuple.hpp index 12f479e7..2014e51f 100644 --- a/sprout/type/tuple.hpp +++ b/sprout/type/tuple.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace sprout { namespace types { @@ -42,8 +43,23 @@ namespace sprout { // template struct tuple_element - : public std::tuple_element + : public sprout::tuples::tuple_element {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using begin_t = typename sprout::types::begin::type; + template + using end_t = typename sprout::types::end::type; + + template + using tuple_element_t = typename sprout::types::tuple_element::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR std::size_t tuple_size_v = sprout::types::tuple_size::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace types } // namespace sprout diff --git a/sprout/type/type_tuple.hpp b/sprout/type/type_tuple.hpp index 83921644..2a169a99 100644 --- a/sprout/type/type_tuple.hpp +++ b/sprout/type/type_tuple.hpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace sprout { namespace types { @@ -54,6 +55,10 @@ namespace sprout { namespace detail { template struct head_element; + template<> + struct head_element > + : public sprout::detail::nil_base + {}; template struct head_element > : public sprout::identity @@ -61,6 +66,10 @@ namespace sprout { template struct tuple_head; + template<> + struct tuple_head > + : public sprout::detail::nil_base + {}; template struct tuple_head > : public sprout::identity > @@ -68,6 +77,10 @@ namespace sprout { template struct tuple_tail; + template<> + struct tuple_tail > + : public sprout::detail::nil_base + {}; template struct tuple_tail > : public sprout::identity > @@ -93,35 +106,49 @@ namespace sprout { static sprout::types::type_tuple eval(typename sprout::types::detail::dummy_index::type*..., Types*...); }; - template + template::value)> struct tuple_drop_impl; + template + struct tuple_drop_impl + : public sprout::detail::nil_base + {}; template - struct tuple_drop_impl > + struct tuple_drop_impl, true> : public sprout::identity::type> ::eval(static_cast*>(0)...) )>::type {}; template - struct tuple_drop; - template - struct tuple_drop > - : public sprout::types::detail::tuple_drop_impl > + struct tuple_drop + : public sprout::types::detail::tuple_drop_impl {}; + template::value)> + struct tuple_element_impl; template - struct tuple_element; + struct tuple_element_impl + : public sprout::detail::nil_base + {}; template - struct tuple_element > + struct tuple_element_impl, true> : public sprout::types::detail::head_element< typename sprout::types::detail::tuple_drop >::type > {}; + template + struct tuple_element + : public sprout::types::detail::tuple_element_impl + {}; - template + template::value)> struct tuple_take_impl; + template + struct tuple_take_impl + : public sprout::detail::nil_base + {}; template - struct tuple_take_impl, sprout::index_tuple > + struct tuple_take_impl, sprout::index_tuple, true> : public sprout::identity< sprout::types::type_tuple< typename sprout::types::detail::tuple_element >::type... @@ -166,4 +193,64 @@ namespace std { #endif } // namespace std +namespace sprout { + namespace types { + // + // push_back + // + template + struct push_back; + template + struct push_back, Ts...> + : public sprout::identity > + {}; + // + // push_front + // + template + struct push_front; + template + struct push_front, Ts...> + : public sprout::identity > + {}; + // + // pop_back + // + template + struct pop_back; + template + struct pop_back > + : public sprout::types::detail::tuple_take<(sizeof...(Types) - 1), sprout::types::type_tuple > + {}; + // + // pop_front + // + template + struct pop_front; + template + struct pop_front > + : public sprout::identity > + {}; + + // + // append_back + // + template + struct append_back; + template + struct append_back > + : public sprout::types::push_back + {}; + // + // append_front + // + template + struct append_front; + template + struct append_front > + : public sprout::types::push_front + {}; + } // namespace types +} // namespace sprout + #endif // #ifndef SPROUT_TYPE_TYPE_TUPLE_HPP diff --git a/sprout/type/uniform_types.hpp b/sprout/type/uniform_types.hpp index f174dbe7..5a72671a 100644 --- a/sprout/type/uniform_types.hpp +++ b/sprout/type/uniform_types.hpp @@ -8,6 +8,7 @@ #ifndef SPROUT_TYPE_UNIFORM_TYPES_HPP #define SPROUT_TYPE_UNIFORM_TYPES_HPP +#include #include #include #include @@ -16,6 +17,8 @@ #include #include #include +#include +#include namespace sprout { namespace types { @@ -69,11 +72,9 @@ namespace std { // tuple_element // template - struct tuple_element > { - static_assert(I < N, "tuple_element<>: index out of range"); - public: - typedef T type; - }; + struct tuple_element > + : public std::conditional<(I < N), sprout::identity, sprout::detail::nil_base>::type + {}; #if defined(__clang__) # pragma clang diagnostic pop #endif diff --git a/sprout/utility.hpp b/sprout/utility.hpp index b8d04590..dde969ea 100644 --- a/sprout/utility.hpp +++ b/sprout/utility.hpp @@ -18,5 +18,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_UTILITY_HPP diff --git a/sprout/utility/pack.hpp b/sprout/utility/pack.hpp index 8000ef4e..96a44603 100644 --- a/sprout/utility/pack.hpp +++ b/sprout/utility/pack.hpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace sprout { // @@ -30,7 +31,7 @@ namespace sprout { // template struct pack_element_c - : public sprout::pack_element...>::type + : public sprout::pack_element...> {}; // @@ -59,10 +60,16 @@ namespace sprout { // // head_element // + template + struct head_element; template - struct head_element + struct head_element : public sprout::identity {}; + template<> + struct head_element<> + : public sprout::detail::nil_base + {}; // // head_get diff --git a/sprout/utility/pair/tuple.hpp b/sprout/utility/pair/tuple.hpp index b5e69375..e4c335f8 100644 --- a/sprout/utility/pair/tuple.hpp +++ b/sprout/utility/pair/tuple.hpp @@ -13,22 +13,26 @@ #include #include #include +#include +#include namespace sprout { namespace tuples { namespace detail { template struct tuple_element_impl; + template + struct tuple_element_impl > + : public sprout::detail::nil_base + {}; template - struct tuple_element_impl<0, sprout::pair > { - public: - typedef T1 type; - }; + struct tuple_element_impl<0, sprout::pair > + : public sprout::identity + {}; template - struct tuple_element_impl<1, sprout::pair > { - public: - typedef T2 type; - }; + struct tuple_element_impl<1, sprout::pair > + : public sprout::identity + {}; template struct get_impl; diff --git a/sprout/utility/use_default.hpp b/sprout/utility/use_default.hpp new file mode 100644 index 00000000..9c6642d4 --- /dev/null +++ b/sprout/utility/use_default.hpp @@ -0,0 +1,37 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + 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.sprout.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_UTILITY_USE_DEFAULT_HPP +#define SPROUT_UTILITY_USE_DEFAULT_HPP + +#include +#include + +namespace sprout { + // + // use_default + // + struct use_default; + + // + // is_use_default + // + template + struct is_use_default + : public sprout::is_same + {}; + + // + // select_default + // + template + struct select_default + : public std::conditional::value, Default, T> + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_USE_DEFAULT_HPP diff --git a/sprout/uuid/tuple.hpp b/sprout/uuid/tuple.hpp index 192ba296..479bba37 100644 --- a/sprout/uuid/tuple.hpp +++ b/sprout/uuid/tuple.hpp @@ -8,6 +8,7 @@ #ifndef SPROUT_UUID_TUPLE_HPP #define SPROUT_UUID_TUPLE_HPP +#include #include #include #include @@ -15,6 +16,8 @@ #include #include #include +#include +#include namespace sprout { // @@ -48,21 +51,17 @@ namespace std { // tuple_size // template<> - struct tuple_size { - public: - typedef sprout::integral_constant type; - SPROUT_STATIC_CONSTEXPR std::size_t value = type::value; - }; + struct tuple_size + : public sprout::integral_constant + {}; // // tuple_element // template - struct tuple_element { - static_assert(I < 16, "tuple_element<>: index out of range"); - public: - typedef sprout::uuids::uuid::value_type type; - }; + struct tuple_element + : public std::conditional<(I < 16), sprout::identity, sprout::detail::nil_base>::type + {}; #if defined(__clang__) # pragma clang diagnostic pop #endif diff --git a/sprout/variant/tuple.hpp b/sprout/variant/tuple.hpp index 75aa3079..afcdcc7e 100644 --- a/sprout/variant/tuple.hpp +++ b/sprout/variant/tuple.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace sprout { @@ -63,7 +64,7 @@ namespace std { // template struct tuple_element > - : public std::tuple_element::tuple_type> + : public sprout::tuples::tuple_element::tuple_type> {}; #if defined(__clang__) # pragma clang diagnostic pop