Home | History | Annotate | Download | only in support
      1 //===----------------------------------------------------------------------===//
      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 
     26 namespace 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 
     38 template <class Tp, class ...Args>
     39 constexpr bool test_convertible()
     40 { return detail::test_convertible_imp<Tp, Args...>(0); }
     41 
     42 #endif // SUPPORT_TEST_CONVERTIBLE_HPP
     43