Skip to content

Commit

Permalink
Avoid using std::result_of when std::invoke_result is available
Browse files Browse the repository at this point in the history
Closes #1934
  • Loading branch information
horenmar committed May 21, 2020
1 parent bed4737 commit ddc9f4c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions include/internal/benchmark/detail/catch_complete_invoke.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define TWOBLUECUBES_CATCH_DETAIL_COMPLETE_INVOKE_HPP_INCLUDED

#include "../../catch_enforce.h"
#include "../../catch_meta.hpp"

#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -42,20 +43,18 @@ namespace Catch {
return {};
}
};
template <typename Sig>
using ResultOf_t = typename std::result_of<Sig>::type;

// invoke and not return void :(
template <typename Fun, typename... Args>
CompleteType_t<ResultOf_t<Fun(Args...)>> complete_invoke(Fun&& fun, Args&&... args) {
return CompleteInvoker<ResultOf_t<Fun(Args...)>>::invoke(std::forward<Fun>(fun), std::forward<Args>(args)...);
CompleteType_t<FunctionReturnType<Fun(Args...)>> complete_invoke(Fun&& fun, Args&&... args) {
return CompleteInvoker<FunctionReturnType<Fun(Args...)>>::invoke(std::forward<Fun>(fun), std::forward<Args>(args)...);
}

const std::string benchmarkErrorMsg = "a benchmark failed to run successfully";
} // namespace Detail

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{
return Detail::complete_invoke(std::forward<Fun>(fun));
} CATCH_CATCH_ALL{
Expand Down
2 changes: 1 addition & 1 deletion include/internal/benchmark/detail/catch_timing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Catch {
int iterations;
};
template <typename Clock, typename Sig>
using TimingOf = Timing<ClockDuration<Clock>, Detail::CompleteType_t<Detail::ResultOf_t<Sig>>>;
using TimingOf = Timing<ClockDuration<Clock>, Detail::CompleteType_t<FunctionReturnType<Sig>>>;
} // namespace Benchmark
} // namespace Catch

Expand Down

0 comments on commit ddc9f4c

Please sign in to comment.