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_DESTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_DESTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_destructible.h>
15#include <__type_traits/is_reference.h>
16#include <__type_traits/is_scalar.h>
17#include <__type_traits/remove_all_extents.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#if !defined(_LIBCPP_CXX03_LANG)
28
29template <bool, class _Tp> struct __libcpp_is_nothrow_destructible;
30
31template <class _Tp>
32struct __libcpp_is_nothrow_destructible<false, _Tp>
33    : public false_type
34{
35};
36
37template <class _Tp>
38struct __libcpp_is_nothrow_destructible<true, _Tp>
39    : public integral_constant<bool, noexcept(std::declval<_Tp>().~_Tp()) >
40{
41};
42
43template <class _Tp>
44struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
45    : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
46{
47};
48
49template <class _Tp, size_t _Ns>
50struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[_Ns]>
51    : public is_nothrow_destructible<_Tp>
52{
53};
54
55template <class _Tp>
56struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&>
57    : public true_type
58{
59};
60
61template <class _Tp>
62struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&>
63    : public true_type
64{
65};
66
67#else
68
69template <class _Tp> struct __libcpp_nothrow_destructor
70    : public integral_constant<bool, is_scalar<_Tp>::value ||
71                                     is_reference<_Tp>::value> {};
72
73template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
74    : public __libcpp_nothrow_destructor<__remove_all_extents_t<_Tp> > {};
75
76template <class _Tp>
77struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[]>
78    : public false_type {};
79
80#endif
81
82#if _LIBCPP_STD_VER > 14
83template <class _Tp>
84inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<_Tp>::value;
85#endif
86
87_LIBCPP_END_NAMESPACE_STD
88
89#endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_DESTRUCTIBLE_H
90