aboutsummaryrefslogtreecommitdiffstats
path: root/include/type_traits
diff options
context:
space:
mode:
Diffstat (limited to 'include/type_traits')
-rw-r--r--include/type_traits176
1 files changed, 91 insertions, 85 deletions
diff --git a/include/type_traits b/include/type_traits
index 5ccafec01f0b..77b57a41e418 100644
--- a/include/type_traits
+++ b/include/type_traits
@@ -509,8 +509,8 @@ struct _Lazy : _Func<_Args...> {};
// Member detector base
-template <template <class...> class _Templ, class ..._Args>
-true_type __sfinae_test_impl(_FirstType<int, _Templ<_Args...> >);
+template <template <class...> class _Templ, class ..._Args, class = _Templ<_Args...> >
+true_type __sfinae_test_impl(int);
template <template <class...> class, class ...>
false_type __sfinae_test_impl(...);
@@ -886,28 +886,15 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_class_v
// is_function
-namespace __libcpp_is_function_imp
-{
-struct __dummy_type {};
-template <class _Tp> char __test(_Tp*);
-template <class _Tp> char __test(__dummy_type);
-template <class _Tp> __two __test(...);
-template <class _Tp> _Tp& __source(int);
-template <class _Tp> __dummy_type __source(...);
-}
-
-template <class _Tp, bool = is_class<_Tp>::value ||
- is_union<_Tp>::value ||
- is_void<_Tp>::value ||
- is_reference<_Tp>::value ||
- __is_nullptr_t<_Tp>::value >
-struct __libcpp_is_function
- : public integral_constant<bool, sizeof(__libcpp_is_function_imp::__test<_Tp>(__libcpp_is_function_imp::__source<_Tp>(0))) == 1>
- {};
-template <class _Tp> struct __libcpp_is_function<_Tp, true> : public false_type {};
-
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_function
- : public __libcpp_is_function<_Tp> {};
+ : public _BoolConstant<
+#ifdef __clang__
+ __is_function(_Tp)
+#else
+ !(is_reference<_Tp>::value || is_const<const _Tp>::value)
+#endif
+ > {};
+
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
@@ -915,27 +902,24 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_function_v
= is_function<_Tp>::value;
#endif
-// is_member_function_pointer
-
-// template <class _Tp> struct __libcpp_is_member_function_pointer : public false_type {};
-// template <class _Tp, class _Up> struct __libcpp_is_member_function_pointer<_Tp _Up::*> : public is_function<_Tp> {};
-//
-
-template <class _MP, bool _IsMemberFunctionPtr, bool _IsMemberObjectPtr>
-struct __member_pointer_traits_imp
-{ // forward declaration; specializations later
+template <class _Tp> struct __libcpp_is_member_pointer {
+ enum {
+ __is_member = false,
+ __is_func = false,
+ __is_obj = false
+ };
+};
+template <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> {
+ enum {
+ __is_member = true,
+ __is_func = is_function<_Tp>::value,
+ __is_obj = !__is_func,
+ };
};
-template <class _Tp> struct __libcpp_is_member_function_pointer
- : public false_type {};
-
-template <class _Ret, class _Class>
-struct __libcpp_is_member_function_pointer<_Ret _Class::*>
- : public is_function<_Ret> {};
-
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
- : public __libcpp_is_member_function_pointer<typename remove_cv<_Tp>::type>::type {};
+ : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_func > {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
@@ -945,11 +929,8 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_function_pointer_v
// is_member_pointer
-template <class _Tp> struct __libcpp_is_member_pointer : public false_type {};
-template <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> : public true_type {};
-
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_pointer
- : public __libcpp_is_member_pointer<typename remove_cv<_Tp>::type> {};
+ : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_member > {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
@@ -960,8 +941,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_pointer_v
// is_member_object_pointer
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
- : public integral_constant<bool, is_member_pointer<_Tp>::value &&
- !is_member_function_pointer<_Tp>::value> {};
+ : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_obj > {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
@@ -1080,16 +1060,9 @@ struct __is_referenceable : integral_constant<bool,
// add_const
-template <class _Tp, bool = is_reference<_Tp>::value ||
- is_function<_Tp>::value ||
- is_const<_Tp>::value >
-struct __add_const {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
-
-template <class _Tp>
-struct __add_const<_Tp, false> {typedef _LIBCPP_NODEBUG_TYPE const _Tp type;};
-
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_const
- {typedef _LIBCPP_NODEBUG_TYPE typename __add_const<_Tp>::type type;};
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_const {
+ typedef _LIBCPP_NODEBUG_TYPE const _Tp type;
+};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using add_const_t = typename add_const<_Tp>::type;
@@ -1097,25 +1070,18 @@ template <class _Tp> using add_const_t = typename add_const<_Tp>::type;
// add_volatile
-template <class _Tp, bool = is_reference<_Tp>::value ||
- is_function<_Tp>::value ||
- is_volatile<_Tp>::value >
-struct __add_volatile {typedef _Tp type;};
-
-template <class _Tp>
-struct __add_volatile<_Tp, false> {typedef volatile _Tp type;};
-
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_volatile
- {typedef _LIBCPP_NODEBUG_TYPE typename __add_volatile<_Tp>::type type;};
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_volatile {
+ typedef _LIBCPP_NODEBUG_TYPE volatile _Tp type;
+};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type;
#endif
// add_cv
-
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_cv
- {typedef _LIBCPP_NODEBUG_TYPE typename add_const<typename add_volatile<_Tp>::type>::type type;};
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_cv {
+ typedef _LIBCPP_NODEBUG_TYPE const volatile _Tp type;
+};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type;
@@ -1153,8 +1119,12 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_rvalue_reference
template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
#endif
+// Suppress deprecation notice for volatile-qualified return type resulting
+// from volatile-qualified types _Tp.
+_LIBCPP_SUPPRESS_DEPRECATED_PUSH
template <class _Tp> _Tp&& __declval(int);
template <class _Tp> _Tp __declval(long);
+_LIBCPP_SUPPRESS_DEPRECATED_POP
template <class _Tp>
decltype(_VSTD::__declval<_Tp>(0))
@@ -2307,6 +2277,11 @@ __decay_copy(_Tp&& __t)
return _VSTD::forward<_Tp>(__t);
}
+template <class _MP, bool _IsMemberFunctionPtr, bool _IsMemberObjectPtr>
+struct __member_pointer_traits_imp
+{
+};
+
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false>
{
@@ -2836,6 +2811,30 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_default_constructible_v
= is_default_constructible<_Tp>::value;
#endif
+#ifndef _LIBCPP_CXX03_LANG
+// First of all, we can't implement this check in C++03 mode because the {}
+// default initialization syntax isn't valid.
+// Second, we implement the trait in a funny manner with two defaulted template
+// arguments to workaround Clang's PR43454.
+template <class _Tp>
+void __test_implicit_default_constructible(_Tp);
+
+template <class _Tp, class = void, bool = is_default_constructible<_Tp>::value>
+struct __is_implicitly_default_constructible
+ : false_type
+{ };
+
+template <class _Tp>
+struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), true>
+ : true_type
+{ };
+
+template <class _Tp>
+struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), false>
+ : false_type
+{ };
+#endif // !C++03
+
// is_copy_constructible
template <class _Tp>
@@ -3681,6 +3680,13 @@ _LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_r_v
template <class _Tp> struct __is_swappable;
template <class _Tp> struct __is_nothrow_swappable;
+// swap, swap_ranges
+
+template <class _ForwardIterator1, class _ForwardIterator2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_ForwardIterator2
+swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2);
+
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
#ifndef _LIBCPP_CXX03_LANG
@@ -3706,7 +3712,22 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
typename enable_if<
__is_swappable<_Tp>::value
>::type
-swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value);
+swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
+{
+ _VSTD::swap_ranges(__a, __a + _Np, __b);
+}
+
+template <class _ForwardIterator1, class _ForwardIterator2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_ForwardIterator2
+swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
+{
+ for(; __first1 != __last1; ++__first1, (void) ++__first2)
+ swap(*__first1, *__first2);
+ return __first2;
+}
+
+// iter_swap
template <class _ForwardIterator1, class _ForwardIterator2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
@@ -3985,21 +4006,6 @@ struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy>
#endif
-#if _LIBCPP_STD_VER > 17
-enum class endian
-{
- little = 0xDEAD,
- big = 0xFACE,
-#if defined(_LIBCPP_LITTLE_ENDIAN)
- native = little
-#elif defined(_LIBCPP_BIG_ENDIAN)
- native = big
-#else
- native = 0xCAFE
-#endif
-};
-#endif
-
#ifndef _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
#if _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY