xref: /aosp_15_r20/external/libcxx/test/support/test_convertible.hpp (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
1*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
2*58b9f456SAndroid Build Coastguard Worker //
3*58b9f456SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*58b9f456SAndroid Build Coastguard Worker //
5*58b9f456SAndroid Build Coastguard Worker // This file is dual licensed under the MIT and the University of Illinois Open
6*58b9f456SAndroid Build Coastguard Worker // Source Licenses. See LICENSE.TXT for details.
7*58b9f456SAndroid Build Coastguard Worker //
8*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*58b9f456SAndroid Build Coastguard Worker 
10*58b9f456SAndroid Build Coastguard Worker #ifndef SUPPORT_TEST_CONVERTIBLE_HPP
11*58b9f456SAndroid Build Coastguard Worker #define SUPPORT_TEST_CONVERTIBLE_HPP
12*58b9f456SAndroid Build Coastguard Worker 
13*58b9f456SAndroid Build Coastguard Worker // "test_convertible<Tp, Args...>()" is a metafunction used to check if 'Tp'
14*58b9f456SAndroid Build Coastguard Worker // is implicitly convertible from 'Args...' for any number of arguments,
15*58b9f456SAndroid Build Coastguard Worker // Unlike 'std::is_convertible' which only allows checking for single argument
16*58b9f456SAndroid Build Coastguard Worker // conversions.
17*58b9f456SAndroid Build Coastguard Worker 
18*58b9f456SAndroid Build Coastguard Worker #include <type_traits>
19*58b9f456SAndroid Build Coastguard Worker 
20*58b9f456SAndroid Build Coastguard Worker #include "test_macros.h"
21*58b9f456SAndroid Build Coastguard Worker 
22*58b9f456SAndroid Build Coastguard Worker #if TEST_STD_VER < 11
23*58b9f456SAndroid Build Coastguard Worker #error test_convertible.hpp requires C++11 or newer
24*58b9f456SAndroid Build Coastguard Worker #endif
25*58b9f456SAndroid Build Coastguard Worker 
26*58b9f456SAndroid Build Coastguard Worker namespace detail {
27*58b9f456SAndroid Build Coastguard Worker     template <class Tp> void eat_type(Tp);
28*58b9f456SAndroid Build Coastguard Worker 
29*58b9f456SAndroid Build Coastguard Worker     template <class Tp, class ...Args>
test_convertible_imp(int)30*58b9f456SAndroid Build Coastguard Worker     constexpr auto test_convertible_imp(int)
31*58b9f456SAndroid Build Coastguard Worker         -> decltype(eat_type<Tp>({std::declval<Args>()...}), true)
32*58b9f456SAndroid Build Coastguard Worker     { return true; }
33*58b9f456SAndroid Build Coastguard Worker 
34*58b9f456SAndroid Build Coastguard Worker     template <class Tp, class ...Args>
test_convertible_imp(long)35*58b9f456SAndroid Build Coastguard Worker     constexpr auto test_convertible_imp(long) -> bool { return false; }
36*58b9f456SAndroid Build Coastguard Worker }
37*58b9f456SAndroid Build Coastguard Worker 
38*58b9f456SAndroid Build Coastguard Worker template <class Tp, class ...Args>
test_convertible()39*58b9f456SAndroid Build Coastguard Worker constexpr bool test_convertible()
40*58b9f456SAndroid Build Coastguard Worker { return detail::test_convertible_imp<Tp, Args...>(0); }
41*58b9f456SAndroid Build Coastguard Worker 
42*58b9f456SAndroid Build Coastguard Worker #endif // SUPPORT_TEST_CONVERTIBLE_HPP
43