Eric Fiselier | c797958 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Eric Fiselier | c797958 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef SUPPORT_TEST_CONVERTIBLE_HPP |
| 10 | #define SUPPORT_TEST_CONVERTIBLE_HPP |
| 11 | |
| 12 | // "test_convertible<Tp, Args...>()" is a metafunction used to check if 'Tp' |
| 13 | // is implicitly convertible from 'Args...' for any number of arguments, |
| 14 | // Unlike 'std::is_convertible' which only allows checking for single argument |
| 15 | // conversions. |
| 16 | |
| 17 | #include <type_traits> |
| 18 | |
| 19 | #include "test_macros.h" |
| 20 | |
| 21 | #if TEST_STD_VER < 11 |
| 22 | #error test_convertible.hpp requires C++11 or newer |
| 23 | #endif |
| 24 | |
| 25 | namespace detail { |
| 26 | template <class Tp> void eat_type(Tp); |
| 27 | |
| 28 | template <class Tp, class ...Args> |
| 29 | constexpr auto test_convertible_imp(int) |
| 30 | -> decltype(eat_type<Tp>({std::declval<Args>()...}), true) |
| 31 | { return true; } |
| 32 | |
| 33 | template <class Tp, class ...Args> |
| 34 | constexpr auto test_convertible_imp(long) -> bool { return false; } |
| 35 | } |
| 36 | |
| 37 | template <class Tp, class ...Args> |
| 38 | constexpr bool test_convertible() |
| 39 | { return detail::test_convertible_imp<Tp, Args...>(0); } |
| 40 | |
Stephan T. Lavavej | d29b12e | 2017-07-29 00:55:22 +0000 | [diff] [blame] | 41 | #endif // SUPPORT_TEST_CONVERTIBLE_HPP |