Extract FunctionReturnType to catch_meta.hpp

This commit is contained in:
Martin Hořeňovský 2019-10-28 15:06:54 +01:00
parent 5290d4bedc
commit fc320f6b8f
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 26 additions and 24 deletions

View File

@ -8,6 +8,7 @@
#define TWOBLUECUBES_CATCH_GENERATORS_GENERIC_HPP_INCLUDED #define TWOBLUECUBES_CATCH_GENERATORS_GENERIC_HPP_INCLUDED
#include "catch_generators.hpp" #include "catch_generators.hpp"
#include "catch_meta.hpp"
namespace Catch { namespace Catch {
namespace Generators { namespace Generators {
@ -172,18 +173,7 @@ namespace Generators {
} }
}; };
#if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703 template <typename Func, typename U, typename T = FunctionReturnType<Func, U>>
// 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>>
GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) { GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) {
return GeneratorWrapper<T>( return GeneratorWrapper<T>(
pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator)) pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator))

View File

@ -29,6 +29,18 @@ struct is_callable;
template <typename Fun, typename... Args> template <typename Fun, typename... Args>
struct is_callable<Fun(Args...)> : decltype(is_callable_tester::test<Fun, Args...>(0)) {}; 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 } // namespace Catch
namespace mpl_{ namespace mpl_{