Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:02:47

0001 
0002 //              Copyright Catch2 Authors
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //   (See accompanying file LICENSE.txt or copy at
0005 //        https://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // SPDX-License-Identifier: BSL-1.0
0008 // Adapted from donated nonius code.
0009 
0010 #ifndef CATCH_COMPLETE_INVOKE_HPP_INCLUDED
0011 #define CATCH_COMPLETE_INVOKE_HPP_INCLUDED
0012 
0013 #include <catch2/internal/catch_meta.hpp>
0014 #include <catch2/internal/catch_move_and_forward.hpp>
0015 
0016 namespace Catch {
0017     namespace Benchmark {
0018         namespace Detail {
0019             template <typename T>
0020             struct CompleteType { using type = T; };
0021             template <>
0022             struct CompleteType<void> { struct type {}; };
0023 
0024             template <typename T>
0025             using CompleteType_t = typename CompleteType<T>::type;
0026 
0027             template <typename Result>
0028             struct CompleteInvoker {
0029                 template <typename Fun, typename... Args>
0030                 static Result invoke(Fun&& fun, Args&&... args) {
0031                     return CATCH_FORWARD(fun)(CATCH_FORWARD(args)...);
0032                 }
0033             };
0034             template <>
0035             struct CompleteInvoker<void> {
0036                 template <typename Fun, typename... Args>
0037                 static CompleteType_t<void> invoke(Fun&& fun, Args&&... args) {
0038                     CATCH_FORWARD(fun)(CATCH_FORWARD(args)...);
0039                     return {};
0040                 }
0041             };
0042 
0043             // invoke and not return void :(
0044             template <typename Fun, typename... Args>
0045             CompleteType_t<FunctionReturnType<Fun, Args...>> complete_invoke(Fun&& fun, Args&&... args) {
0046                 return CompleteInvoker<FunctionReturnType<Fun, Args...>>::invoke(CATCH_FORWARD(fun), CATCH_FORWARD(args)...);
0047             }
0048 
0049         } // namespace Detail
0050 
0051         template <typename Fun>
0052         Detail::CompleteType_t<FunctionReturnType<Fun>> user_code(Fun&& fun) {
0053             return Detail::complete_invoke(CATCH_FORWARD(fun));
0054         }
0055     } // namespace Benchmark
0056 } // namespace Catch
0057 
0058 #endif // CATCH_COMPLETE_INVOKE_HPP_INCLUDED