Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorMartin Hořeňovský2019-10-28 15:06:54 +0100
committerMartin Hořeňovský2019-10-28 15:15:13 +0100
commitfc320f6b8f55b8781a5e039ff0cad23c578568c2 (patch)
tree2c8d2f2ba7a72efedcd05162b06922b7403e23ad /include
parent5290d4bedcf8f008d2a5475a5cdcd9fe0c8127c5 (diff)
downloadcatch3-fc320f6b8f55b8781a5e039ff0cad23c578568c2.tar.gz
Extract FunctionReturnType to catch_meta.hpp
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_generators_generic.hpp14
-rw-r--r--include/internal/catch_meta.hpp38
2 files changed, 27 insertions, 25 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 <typename Func, typename U>
- using MapFunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U>>>;
-#else
- template <typename Func, typename U>
- using MapFunctionReturnType = typename std::remove_reference<typename std::remove_cv<typename std::result_of<Func(U)>::type>::type>::type;
-#endif
-
- template <typename Func, typename U, typename T = MapFunctionReturnType<Func, U>>
+ template <typename Func, typename U, typename T = FunctionReturnType<Func, U>>
GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) {
return GeneratorWrapper<T>(
pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(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 <type_traits>
namespace Catch {
-template<typename T>
-struct always_false : std::false_type {};
+ template<typename T>
+ struct always_false : std::false_type {};
-template <typename> struct true_given : std::true_type {};
-struct is_callable_tester {
- template <typename Fun, typename... Args>
- true_given<decltype(std::declval<Fun>()(std::declval<Args>()...))> static test(int);
- template <typename...>
- std::false_type static test(...);
-};
+ template <typename> struct true_given : std::true_type {};
+ struct is_callable_tester {
+ template <typename Fun, typename... Args>
+ true_given<decltype(std::declval<Fun>()(std::declval<Args>()...))> static test(int);
+ template <typename...>
+ std::false_type static test(...);
+ };
-template <typename T>
-struct is_callable;
+ template <typename T>
+ struct is_callable;
-template <typename Fun, typename... Args>
-struct is_callable<Fun(Args...)> : decltype(is_callable_tester::test<Fun, Args...>(0)) {};
+ template <typename Fun, typename... Args>
+ struct is_callable<Fun(Args...)> : decltype(is_callable_tester::test<Fun, Args...>(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 <typename Func, typename U>
+ using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U>>>;
+#else
+ template <typename Func, typename U>
+ using FunctionReturnType = typename std::remove_reference<typename std::remove_cv<typename std::result_of<Func(U)>::type>::type>::type;
+#endif
} // namespace Catch