From fc320f6b8f55b8781a5e039ff0cad23c578568c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Mon, 28 Oct 2019 15:06:54 +0100 Subject: [PATCH] Extract FunctionReturnType to catch_meta.hpp --- include/internal/catch_generators_generic.hpp | 14 ++------ include/internal/catch_meta.hpp | 36 ++++++++++++------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/include/internal/catch_generators_generic.hpp b/include/internal/catch_generators_generic.hpp index 81fd3857..c3410147 100644 --- a/include/internal/catch_generators_generic.hpp +++ b/include/internal/catch_generators_generic.hpp @@ -8,6 +8,7 @@ #define TWOBLUECUBES_CATCH_GENERATORS_GENERIC_HPP_INCLUDED #include "catch_generators.hpp" +#include "catch_meta.hpp" namespace Catch { namespace Generators { @@ -172,18 +173,7 @@ namespace Generators { } }; -#if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703 - // std::result_of is deprecated in C++17 and removed in C++20. Hence, it is - // replaced with std::invoke_result here. Also *_t format is preferred over - // typename *::type format. - template - using MapFunctionReturnType = std::remove_reference_t>>; -#else - template - using MapFunctionReturnType = typename std::remove_reference::type>::type>::type; -#endif - - template > + template > GeneratorWrapper map(Func&& function, GeneratorWrapper&& generator) { return GeneratorWrapper( pf::make_unique>(std::forward(function), std::move(generator)) diff --git a/include/internal/catch_meta.hpp b/include/internal/catch_meta.hpp index 8529766d..4eca7efc 100644 --- a/include/internal/catch_meta.hpp +++ b/include/internal/catch_meta.hpp @@ -12,22 +12,34 @@ #include namespace Catch { -template -struct always_false : std::false_type {}; + template + struct always_false : std::false_type {}; + + template struct true_given : std::true_type {}; + struct is_callable_tester { + template + true_given()(std::declval()...))> static test(int); + template + std::false_type static test(...); + }; + + template + struct is_callable; -template struct true_given : std::true_type {}; -struct is_callable_tester { template - true_given()(std::declval()...))> static test(int); - template - std::false_type static test(...); -}; + struct is_callable : decltype(is_callable_tester::test(0)) {}; -template -struct is_callable; -template -struct is_callable : decltype(is_callable_tester::test(0)) {}; +#if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703 + // std::result_of is deprecated in C++17 and removed in C++20. Hence, it is + // replaced with std::invoke_result here. Also *_t format is preferred over + // typename *::type format. + template + using FunctionReturnType = std::remove_reference_t>>; +#else + template + using FunctionReturnType = typename std::remove_reference::type>::type>::type; +#endif } // namespace Catch