mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Avoid using std::result_of when std::invoke_result is available
This commit is contained in:
parent
21d284df34
commit
1356788ea8
@ -12,6 +12,7 @@
|
|||||||
#define TWOBLUECUBES_CATCH_DETAIL_COMPLETE_INVOKE_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_DETAIL_COMPLETE_INVOKE_HPP_INCLUDED
|
||||||
|
|
||||||
#include <catch2/internal/catch_enforce.hpp>
|
#include <catch2/internal/catch_enforce.hpp>
|
||||||
|
#include <catch2/internal/catch_meta.hpp>
|
||||||
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
||||||
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
||||||
|
|
||||||
@ -44,20 +45,18 @@ namespace Catch {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template <typename Sig>
|
|
||||||
using ResultOf_t = typename std::result_of<Sig>::type;
|
|
||||||
|
|
||||||
// invoke and not return void :(
|
// invoke and not return void :(
|
||||||
template <typename Fun, typename... Args>
|
template <typename Fun, typename... Args>
|
||||||
CompleteType_t<ResultOf_t<Fun(Args...)>> complete_invoke(Fun&& fun, Args&&... args) {
|
CompleteType_t<FunctionReturnType<Fun, Args...>> complete_invoke(Fun&& fun, Args&&... args) {
|
||||||
return CompleteInvoker<ResultOf_t<Fun(Args...)>>::invoke(std::forward<Fun>(fun), std::forward<Args>(args)...);
|
return CompleteInvoker<FunctionReturnType<Fun, Args...>>::invoke(std::forward<Fun>(fun), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const std::string benchmarkErrorMsg;
|
extern const std::string benchmarkErrorMsg;
|
||||||
} // namespace Detail
|
} // namespace Detail
|
||||||
|
|
||||||
template <typename Fun>
|
template <typename Fun>
|
||||||
Detail::CompleteType_t<Detail::ResultOf_t<Fun()>> user_code(Fun&& fun) {
|
Detail::CompleteType_t<FunctionReturnType<Fun>> user_code(Fun&& fun) {
|
||||||
CATCH_TRY{
|
CATCH_TRY{
|
||||||
return Detail::complete_invoke(std::forward<Fun>(fun));
|
return Detail::complete_invoke(std::forward<Fun>(fun));
|
||||||
} CATCH_CATCH_ALL{
|
} CATCH_CATCH_ALL{
|
||||||
|
@ -21,7 +21,7 @@ namespace Catch {
|
|||||||
namespace Benchmark {
|
namespace Benchmark {
|
||||||
namespace Detail {
|
namespace Detail {
|
||||||
template <typename Clock, typename Fun, typename... Args>
|
template <typename Clock, typename Fun, typename... Args>
|
||||||
TimingOf<Clock, Fun(Args...)> measure(Fun&& fun, Args&&... args) {
|
TimingOf<Clock, Fun, Args...> measure(Fun&& fun, Args&&... args) {
|
||||||
auto start = Clock::now();
|
auto start = Clock::now();
|
||||||
auto&& r = Detail::complete_invoke(fun, std::forward<Args>(args)...);
|
auto&& r = Detail::complete_invoke(fun, std::forward<Args>(args)...);
|
||||||
auto end = Clock::now();
|
auto end = Clock::now();
|
||||||
|
@ -25,11 +25,11 @@ namespace Catch {
|
|||||||
namespace Benchmark {
|
namespace Benchmark {
|
||||||
namespace Detail {
|
namespace Detail {
|
||||||
template <typename Clock, typename Fun>
|
template <typename Clock, typename Fun>
|
||||||
TimingOf<Clock, Fun(int)> measure_one(Fun&& fun, int iters, std::false_type) {
|
TimingOf<Clock, Fun, int> measure_one(Fun&& fun, int iters, std::false_type) {
|
||||||
return Detail::measure<Clock>(fun, iters);
|
return Detail::measure<Clock>(fun, iters);
|
||||||
}
|
}
|
||||||
template <typename Clock, typename Fun>
|
template <typename Clock, typename Fun>
|
||||||
TimingOf<Clock, Fun(Chronometer)> measure_one(Fun&& fun, int iters, std::true_type) {
|
TimingOf<Clock, Fun, Chronometer> measure_one(Fun&& fun, int iters, std::true_type) {
|
||||||
Detail::ChronometerModel<Clock> meter;
|
Detail::ChronometerModel<Clock> meter;
|
||||||
auto&& result = Detail::complete_invoke(fun, Chronometer(meter, iters));
|
auto&& result = Detail::complete_invoke(fun, Chronometer(meter, iters));
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ namespace Catch {
|
|||||||
void throw_optimized_away_error();
|
void throw_optimized_away_error();
|
||||||
|
|
||||||
template <typename Clock, typename Fun>
|
template <typename Clock, typename Fun>
|
||||||
TimingOf<Clock, Fun(run_for_at_least_argument_t<Clock, Fun>)> run_for_at_least(ClockDuration<Clock> how_long, int seed, Fun&& fun) {
|
TimingOf<Clock, Fun, run_for_at_least_argument_t<Clock, Fun>> run_for_at_least(ClockDuration<Clock> how_long, int seed, Fun&& fun) {
|
||||||
auto iters = seed;
|
auto iters = seed;
|
||||||
while (iters < (1 << 30)) {
|
while (iters < (1 << 30)) {
|
||||||
auto&& Timing = measure_one<Clock>(fun, iters, is_callable<Fun(Chronometer)>());
|
auto&& Timing = measure_one<Clock>(fun, iters, is_callable<Fun(Chronometer)>());
|
||||||
|
@ -24,8 +24,8 @@ namespace Catch {
|
|||||||
Result result;
|
Result result;
|
||||||
int iterations;
|
int iterations;
|
||||||
};
|
};
|
||||||
template <typename Clock, typename Sig>
|
template <typename Clock, typename Func, typename... Args>
|
||||||
using TimingOf = Timing<ClockDuration<Clock>, Detail::CompleteType_t<Detail::ResultOf_t<Sig>>>;
|
using TimingOf = Timing<ClockDuration<Clock>, Detail::CompleteType_t<FunctionReturnType<Func, Args...>>>;
|
||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
|
@ -32,13 +32,12 @@ namespace Catch {
|
|||||||
|
|
||||||
#if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703
|
#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
|
// 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
|
// replaced with std::invoke_result here.
|
||||||
// typename *::type format.
|
template <typename Func, typename... U>
|
||||||
template <typename Func, typename U>
|
using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U...>>>;
|
||||||
using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U>>>;
|
|
||||||
#else
|
#else
|
||||||
template <typename Func, typename U>
|
template <typename Func, typename... U>
|
||||||
using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::result_of_t<Func(U)>>>;
|
using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::result_of_t<Func(U...)>>>;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
Loading…
Reference in New Issue
Block a user