test_convertible.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #ifndef SUPPORT_TEST_CONVERTIBLE_H
  9. #define SUPPORT_TEST_CONVERTIBLE_H
  10. // "test_convertible<Tp, Args...>()" is a metafunction used to check if 'Tp'
  11. // is implicitly convertible from 'Args...' for any number of arguments,
  12. // Unlike 'std::is_convertible' which only allows checking for single argument
  13. // conversions.
  14. #include <type_traits>
  15. #include "test_macros.h"
  16. #if TEST_STD_VER < 11
  17. #error test_convertible.h requires C++11 or newer
  18. #endif
  19. namespace detail {
  20. template <class Tp> void eat_type(Tp);
  21. template <class Tp, class ...Args>
  22. constexpr auto test_convertible_imp(int)
  23. -> decltype(eat_type<Tp>({std::declval<Args>()...}), true)
  24. { return true; }
  25. template <class Tp, class ...Args>
  26. constexpr auto test_convertible_imp(long) -> bool { return false; }
  27. }
  28. template <class Tp, class ...Args>
  29. constexpr bool test_convertible()
  30. { return detail::test_convertible_imp<Tp, Args...>(0); }
  31. #endif // SUPPORT_TEST_CONVERTIBLE_H