/* * Created by Joachim on 16/04/2019. * Adapted from donated nonius code. * * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ // Invoke with a special case for void #ifndef TWOBLUECUBES_CATCH_DETAIL_COMPLETE_INVOKE_HPP_INCLUDED #define TWOBLUECUBES_CATCH_DETAIL_COMPLETE_INVOKE_HPP_INCLUDED #include "../../catch_enforce.h" #include #include namespace Catch { namespace Benchmark { namespace Detail { template struct CompleteType { using type = T; }; template <> struct CompleteType { struct type {}; }; template using CompleteType_t = typename CompleteType::type; template struct CompleteInvoker { template static Result invoke(Fun&& fun, Args&&... args) { return std::forward(fun)(std::forward(args)...); } }; template <> struct CompleteInvoker { template static CompleteType_t invoke(Fun&& fun, Args&&... args) { std::forward(fun)(std::forward(args)...); return {}; } }; template using ResultOf_t = typename std::result_of::type; // invoke and not return void :( template CompleteType_t> complete_invoke(Fun&& fun, Args&&... args) { return CompleteInvoker>::invoke(std::forward(fun), std::forward(args)...); } const std::string benchmarkErrorMsg = "a benchmark failed to run successfully"; } // namespace Detail template Detail::CompleteType_t> user_code(Fun&& fun) { CATCH_TRY{ return Detail::complete_invoke(std::forward(fun)); } CATCH_CATCH_ALL{ getResultCapture().benchmarkFailed(translateActiveException()); CATCH_RUNTIME_ERROR(Detail::benchmarkErrorMsg); } } } // namespace Benchmark } // namespace Catch #endif // TWOBLUECUBES_CATCH_DETAIL_COMPLETE_INVOKE_HPP_INCLUDED