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/integral_constant.h>
14 #include <__type_traits/is_constructible.h>
15 #include <__type_traits/is_reference.h>
16 #include <__utility/declval.h>
17 #include <cstddef>
18 
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 #  pragma GCC system_header
21 #endif
22 
23 _LIBCPP_BEGIN_NAMESPACE_STD
24 
25 // GCC is disabled due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106611
26 #if __has_builtin(__is_nothrow_constructible) && !defined(_LIBCPP_COMPILER_GCC)
27 
28 template < class _Tp, class... _Args>
29 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
30     : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
31 #else
32 
33 template <bool, bool, class _Tp, class... _Args>
34 struct __libcpp_is_nothrow_constructible;
35 
36 template <class _Tp, class... _Args>
37 struct __libcpp_is_nothrow_constructible</*is constructible*/ true, /*is reference*/ false, _Tp, _Args...>
38     : public integral_constant<bool, noexcept(_Tp(std::declval<_Args>()...))> {};
39 
40 template <class _Tp>
41 void __implicit_conversion_to(_Tp) noexcept {}
42 
43 template <class _Tp, class _Arg>
44 struct __libcpp_is_nothrow_constructible</*is constructible*/ true, /*is reference*/ true, _Tp, _Arg>
45     : public integral_constant<bool, noexcept(std::__implicit_conversion_to<_Tp>(std::declval<_Arg>()))> {};
46 
47 template <class _Tp, bool _IsReference, class... _Args>
48 struct __libcpp_is_nothrow_constructible</*is constructible*/ false, _IsReference, _Tp, _Args...> : public false_type {
49 };
50 
51 template <class _Tp, class... _Args>
52 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
53     : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value,
54                                         is_reference<_Tp>::value,
55                                         _Tp,
56                                         _Args...> {};
57 
58 template <class _Tp, size_t _Ns>
59 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]>
60     : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp> {};
61 
62 #endif // __has_builtin(__is_nothrow_constructible)
63 
64 #if _LIBCPP_STD_VER >= 17
65 template <class _Tp, class... _Args>
66 inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<_Tp, _Args...>::value;
67 #endif
68 
69 _LIBCPP_END_NAMESPACE_STD
70 
71 #endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONSTRUCTIBLE_H
72