catch_meta.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Created by Jozef on 02/12/2018.
  3. * Copyright 2018 Two Blue Cubes Ltd. All rights reserved.
  4. *
  5. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef TWOBLUECUBES_CATCH_META_HPP_INCLUDED
  9. #define TWOBLUECUBES_CATCH_META_HPP_INCLUDED
  10. #include <type_traits>
  11. namespace Catch {
  12. template<typename T>
  13. struct always_false : std::false_type {};
  14. template <typename> struct true_given : std::true_type {};
  15. struct is_callable_tester {
  16. template <typename Fun, typename... Args>
  17. true_given<decltype(std::declval<Fun>()(std::declval<Args>()...))> static test(int);
  18. template <typename...>
  19. std::false_type static test(...);
  20. };
  21. template <typename T>
  22. struct is_callable;
  23. template <typename Fun, typename... Args>
  24. struct is_callable<Fun(Args...)> : decltype(is_callable_tester::test<Fun, Args...>(0)) {};
  25. #if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703
  26. // std::result_of is deprecated in C++17 and removed in C++20. Hence, it is
  27. // replaced with std::invoke_result here.
  28. template <typename Func, typename... U>
  29. using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U...>>>;
  30. #else
  31. // Keep ::type here because we still support C++11
  32. template <typename Func, typename... U>
  33. using FunctionReturnType = typename std::remove_reference<typename std::remove_cv<typename std::result_of<Func(U...)>::type>::type>::type;
  34. #endif
  35. } // namespace Catch
  36. namespace mpl_{
  37. struct na;
  38. }
  39. #endif // TWOBLUECUBES_CATCH_META_HPP_INCLUDED