From 1bb9336d34e5d15e49338de2929f3da9d31ec217 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 29 Mar 2014 09:16:43 +0900 Subject: [PATCH] fix common_type: support C++14 version --- sprout/array/array.hpp | 11 +-- sprout/type_traits.hpp | 2 + sprout/type_traits/common_decay.hpp | 4 +- sprout/type_traits/common_type.hpp | 71 +++++++++++++++++++ sprout/type_traits/has_type.hpp | 26 +++++++ sprout/type_traits/inherit_if_type.hpp | 21 ++++++ sprout/type_traits/is_c_str.hpp | 5 ++ sprout/type_traits/is_char_type.hpp | 5 ++ sprout/type_traits/is_const_unqualified.hpp | 5 ++ .../type_traits/is_convert_constructible.hpp | 5 ++ sprout/type_traits/is_cv_unqualified.hpp | 5 ++ sprout/type_traits/is_sint.hpp | 5 ++ sprout/type_traits/is_uint.hpp | 5 ++ .../type_traits/is_volatile_unqualified.hpp | 5 ++ sprout/type_traits/std_type_aliases.hpp | 4 +- sprout/type_traits/std_type_traits.hpp | 4 +- sprout/utility/pack.hpp | 18 +++++ 17 files changed, 191 insertions(+), 10 deletions(-) create mode 100644 sprout/type_traits/common_type.hpp create mode 100644 sprout/type_traits/has_type.hpp create mode 100644 sprout/type_traits/inherit_if_type.hpp diff --git a/sprout/array/array.hpp b/sprout/array/array.hpp index 6aefaa89..8d7ecd99 100644 --- a/sprout/array/array.hpp +++ b/sprout/array/array.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -232,17 +233,17 @@ namespace sprout { namespace detail { template - inline SPROUT_CONSTEXPR sprout::array - to_array_impl(T const (& arr)[N], sprout::index_tuple) { - return sprout::array{{arr[Indexes]...}}; + inline SPROUT_CONSTEXPR sprout::array::type, N> + to_array_impl(T (& arr)[N], sprout::index_tuple) { + return sprout::array::type, N>{{arr[Indexes]...}}; } } // namespace detail // // to_array // template - inline SPROUT_CONSTEXPR sprout::array - to_array(T const (& arr)[N]) { + inline SPROUT_CONSTEXPR sprout::array::type, N> + to_array(T (& arr)[N]) { return sprout::detail::to_array_impl(arr, sprout::make_index_tuple::make()); } } // namespace sprout diff --git a/sprout/type_traits.hpp b/sprout/type_traits.hpp index e472419b..c512a0fa 100644 --- a/sprout/type_traits.hpp +++ b/sprout/type_traits.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/sprout/type_traits/common_decay.hpp b/sprout/type_traits/common_decay.hpp index 4d3b120e..758141c2 100644 --- a/sprout/type_traits/common_decay.hpp +++ b/sprout/type_traits/common_decay.hpp @@ -8,8 +8,8 @@ #ifndef SPROUT_TYPE_TRAITS_COMMON_DECAY_HPP #define SPROUT_TYPE_TRAITS_COMMON_DECAY_HPP -#include #include +#include namespace sprout { // @@ -17,7 +17,7 @@ namespace sprout { // template struct common_decay - : public std::decay::type> + : public sprout::common_type {}; #if SPROUT_USE_TEMPLATE_ALIASES diff --git a/sprout/type_traits/common_type.hpp b/sprout/type_traits/common_type.hpp new file mode 100644 index 00000000..7ed58b46 --- /dev/null +++ b/sprout/type_traits/common_type.hpp @@ -0,0 +1,71 @@ +/*============================================================================= + 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_COMMON_TYPE_HPP +#define SPROUT_TYPE_TRAITS_COMMON_TYPE_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + // + // undecayed_common_type + // + namespace detail { + template + struct undecayed_common_type2 + : public sprout::identity() ? std::declval() : std::declval())> + {}; + template + struct undecayed_common_type_impl {}; + template + struct undecayed_common_type_impl + : public sprout::identity + {}; + template + struct undecayed_common_type_impl::type>::type, T1, T2, Tail...> + : public sprout::detail::undecayed_common_type_impl::type, Tail...> + {}; + } // namespace detail + template + struct undecayed_common_type + : public sprout::detail::undecayed_common_type_impl + {}; + + // + // common_type + // + namespace detail { + template::value> + struct common_type_impl; + template + struct common_type_impl + : public CommonType + {}; + template + struct common_type_impl + : public std::decay + {}; + } // namespace detail + template + struct common_type + : public sprout::detail::common_type_impl > + {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using undecayed_common_type_t = typename sprout::undecayed_common_type::type; + + template + using common_type_t = typename sprout::common_type::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_TRAITS_COMMON_TYPE_HPP diff --git a/sprout/type_traits/has_type.hpp b/sprout/type_traits/has_type.hpp new file mode 100644 index 00000000..2781ba5d --- /dev/null +++ b/sprout/type_traits/has_type.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_TYPE_HPP +#define SPROUT_TYPE_TRAITS_HAS_TYPE_HPP + +#include +#include + +namespace sprout { + // + // has_type + // + SPROUT_HAS_XXX_TYPE_DEF_LAZY(type); + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool has_type_v = sprout::has_type::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_TRAITS_HAS_TYPE_HPP diff --git a/sprout/type_traits/inherit_if_type.hpp b/sprout/type_traits/inherit_if_type.hpp new file mode 100644 index 00000000..adf2a916 --- /dev/null +++ b/sprout/type_traits/inherit_if_type.hpp @@ -0,0 +1,21 @@ +/*============================================================================= + 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_INHERIT_IF_TYPE_HPP +#define SPROUT_TYPE_TRAITS_INHERIT_IF_TYPE_HPP + +#include +#include + +namespace sprout { + // + // inherit_if_type + // + SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(type); +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_TRAITS_INHERIT_IF_TYPE_HPP diff --git a/sprout/type_traits/is_c_str.hpp b/sprout/type_traits/is_c_str.hpp index 0ceff4d9..320ed842 100644 --- a/sprout/type_traits/is_c_str.hpp +++ b/sprout/type_traits/is_c_str.hpp @@ -48,6 +48,11 @@ namespace sprout { struct is_c_str : public sprout::true_type {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_c_str_v = sprout::is_c_str::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace sprout #endif // #ifndef SPROUT_TYPE_TRAITS_IS_C_STR_HPP diff --git a/sprout/type_traits/is_char_type.hpp b/sprout/type_traits/is_char_type.hpp index fa32f5d6..b5870e5e 100644 --- a/sprout/type_traits/is_char_type.hpp +++ b/sprout/type_traits/is_char_type.hpp @@ -47,6 +47,11 @@ namespace sprout { struct is_char_type : public sprout::true_type {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_char_type_v = sprout::is_char_type::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace sprout #endif // #ifndef SPROUT_TYPE_TRAITS_IS_CHAR_TYPE_HPP diff --git a/sprout/type_traits/is_const_unqualified.hpp b/sprout/type_traits/is_const_unqualified.hpp index 3d3a6a40..108e7cc0 100644 --- a/sprout/type_traits/is_const_unqualified.hpp +++ b/sprout/type_traits/is_const_unqualified.hpp @@ -23,6 +23,11 @@ namespace sprout { std::is_const::value > {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_const_unqualified_v = sprout::is_const_unqualified::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace sprout #endif // #ifndef SPROUT_TYPE_TRAITS_IS_CONST_UNQUALIFIED_HPP diff --git a/sprout/type_traits/is_convert_constructible.hpp b/sprout/type_traits/is_convert_constructible.hpp index 22dbfd43..ffa192e9 100644 --- a/sprout/type_traits/is_convert_constructible.hpp +++ b/sprout/type_traits/is_convert_constructible.hpp @@ -30,6 +30,11 @@ namespace sprout { struct is_convert_constructible : public sprout::identity::test(std::declval()))>::type {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_convert_constructible_v = sprout::is_convert_constructible::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace sprout #endif // #ifndef SPROUT_TYPE_TRAITS_IS_CONVERT_CONSTRUCTIBLE_HPP diff --git a/sprout/type_traits/is_cv_unqualified.hpp b/sprout/type_traits/is_cv_unqualified.hpp index eee92d7c..0f8b40df 100644 --- a/sprout/type_traits/is_cv_unqualified.hpp +++ b/sprout/type_traits/is_cv_unqualified.hpp @@ -24,6 +24,11 @@ namespace sprout { sprout::is_const_unqualified::value && sprout::is_volatile_unqualified::value > {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_cv_unqualified_v = sprout::is_cv_unqualified::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace sprout #endif // #ifndef SPROUT_TYPE_TRAITS_IS_CV_UNQUALIFIED_HPP diff --git a/sprout/type_traits/is_sint.hpp b/sprout/type_traits/is_sint.hpp index 3bdb2ed8..6fce899a 100644 --- a/sprout/type_traits/is_sint.hpp +++ b/sprout/type_traits/is_sint.hpp @@ -23,6 +23,11 @@ namespace sprout { std::is_integral::value && std::is_signed::value > {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_sint_v = sprout::is_sint::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace sprout #endif // #ifndef SPROUT_TYPE_TRAITS_IS_SINT_HPP diff --git a/sprout/type_traits/is_uint.hpp b/sprout/type_traits/is_uint.hpp index 5f2204d0..d846891e 100644 --- a/sprout/type_traits/is_uint.hpp +++ b/sprout/type_traits/is_uint.hpp @@ -23,6 +23,11 @@ namespace sprout { std::is_integral::value && std::is_unsigned::value > {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_uint_v = sprout::is_uint::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace sprout #endif // #ifndef SPROUT_TYPE_TRAITS_IS_UINT_HPP diff --git a/sprout/type_traits/is_volatile_unqualified.hpp b/sprout/type_traits/is_volatile_unqualified.hpp index 64f31fd1..c8288acc 100644 --- a/sprout/type_traits/is_volatile_unqualified.hpp +++ b/sprout/type_traits/is_volatile_unqualified.hpp @@ -23,6 +23,11 @@ namespace sprout { std::is_volatile::value > {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_volatile_unqualified_v = sprout::is_volatile_unqualified::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace sprout #endif // #ifndef SPROUT_TYPE_TRAITS_IS_VOLATILE_UNQUALIFIED_HPP diff --git a/sprout/type_traits/std_type_aliases.hpp b/sprout/type_traits/std_type_aliases.hpp index 1d617de7..a880e274 100644 --- a/sprout/type_traits/std_type_aliases.hpp +++ b/sprout/type_traits/std_type_aliases.hpp @@ -78,8 +78,8 @@ namespace sprout { using enable_if_t = typename sprout::enable_if::type; template using conditional_t = typename sprout::conditional::type; - template - using common_type_t = typename sprout::common_type::type; +// template +// using common_type_t = typename sprout::common_type::type; template using underlying_type_t = typename sprout::underlying_type::type; template diff --git a/sprout/type_traits/std_type_traits.hpp b/sprout/type_traits/std_type_traits.hpp index 417b1b70..6158d479 100644 --- a/sprout/type_traits/std_type_traits.hpp +++ b/sprout/type_traits/std_type_traits.hpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #if !defined(_LIBCPP_VERSION) || (_LIBCPP_VERSION < 1101) # include @@ -471,7 +473,7 @@ namespace sprout { using std::decay; using std::enable_if; using std::conditional; - using std::common_type; +// using std::common_type; using std::underlying_type; using std::result_of; } // namespace sprout diff --git a/sprout/utility/pack.hpp b/sprout/utility/pack.hpp index f53a2ffe..925a169b 100644 --- a/sprout/utility/pack.hpp +++ b/sprout/utility/pack.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace sprout { @@ -54,6 +55,23 @@ namespace sprout { typename sprout::types::detail::tuple_take >::type >::eval(SPROUT_FORWARD(Args, args)...); } + + // + // head_element + // + template + struct head_element + : public sprout::identity + {}; + + // + // head_get + // + template + inline SPROUT_CONSTEXPR Head&& + head_get(Head&& head, Tail&&... tail) { + return SPROUT_FORWARD(Head, head); + } } // namespace sprout #endif // #ifndef SPROUT_UTILITY_PACK_HPP