From 39bb8e8adaf9ea1d8acaf63ef2b2c7e5cd92192a Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Wed, 6 Aug 2014 00:00:43 +0900 Subject: [PATCH] reimplementation types::tuple_element, types::tuple_size --- sprout/tuple/tuple/tuple_element.hpp | 16 +- sprout/tuple/tuple/tuple_size.hpp | 16 +- sprout/type/tuple.hpp | 83 ++++++++++- sprout/type/type_tuple.hpp | 190 +----------------------- sprout/type/type_tuple_decl.hpp | 212 +++++++++++++++++++++++++++ sprout/type_traits.hpp | 1 + sprout/type_traits/has_value.hpp | 26 ++++ sprout/utility/pack.hpp | 2 +- 8 files changed, 350 insertions(+), 196 deletions(-) create mode 100644 sprout/type/type_tuple_decl.hpp create mode 100644 sprout/type_traits/has_value.hpp diff --git a/sprout/tuple/tuple/tuple_element.hpp b/sprout/tuple/tuple/tuple_element.hpp index f077626c..45fcd71a 100644 --- a/sprout/tuple/tuple/tuple_element.hpp +++ b/sprout/tuple/tuple/tuple_element.hpp @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #include namespace sprout { @@ -20,7 +23,18 @@ namespace sprout { // tuple_element // namespace detail { - template::value)> + template >::value> + struct valid_tuple_index; + template + struct valid_tuple_index + : public sprout::false_type + {}; + template + struct valid_tuple_index + : public sprout::integral_constant::value)> + {}; + + template >::value && sprout::tuples::detail::valid_tuple_index::value> struct tuple_element_default; template struct tuple_element_default diff --git a/sprout/tuple/tuple/tuple_size.hpp b/sprout/tuple/tuple/tuple_size.hpp index 21aab7a2..bb5fa9b3 100644 --- a/sprout/tuple/tuple/tuple_size.hpp +++ b/sprout/tuple/tuple/tuple_size.hpp @@ -12,15 +12,29 @@ #include #include #include +#include +#include namespace sprout { namespace tuples { // // tuple_size // + namespace detail { + template >::value> + struct tuple_size_default; + template + struct tuple_size_default + : public sprout::detail::nil_base + {}; + template + struct tuple_size_default + : public sprout::detail::type_traits_wrapper > + {}; + } // namespace detail template struct tuple_size - : public sprout::detail::type_traits_wrapper > + : public sprout::tuples::detail::tuple_size_default {}; template struct tuple_size diff --git a/sprout/type/tuple.hpp b/sprout/type/tuple.hpp index 2014e51f..551a8284 100644 --- a/sprout/type/tuple.hpp +++ b/sprout/type/tuple.hpp @@ -12,7 +12,13 @@ #include #include #include +#include +#include +#include +#include #include +#include +#include namespace sprout { namespace types { @@ -34,16 +40,83 @@ namespace sprout { // // tuple_size // - template + namespace detail { + template + struct tuple_size_impl + : public sprout::detail::nil_base + {}; + template class TupleClass, typename... Ts> + struct tuple_size_impl > + : public sprout::integral_constant + {}; + template class IntegerSequenceClass, typename T, T... Vs> + struct tuple_size_impl > + : public sprout::integral_constant + {}; + template class IndexTupleClass, sprout::index_t... Vs> + struct tuple_size_impl > + : public sprout::integral_constant + {}; + template class UIndexTupleClass, sprout::uindex_t... Vs> + struct tuple_size_impl > + : public sprout::integral_constant + {}; + + template >::value> + struct tuple_size_default; + template + struct tuple_size_default + : public sprout::types::detail::tuple_size_impl + {}; + template + struct tuple_size_default + : public sprout::tuples::tuple_size + {}; + } // namespace detail + template struct tuple_size - : public sprout::detail::type_traits_wrapper > + : public sprout::types::detail::tuple_size_default {}; + // // tuple_element // - template + namespace detail { + template + struct tuple_element_default_impl + : public sprout::detail::nil_base + {}; + template class TupleClass, typename... Ts> + struct tuple_element_default_impl > + : public std::tuple_element > + {}; + template class IntegerSequenceClass, typename T, T... Vs> + struct tuple_element_default_impl > + : public std::tuple_element...> > + {}; + template class IndexTupleClass, sprout::index_t... Vs> + struct tuple_element_default_impl > + : public std::tuple_element...> > + {}; + template class UIndexTupleClass, sprout::uindex_t... Vs> + struct tuple_element_default_impl > + : public std::tuple_element...> > + {}; + + template >::value> + struct tuple_element_default; + template + struct tuple_element_default + : public sprout::types::detail::tuple_element_default_impl + {}; + template + struct tuple_element_default + : public sprout::tuples::tuple_element + {}; + } // namespace detail + template struct tuple_element - : public sprout::tuples::tuple_element + : public sprout::types::detail::tuple_element_default {}; #if SPROUT_USE_TEMPLATE_ALIASES @@ -63,4 +136,6 @@ namespace sprout { } // namespace types } // namespace sprout +#include + #endif // #ifndef SPROUT_TYPE_TUPLE_HPP diff --git a/sprout/type/type_tuple.hpp b/sprout/type/type_tuple.hpp index 9449baf3..354197d1 100644 --- a/sprout/type/type_tuple.hpp +++ b/sprout/type/type_tuple.hpp @@ -8,19 +8,11 @@ #ifndef SPROUT_TYPE_TYPE_TUPLE_HPP #define SPROUT_TYPE_TYPE_TUPLE_HPP -#include -#include #include #include -#include -#include -#include #include #include -#include -#include -#include -#include +#include namespace sprout { namespace types { @@ -38,186 +30,6 @@ namespace sprout { }; template SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::types::type_tuple::static_size; - - namespace detail { - template - struct head_element; - template<> - struct head_element > - : public sprout::detail::nil_base - {}; - template - struct head_element > - : public sprout::identity - {}; - - template - struct tuple_head; - template<> - struct tuple_head > - : public sprout::detail::nil_base - {}; - template - struct tuple_head > - : public sprout::identity > - {}; - - template - struct tuple_tail; - template<> - struct tuple_tail > - : public sprout::detail::nil_base - {}; - template - struct tuple_tail > - : public sprout::identity > - {}; - - template - struct dummy_index - : public sprout::identity - {}; - - template - struct tuple_cat; - template - struct tuple_cat, sprout::types::type_tuple > - : public sprout::identity > - {}; - - template - struct tuple_drop_helper; - template - struct tuple_drop_helper > { - template - static sprout::types::type_tuple - eval(typename sprout::types::detail::dummy_index::type*..., Types*...); - }; - template::value)> - struct tuple_drop_impl; - template - struct tuple_drop_impl - : public sprout::detail::nil_base - {}; - template - struct tuple_drop_impl, true> - : public sprout::identity::type> - ::eval(static_cast*>(0)...) - )>::type - {}; - template - struct tuple_drop - : public sprout::types::detail::tuple_drop_impl - {}; - - template::value)> - struct tuple_element_impl; - template - struct tuple_element_impl - : public sprout::detail::nil_base - {}; - template - 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::value)> - struct tuple_take_impl; - template - struct tuple_take_impl - : public sprout::detail::nil_base - {}; - template - struct tuple_take_impl, sprout::index_tuple, true> - : public sprout::identity< - sprout::types::type_tuple< - typename sprout::types::detail::tuple_element >::type... - > - >::type - {}; - template - struct tuple_take; - template - struct tuple_take > - : public sprout::types::detail::tuple_take_impl, typename sprout::make_index_tuple::type> - {}; - } // namespace detail - } // namespace types - - using sprout::types::type_tuple; - using sprout::types::rebind_types; -} // namespace sprout - -namespace std { -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wmismatched-tags" -#endif - // - // tuple_size - // - template - struct tuple_size > - : public sprout::integral_constant - {}; - - // - // tuple_element - // - template - struct tuple_element > - : public sprout::types::detail::tuple_element > - {}; -#if defined(__clang__) -# pragma clang diagnostic pop -#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 > - {}; } // namespace types } // namespace sprout diff --git a/sprout/type/type_tuple_decl.hpp b/sprout/type/type_tuple_decl.hpp new file mode 100644 index 00000000..de31b66f --- /dev/null +++ b/sprout/type/type_tuple_decl.hpp @@ -0,0 +1,212 @@ +/*============================================================================= + 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_TYPE_TUPLE_DECL_HPP +#define SPROUT_TYPE_TYPE_TUPLE_DECL_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace types { + // + // type_tuple + // + template + struct type_tuple; + + namespace detail { + template + struct head_element; + template<> + struct head_element > + : public sprout::detail::nil_base + {}; + template + struct head_element > + : public sprout::identity + {}; + + template + struct tuple_head; + template<> + struct tuple_head > + : public sprout::detail::nil_base + {}; + template + struct tuple_head > + : public sprout::identity > + {}; + + template + struct tuple_tail; + template<> + struct tuple_tail > + : public sprout::detail::nil_base + {}; + template + struct tuple_tail > + : public sprout::identity > + {}; + + template + struct dummy_index + : public sprout::identity + {}; + + template + struct tuple_cat; + template + struct tuple_cat, sprout::types::type_tuple > + : public sprout::identity > + {}; + + template + struct tuple_drop_helper; + template + struct tuple_drop_helper > { + template + static sprout::types::type_tuple + eval(typename sprout::types::detail::dummy_index::type*..., Types*...); + }; + template::value)> + struct tuple_drop_impl; + template + struct tuple_drop_impl + : public sprout::detail::nil_base + {}; + template + struct tuple_drop_impl, true> + : public sprout::identity::type> + ::eval(static_cast*>(0)...) + )>::type + {}; + template + struct tuple_drop + : public sprout::types::detail::tuple_drop_impl + {}; + + template::value)> + struct tuple_element_impl; + template + struct tuple_element_impl + : public sprout::detail::nil_base + {}; + template + 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::value)> + struct tuple_take_impl; + template + struct tuple_take_impl + : public sprout::detail::nil_base + {}; + template + struct tuple_take_impl, sprout::index_tuple, true> + : public sprout::identity< + sprout::types::type_tuple< + typename sprout::types::detail::tuple_element >::type... + > + >::type + {}; + template + struct tuple_take; + template + struct tuple_take > + : public sprout::types::detail::tuple_take_impl, typename sprout::make_index_tuple::type> + {}; + } // namespace detail + } // namespace types + + using sprout::types::type_tuple; + using sprout::types::rebind_types; +} // namespace sprout + +namespace std { +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wmismatched-tags" +#endif + // + // tuple_size + // + template + struct tuple_size > + : public sprout::integral_constant + {}; + + // + // tuple_element + // + template + struct tuple_element > + : public sprout::types::detail::tuple_element > + {}; +#if defined(__clang__) +# pragma clang diagnostic pop +#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 > + {}; + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_TYPE_TUPLE_DECL_HPP diff --git a/sprout/type_traits.hpp b/sprout/type_traits.hpp index 911c012a..a7baf937 100644 --- a/sprout/type_traits.hpp +++ b/sprout/type_traits.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/sprout/type_traits/has_value.hpp b/sprout/type_traits/has_value.hpp new file mode 100644 index 00000000..a18a0d05 --- /dev/null +++ b/sprout/type_traits/has_value.hpp @@ -0,0 +1,26 @@ +/*============================================================================= + 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_TRAITS_HAS_VALUE_HPP +#define SPROUT_TYPE_TRAITS_HAS_VALUE_HPP + +#include +#include + +namespace sprout { + // + // has_value + // + SPROUT_HAS_XXX_VALUE_DEF_LAZY(value); + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool has_value_v = sprout::has_value::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_TRAITS_HAS_VALUE_HPP diff --git a/sprout/utility/pack.hpp b/sprout/utility/pack.hpp index 96a44603..f3caa1e5 100644 --- a/sprout/utility/pack.hpp +++ b/sprout/utility/pack.hpp @@ -11,10 +11,10 @@ #include #include #include -#include #include #include #include +#include #include namespace sprout {