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