mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
fix common_type: support C++14 version
This commit is contained in:
parent
bb0098ce09
commit
1bb9336d34
17 changed files with 191 additions and 10 deletions
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple/metafunction.hpp>
|
||||
|
@ -232,17 +233,17 @@ namespace sprout {
|
|||
|
||||
namespace detail {
|
||||
template<typename T, std::size_t N, sprout::index_t... Indexes>
|
||||
inline SPROUT_CONSTEXPR sprout::array<T, N>
|
||||
to_array_impl(T const (& arr)[N], sprout::index_tuple<Indexes...>) {
|
||||
return sprout::array<T, N>{{arr[Indexes]...}};
|
||||
inline SPROUT_CONSTEXPR sprout::array<typename std::remove_cv<T>::type, N>
|
||||
to_array_impl(T (& arr)[N], sprout::index_tuple<Indexes...>) {
|
||||
return sprout::array<typename std::remove_cv<T>::type, N>{{arr[Indexes]...}};
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// to_array
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::array<T, N>
|
||||
to_array(T const (& arr)[N]) {
|
||||
inline SPROUT_CONSTEXPR sprout::array<typename std::remove_cv<T>::type, N>
|
||||
to_array(T (& arr)[N]) {
|
||||
return sprout::detail::to_array_impl(arr, sprout::make_index_tuple<N>::make());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <sprout/type_traits/is_uint.hpp>
|
||||
#include <sprout/type_traits/is_char_type.hpp>
|
||||
#include <sprout/type_traits/is_c_str.hpp>
|
||||
#include <sprout/type_traits/has_type.hpp>
|
||||
#include <sprout/type_traits/identity.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/type_traits/const_reference.hpp>
|
||||
|
@ -29,6 +30,7 @@
|
|||
#include <sprout/type_traits/common_decay.hpp>
|
||||
#include <sprout/type_traits/arithmetic_promote.hpp>
|
||||
#include <sprout/type_traits/float_promote.hpp>
|
||||
#include <sprout/type_traits/inherit_if_type.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/type_traits/has_xxx.hpp>
|
||||
#include <sprout/type_traits/inherit_if_xxx.hpp>
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
#ifndef SPROUT_TYPE_TRAITS_COMMON_DECAY_HPP
|
||||
#define SPROUT_TYPE_TRAITS_COMMON_DECAY_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/common_type.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -17,7 +17,7 @@ namespace sprout {
|
|||
//
|
||||
template<typename... Types>
|
||||
struct common_decay
|
||||
: public std::decay<typename std::common_type<Types...>::type>
|
||||
: public sprout::common_type<Types...>
|
||||
{};
|
||||
|
||||
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||
|
|
71
sprout/type_traits/common_type.hpp
Normal file
71
sprout/type_traits/common_type.hpp
Normal file
|
@ -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 <utility>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/identity.hpp>
|
||||
#include <sprout/type_traits/has_type.hpp>
|
||||
#include <sprout/utility/pack.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// undecayed_common_type
|
||||
//
|
||||
namespace detail {
|
||||
template<typename T1, typename T2>
|
||||
struct undecayed_common_type2
|
||||
: public sprout::identity<decltype(std::declval<bool>() ? std::declval<T1>() : std::declval<T2>())>
|
||||
{};
|
||||
template<typename Void, typename... Types>
|
||||
struct undecayed_common_type_impl {};
|
||||
template<typename T>
|
||||
struct undecayed_common_type_impl<void, T>
|
||||
: public sprout::identity<T>
|
||||
{};
|
||||
template<typename T1, typename T2, typename... Tail>
|
||||
struct undecayed_common_type_impl<typename sprout::head_element<void, typename sprout::detail::undecayed_common_type2<T1, T2>::type>::type, T1, T2, Tail...>
|
||||
: public sprout::detail::undecayed_common_type_impl<void, typename sprout::detail::undecayed_common_type2<T1, T2>::type, Tail...>
|
||||
{};
|
||||
} // namespace detail
|
||||
template <typename... Types>
|
||||
struct undecayed_common_type
|
||||
: public sprout::detail::undecayed_common_type_impl<void, Types...>
|
||||
{};
|
||||
|
||||
//
|
||||
// common_type
|
||||
//
|
||||
namespace detail {
|
||||
template<typename CommonType, bool = sprout::has_type<CommonType>::value>
|
||||
struct common_type_impl;
|
||||
template<typename CommonType>
|
||||
struct common_type_impl<CommonType, false>
|
||||
: public CommonType
|
||||
{};
|
||||
template<typename CommonType>
|
||||
struct common_type_impl<CommonType, true>
|
||||
: public std::decay<typename CommonType::type>
|
||||
{};
|
||||
} // namespace detail
|
||||
template <typename... Types>
|
||||
struct common_type
|
||||
: public sprout::detail::common_type_impl<sprout::undecayed_common_type<Types...> >
|
||||
{};
|
||||
|
||||
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||
template<typename... Types>
|
||||
using undecayed_common_type_t = typename sprout::undecayed_common_type<Types...>::type;
|
||||
|
||||
template<typename... Types>
|
||||
using common_type_t = typename sprout::common_type<Types...>::type;
|
||||
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_COMMON_TYPE_HPP
|
26
sprout/type_traits/has_type.hpp
Normal file
26
sprout/type_traits/has_type.hpp
Normal file
|
@ -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 <sprout/config.hpp>
|
||||
#include <sprout/type_traits/has_xxx.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// has_type
|
||||
//
|
||||
SPROUT_HAS_XXX_TYPE_DEF_LAZY(type);
|
||||
|
||||
#if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool has_type_v = sprout::has_type<T>::value;
|
||||
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_HAS_TYPE_HPP
|
21
sprout/type_traits/inherit_if_type.hpp
Normal file
21
sprout/type_traits/inherit_if_type.hpp
Normal file
|
@ -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 <sprout/config.hpp>
|
||||
#include <sprout/type_traits/inherit_if_xxx.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// inherit_if_type
|
||||
//
|
||||
SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(type);
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_INHERIT_IF_TYPE_HPP
|
|
@ -48,6 +48,11 @@ namespace sprout {
|
|||
struct is_c_str<char32_t[N]>
|
||||
: public sprout::true_type
|
||||
{};
|
||||
|
||||
#if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_c_str_v = sprout::is_c_str<T>::value;
|
||||
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_C_STR_HPP
|
||||
|
|
|
@ -47,6 +47,11 @@ namespace sprout {
|
|||
struct is_char_type<char32_t>
|
||||
: public sprout::true_type
|
||||
{};
|
||||
|
||||
#if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_char_type_v = sprout::is_char_type<T>::value;
|
||||
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_CHAR_TYPE_HPP
|
||||
|
|
|
@ -23,6 +23,11 @@ namespace sprout {
|
|||
std::is_const<T>::value
|
||||
>
|
||||
{};
|
||||
|
||||
#if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_const_unqualified_v = sprout::is_const_unqualified<T>::value;
|
||||
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_CONST_UNQUALIFIED_HPP
|
||||
|
|
|
@ -30,6 +30,11 @@ namespace sprout {
|
|||
struct is_convert_constructible
|
||||
: public sprout::identity<decltype(sprout::detail::is_convert_constructible_test<T>::test(std::declval<Arg>()))>::type
|
||||
{};
|
||||
|
||||
#if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_convert_constructible_v = sprout::is_convert_constructible<T>::value;
|
||||
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_CONVERT_CONSTRUCTIBLE_HPP
|
||||
|
|
|
@ -24,6 +24,11 @@ namespace sprout {
|
|||
sprout::is_const_unqualified<T>::value && sprout::is_volatile_unqualified<T>::value
|
||||
>
|
||||
{};
|
||||
|
||||
#if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_cv_unqualified_v = sprout::is_cv_unqualified<T>::value;
|
||||
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_CV_UNQUALIFIED_HPP
|
||||
|
|
|
@ -23,6 +23,11 @@ namespace sprout {
|
|||
std::is_integral<T>::value && std::is_signed<T>::value
|
||||
>
|
||||
{};
|
||||
|
||||
#if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_sint_v = sprout::is_sint<T>::value;
|
||||
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_SINT_HPP
|
||||
|
|
|
@ -23,6 +23,11 @@ namespace sprout {
|
|||
std::is_integral<T>::value && std::is_unsigned<T>::value
|
||||
>
|
||||
{};
|
||||
|
||||
#if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_uint_v = sprout::is_uint<T>::value;
|
||||
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_UINT_HPP
|
||||
|
|
|
@ -23,6 +23,11 @@ namespace sprout {
|
|||
std::is_volatile<T>::value
|
||||
>
|
||||
{};
|
||||
|
||||
#if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_volatile_unqualified_v = sprout::is_volatile_unqualified<T>::value;
|
||||
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_VOLATILE_UNQUALIFIED_HPP
|
||||
|
|
|
@ -78,8 +78,8 @@ namespace sprout {
|
|||
using enable_if_t = typename sprout::enable_if<B, T>::type;
|
||||
template<bool B, typename T, typename F>
|
||||
using conditional_t = typename sprout::conditional<B, T, F>::type;
|
||||
template<typename... Types>
|
||||
using common_type_t = typename sprout::common_type<Types...>::type;
|
||||
// template<typename... Types>
|
||||
// using common_type_t = typename sprout::common_type<Types...>::type;
|
||||
template<typename T>
|
||||
using underlying_type_t = typename sprout::underlying_type<T>::type;
|
||||
template<typename F, typename... ArgTypes>
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/detail/predef.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/common_type.hpp>
|
||||
#include <sprout/type_traits/detail/type_traits_wrapper.hpp>
|
||||
#if !defined(_LIBCPP_VERSION) || (_LIBCPP_VERSION < 1101)
|
||||
# include <sprout/tpp/algorithm/max_element.hpp>
|
||||
|
@ -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
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/type/type_tuple.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/identity.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
|
@ -54,6 +55,23 @@ namespace sprout {
|
|||
typename sprout::types::detail::tuple_take<I, sprout::types::type_tuple<Args...> >::type
|
||||
>::eval(SPROUT_FORWARD(Args, args)...);
|
||||
}
|
||||
|
||||
//
|
||||
// head_element
|
||||
//
|
||||
template<typename Head, typename... Tail>
|
||||
struct head_element
|
||||
: public sprout::identity<Head>
|
||||
{};
|
||||
|
||||
//
|
||||
// head_get
|
||||
//
|
||||
template<typename Head, typename... Tail>
|
||||
inline SPROUT_CONSTEXPR Head&&
|
||||
head_get(Head&& head, Tail&&... tail) {
|
||||
return SPROUT_FORWARD(Head, head);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_PACK_HPP
|
||||
|
|
Loading…
Reference in a new issue