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