xref: /freebsd/contrib/llvm-project/libcxx/include/__type_traits/is_nothrow_convertible.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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_CONVERTIBLE_H
10 #define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONVERTIBLE_H
11 
12 #include <__config>
13 #include <__type_traits/conjunction.h>
14 #include <__type_traits/disjunction.h>
15 #include <__type_traits/integral_constant.h>
16 #include <__type_traits/is_convertible.h>
17 #include <__type_traits/is_void.h>
18 #include <__type_traits/lazy.h>
19 #include <__utility/declval.h>
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 _LIBCPP_STD_VER >= 20
28 
29 #  if __has_builtin(__is_nothrow_convertible)
30 
31 template <class _Tp, class _Up>
32 struct is_nothrow_convertible : bool_constant<__is_nothrow_convertible(_Tp, _Up)> {};
33 
34 template <class _Tp, class _Up>
35 inline constexpr bool is_nothrow_convertible_v = __is_nothrow_convertible(_Tp, _Up);
36 
37 #  else // __has_builtin(__is_nothrow_convertible)
38 
39 template <typename _Tp>
40 void __test_noexcept(_Tp) noexcept;
41 
42 template <typename _Fm, typename _To>
43 bool_constant<noexcept(std::__test_noexcept<_To>(std::declval<_Fm>()))> __is_nothrow_convertible_test();
44 
45 template <typename _Fm, typename _To>
46 struct __is_nothrow_convertible_helper : decltype(__is_nothrow_convertible_test<_Fm, _To>()) {};
47 
48 template <typename _Fm, typename _To>
49 struct is_nothrow_convertible
50     : _Or<_And<is_void<_To>, is_void<_Fm>>,
51           _Lazy<_And, is_convertible<_Fm, _To>, __is_nothrow_convertible_helper<_Fm, _To> > >::type {};
52 
53 template <typename _Fm, typename _To>
54 inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<_Fm, _To>::value;
55 
56 #  endif // __has_builtin(__is_nothrow_convertible)
57 
58 #endif // _LIBCPP_STD_VER >= 20
59 
60 _LIBCPP_END_NAMESPACE_STD
61 
62 #endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONVERTIBLE_H
63