CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
FunctionTimer.hpp
1 /*
2  * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
3  *
4  * This software is distributed under the terms of the GNU General Public
5  * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
6  * the license.
7  */
8 #pragma once
9 
10 #include <chrono>
11 #include <utility>
12 #include <type_traits>
13 
14 #include <corsika/framework/analytics/Timer.hpp>
15 
16 namespace corsika {
17 
19 
27  template <typename TFunc, class TTimer = Timer<std::chrono::high_resolution_clock,
28  std::chrono::microseconds>>
29  class FunctionTimer : public TTimer {
30  static_assert(
31  is_timer_v<TTimer>,
32  "TTimer is not a timer!"); // Better
33  // https://en.cppreference.com/w/cpp/language/constraints
34  // but not available in C++17
35  public:
39  FunctionTimer(TFunc f);
40 
51  template <typename... TArgs>
52  auto operator()(TArgs&&... args) -> std::invoke_result_t<TFunc, TArgs...>;
53 
54  private:
55  TFunc function_;
56  };
57 
58 } // namespace corsika
59 
60 #include <corsika/detail/framework/analytics/FunctionTimer.inl>
Wraps and measures the runtime of a single function type object.
`, since they are used everywhere as integral part of the framework.
auto operator()(TArgs &&... args) -> std::invoke_result_t< TFunc, TArgs... >
Functor for calling the wrapped function This functor calls the wrapped function and measures the ela...
FunctionTimer(TFunc f)
Constructs the wrapper with the given functionpointer.