summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/std/type_traits290
1 files changed, 60 insertions, 230 deletions
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index aac7cff6cf6..390b6f40af5 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -924,213 +924,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: public __is_default_constructible_safe<_Tp>::type
{ };
-
- // Implementation of is_constructible.
-
- // The hardest part of this trait is the binary direct-initialization
- // case, because we hit into a functional cast of the form T(arg).
- // This implementation uses different strategies depending on the
- // target type to reduce the test overhead as much as possible:
- //
- // a) For a reference target type, we use a static_cast expression
- // modulo its extra cases.
- //
- // b) For a non-reference target type we use a ::new expression.
- struct __do_is_static_castable_impl
- {
- template<typename _From, typename _To, typename
- = decltype(static_cast<_To>(declval<_From>()))>
- static true_type __test(int);
-
- template<typename, typename>
- static false_type __test(...);
- };
-
- template<typename _From, typename _To>
- struct __is_static_castable_impl
- : public __do_is_static_castable_impl
- {
- typedef decltype(__test<_From, _To>(0)) type;
- };
-
- template<typename _From, typename _To>
- struct __is_static_castable_safe
- : public __is_static_castable_impl<_From, _To>::type
- { };
-
- // __is_static_castable
- template<typename _From, typename _To>
- struct __is_static_castable
- : public integral_constant<bool, (__is_static_castable_safe<
- _From, _To>::value)>
- { };
-
- // Implementation for non-reference types. To meet the proper
- // variable definition semantics, we also need to test for
- // is_destructible in this case.
- // This form should be simplified by a single expression:
- // ::delete ::new _Tp(declval<_Arg>()), see c++/51222.
- struct __do_is_direct_constructible_impl
- {
- template<typename _Tp, typename _Arg, typename
- = decltype(::new _Tp(declval<_Arg>()))>
- static true_type __test(int);
-
- template<typename, typename>
- static false_type __test(...);
- };
-
- template<typename _Tp, typename _Arg>
- struct __is_direct_constructible_impl
- : public __do_is_direct_constructible_impl
- {
- typedef decltype(__test<_Tp, _Arg>(0)) type;
- };
-
- template<typename _Tp, typename _Arg>
- struct __is_direct_constructible_new_safe
- : public __and_<is_destructible<_Tp>,
- __is_direct_constructible_impl<_Tp, _Arg>>
- { };
-
- template<typename, typename>
- struct is_same;
-
- template<typename, typename>
- struct is_base_of;
-
- template<typename>
- struct remove_reference;
-
- template<typename _From, typename _To, bool
- = __not_<__or_<is_void<_From>,
- is_function<_From>>>::value>
- struct __is_base_to_derived_ref;
-
- template<typename _Tp, typename... _Args>
- struct is_constructible;
-
- // Detect whether we have a downcast situation during
- // reference binding.
- template<typename _From, typename _To>
- struct __is_base_to_derived_ref<_From, _To, true>
- {
- typedef typename remove_cv<typename remove_reference<_From
- >::type>::type __src_t;
- typedef typename remove_cv<typename remove_reference<_To
- >::type>::type __dst_t;
- typedef __and_<__not_<is_same<__src_t, __dst_t>>,
- is_base_of<__src_t, __dst_t>,
- __not_<is_constructible<__dst_t, _From>>> type;
- static constexpr bool value = type::value;
- };
-
- template<typename _From, typename _To>
- struct __is_base_to_derived_ref<_From, _To, false>
- : public false_type
- { };
-
- template<typename _From, typename _To, bool
- = __and_<is_lvalue_reference<_From>,
- is_rvalue_reference<_To>>::value>
- struct __is_lvalue_to_rvalue_ref;
-
- // Detect whether we have an lvalue of non-function type
- // bound to a reference-compatible rvalue-reference.
- template<typename _From, typename _To>
- struct __is_lvalue_to_rvalue_ref<_From, _To, true>
- {
- typedef typename remove_cv<typename remove_reference<
- _From>::type>::type __src_t;
- typedef typename remove_cv<typename remove_reference<
- _To>::type>::type __dst_t;
- typedef __and_<__not_<is_function<__src_t>>,
- __or_<is_same<__src_t, __dst_t>,
- is_base_of<__dst_t, __src_t>>> type;
- static constexpr bool value = type::value;
- };
-
- template<typename _From, typename _To>
- struct __is_lvalue_to_rvalue_ref<_From, _To, false>
- : public false_type
- { };
-
- // Here we handle direct-initialization to a reference type as
- // equivalent to a static_cast modulo overshooting conversions.
- // These are restricted to the following conversions:
- // a) A base class value to a derived class reference
- // b) An lvalue to an rvalue-reference of reference-compatible
- // types that are not functions
- template<typename _Tp, typename _Arg>
- struct __is_direct_constructible_ref_cast
- : public __and_<__is_static_castable<_Arg, _Tp>,
- __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
- __is_lvalue_to_rvalue_ref<_Arg, _Tp>
- >>>
- { };
-
- template<typename _Tp, typename _Arg>
- struct __is_direct_constructible_new
- : public conditional<is_reference<_Tp>::value,
- __is_direct_constructible_ref_cast<_Tp, _Arg>,
- __is_direct_constructible_new_safe<_Tp, _Arg>
- >::type
- { };
-
- template<typename _Tp, typename _Arg>
- struct __is_direct_constructible
- : public __is_direct_constructible_new<_Tp, _Arg>::type
- { };
-
- // Since default-construction and binary direct-initialization have
- // been handled separately, the implementation of the remaining
- // n-ary construction cases is rather straightforward. We can use
- // here a functional cast, because array types are excluded anyway
- // and this form is never interpreted as a C cast.
- struct __do_is_nary_constructible_impl
- {
- template<typename _Tp, typename... _Args, typename
- = decltype(_Tp(declval<_Args>()...))>
- static true_type __test(int);
-
- template<typename, typename...>
- static false_type __test(...);
- };
-
- template<typename _Tp, typename... _Args>
- struct __is_nary_constructible_impl
- : public __do_is_nary_constructible_impl
- {
- typedef decltype(__test<_Tp, _Args...>(0)) type;
- };
-
- template<typename _Tp, typename... _Args>
- struct __is_nary_constructible
- : public __is_nary_constructible_impl<_Tp, _Args...>::type
- {
- static_assert(sizeof...(_Args) > 1,
- "Only useful for > 1 arguments");
- };
-
- template<typename _Tp, typename... _Args>
- struct __is_constructible_impl
- : public __is_nary_constructible<_Tp, _Args...>
- { };
-
- template<typename _Tp, typename _Arg>
- struct __is_constructible_impl<_Tp, _Arg>
- : public __is_direct_constructible<_Tp, _Arg>
- { };
-
- template<typename _Tp>
- struct __is_constructible_impl<_Tp>
- : public is_default_constructible<_Tp>
- { };
-
/// is_constructible
template<typename _Tp, typename... _Args>
struct is_constructible
- : public __is_constructible_impl<_Tp, _Args...>::type
+ : public __bool_constant<__is_constructible(_Tp, _Args...)>
{ };
template<typename _Tp, bool = __is_referenceable<_Tp>::value>
@@ -1255,26 +1052,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: public __is_nothrow_move_constructible_impl<_Tp>
{ };
- template<typename _Tp, typename _Up>
- class __is_assignable_helper
- {
- template<typename _Tp1, typename _Up1,
- typename = decltype(declval<_Tp1>() = declval<_Up1>())>
- static true_type
- __test(int);
-
- template<typename, typename>
- static false_type
- __test(...);
-
- public:
- typedef decltype(__test<_Tp, _Up>(0)) type;
- };
-
/// is_assignable
template<typename _Tp, typename _Up>
struct is_assignable
- : public __is_assignable_helper<_Tp, _Up>::type
+ : public __bool_constant<__is_assignable(_Tp, _Up)>
{ };
template<typename _Tp, bool = __is_referenceable<_Tp>::value>
@@ -1364,8 +1145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// is_trivially_constructible
template<typename _Tp, typename... _Args>
struct is_trivially_constructible
- : public __and_<is_constructible<_Tp, _Args...>, integral_constant<bool,
- __is_trivially_constructible(_Tp, _Args...)>>
+ : public __bool_constant<__is_trivially_constructible(_Tp, _Args...)>
{ };
/// is_trivially_default_constructible
@@ -1405,45 +1185,95 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ };
/// is_trivially_copy_constructible
+
+ template<typename _Tp, bool = __is_referenceable<_Tp>::value>
+ struct __is_trivially_copy_constructible_impl;
+
template<typename _Tp>
- struct is_trivially_copy_constructible
+ struct __is_trivially_copy_constructible_impl<_Tp, false>
+ : public false_type { };
+
+ template<typename _Tp>
+ struct __is_trivially_copy_constructible_impl<_Tp, true>
: public __and_<is_copy_constructible<_Tp>,
integral_constant<bool,
__is_trivially_constructible(_Tp, const _Tp&)>>
{ };
+ template<typename _Tp>
+ struct is_trivially_copy_constructible
+ : public __is_trivially_copy_constructible_impl<_Tp>
+ { };
+
/// is_trivially_move_constructible
+
+ template<typename _Tp, bool = __is_referenceable<_Tp>::value>
+ struct __is_trivially_move_constructible_impl;
+
template<typename _Tp>
- struct is_trivially_move_constructible
+ struct __is_trivially_move_constructible_impl<_Tp, false>
+ : public false_type { };
+
+ template<typename _Tp>
+ struct __is_trivially_move_constructible_impl<_Tp, true>
: public __and_<is_move_constructible<_Tp>,
integral_constant<bool,
__is_trivially_constructible(_Tp, _Tp&&)>>
{ };
+ template<typename _Tp>
+ struct is_trivially_move_constructible
+ : public __is_trivially_move_constructible_impl<_Tp>
+ { };
+
/// is_trivially_assignable
template<typename _Tp, typename _Up>
struct is_trivially_assignable
- : public __and_<is_assignable<_Tp, _Up>,
- integral_constant<bool,
- __is_trivially_assignable(_Tp, _Up)>>
+ : public __bool_constant<__is_trivially_assignable(_Tp, _Up)>
{ };
/// is_trivially_copy_assignable
+
+ template<typename _Tp, bool = __is_referenceable<_Tp>::value>
+ struct __is_trivially_copy_assignable_impl;
+
template<typename _Tp>
- struct is_trivially_copy_assignable
+ struct __is_trivially_copy_assignable_impl<_Tp, false>
+ : public false_type { };
+
+ template<typename _Tp>
+ struct __is_trivially_copy_assignable_impl<_Tp, true>
: public __and_<is_copy_assignable<_Tp>,
integral_constant<bool,
__is_trivially_assignable(_Tp&, const _Tp&)>>
{ };
+ template<typename _Tp>
+ struct is_trivially_copy_assignable
+ : public __is_trivially_copy_assignable_impl<_Tp>
+ { };
+
/// is_trivially_move_assignable
+
+ template<typename _Tp, bool = __is_referenceable<_Tp>::value>
+ struct __is_trivially_move_assignable_impl;
+
template<typename _Tp>
- struct is_trivially_move_assignable
+ struct __is_trivially_move_assignable_impl<_Tp, false>
+ : public false_type { };
+
+ template<typename _Tp>
+ struct __is_trivially_move_assignable_impl<_Tp, true>
: public __and_<is_move_assignable<_Tp>,
integral_constant<bool,
__is_trivially_assignable(_Tp&, _Tp&&)>>
{ };
+ template<typename _Tp>
+ struct is_trivially_move_assignable
+ : public __is_trivially_move_assignable_impl<_Tp>
+ { };
+
/// is_trivially_destructible
template<typename _Tp>
struct is_trivially_destructible