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#if __has_builtin(__is_nothrow_constructible)
26
27template <
28    class _Tp, class... _Args>
29struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
30    : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
31#else
32
33template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible;
34
35template <class _Tp, class... _Args>
36struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/false, _Tp, _Args...>
37    : public integral_constant<bool, noexcept(_Tp(std::declval<_Args>()...))>
38{
39};
40
41template <class _Tp>
42void __implicit_conversion_to(_Tp) noexcept { }
43
44template <class _Tp, class _Arg>
45struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/true, _Tp, _Arg>
46    : public integral_constant<bool, noexcept(_VSTD::__implicit_conversion_to<_Tp>(std::declval<_Arg>()))>
47{
48};
49
50template <class _Tp, bool _IsReference, class... _Args>
51struct __libcpp_is_nothrow_constructible</*is constructible*/false, _IsReference, _Tp, _Args...>
52    : public false_type
53{
54};
55
56template <class _Tp, class... _Args>
57struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
58    : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, is_reference<_Tp>::value, _Tp, _Args...>
59{
60};
61
62template <class _Tp, size_t _Ns>
63struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]>
64    : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp>
65{
66};
67
68#endif // __has_builtin(__is_nothrow_constructible)
69
70
71#if _LIBCPP_STD_VER > 14
72template <class _Tp, class ..._Args>
73inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<_Tp, _Args...>::value;
74#endif
75
76_LIBCPP_END_NAMESPACE_STD
77
78#endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONSTRUCTIBLE_H
79