1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONSTRUCTIBLE_H 10 #define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONSTRUCTIBLE_H 11 12 #include <__config> 13 #include <__type_traits/add_lvalue_reference.h> 14 #include <__type_traits/add_rvalue_reference.h> 15 #include <__type_traits/integral_constant.h> 16 #include <__type_traits/is_constructible.h> 17 #include <__type_traits/is_reference.h> 18 #include <__utility/declval.h> 19 #include <cstddef> 20 21 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 22 # pragma GCC system_header 23 #endif 24 25 _LIBCPP_BEGIN_NAMESPACE_STD 26 27 // GCC is disabled due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106611 28 #if __has_builtin(__is_nothrow_constructible) && !defined(_LIBCPP_COMPILER_GCC) 29 30 template < class _Tp, class... _Args> 31 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible 32 : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {}; 33 #else 34 35 template <bool, bool, class _Tp, class... _Args> 36 struct __libcpp_is_nothrow_constructible; 37 38 template <class _Tp, class... _Args> 39 struct __libcpp_is_nothrow_constructible</*is constructible*/ true, /*is reference*/ false, _Tp, _Args...> 40 : public integral_constant<bool, noexcept(_Tp(std::declval<_Args>()...))> {}; 41 42 template <class _Tp> 43 void __implicit_conversion_to(_Tp) noexcept {} 44 45 template <class _Tp, class _Arg> 46 struct __libcpp_is_nothrow_constructible</*is constructible*/ true, /*is reference*/ true, _Tp, _Arg> 47 : public integral_constant<bool, noexcept(std::__implicit_conversion_to<_Tp>(std::declval<_Arg>()))> {}; 48 49 template <class _Tp, bool _IsReference, class... _Args> 50 struct __libcpp_is_nothrow_constructible</*is constructible*/ false, _IsReference, _Tp, _Args...> : public false_type { 51 }; 52 53 template <class _Tp, class... _Args> 54 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible 55 : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, 56 is_reference<_Tp>::value, 57 _Tp, 58 _Args...> {}; 59 60 template <class _Tp, size_t _Ns> 61 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]> 62 : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp> {}; 63 64 #endif // __has_builtin(__is_nothrow_constructible) 65 66 #if _LIBCPP_STD_VER >= 17 67 template <class _Tp, class... _Args> 68 inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<_Tp, _Args...>::value; 69 #endif 70 71 // TODO: remove this implementation once https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106611 is fixed 72 #ifdef _LIBCPP_COMPILER_GCC 73 74 template <class _Tp> 75 struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible 76 : public is_nothrow_constructible<_Tp, __add_lvalue_reference_t<const _Tp> > {}; 77 78 #else // _LIBCPP_COMPILER_GCC 79 80 template <class _Tp> 81 struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible 82 : public integral_constant< bool, __is_nothrow_constructible(_Tp, __add_lvalue_reference_t<const _Tp>)> {}; 83 84 #endif // _LIBCPP_COMPILER_GCC 85 86 #if _LIBCPP_STD_VER >= 17 87 template <class _Tp> 88 inline constexpr bool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<_Tp>::value; 89 #endif 90 91 // TODO: remove this implementation once https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106611 is fixed 92 #ifndef _LIBCPP_COMPILER_GCC 93 94 template <class _Tp> 95 struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible 96 : public integral_constant<bool, __is_nothrow_constructible(_Tp, __add_rvalue_reference_t<_Tp>)> {}; 97 98 #else // _LIBCPP_COMPILER_GCC 99 100 template <class _Tp> 101 struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible 102 : public is_nothrow_constructible<_Tp, __add_rvalue_reference_t<_Tp> > {}; 103 104 #endif // _LIBCPP_COMPILER_GCC 105 106 #if _LIBCPP_STD_VER >= 17 107 template <class _Tp> 108 inline constexpr bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<_Tp>::value; 109 #endif 110 111 template <class _Tp> 112 struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructible 113 : public integral_constant<bool, __is_nothrow_constructible(_Tp)> {}; 114 115 #if _LIBCPP_STD_VER >= 17 116 template <class _Tp> 117 inline constexpr bool is_nothrow_default_constructible_v = __is_nothrow_constructible(_Tp); 118 #endif 119 120 _LIBCPP_END_NAMESPACE_STD 121 122 #endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONSTRUCTIBLE_H 123