OGLplus  (0.59.0) a C++ wrapper for rendering APIs

interleaved_call.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_INTERLEAVED_CALL_HPP
10 #define EAGINE_INTERLEAVED_CALL_HPP
11 
12 #include "branch_predict.hpp"
13 #include <utility>
14 
15 namespace eagine {
16 
19 template <typename Func, typename SepFunc>
21 public:
23  interleaved_call(Func func, SepFunc sep_func)
24  : _func(func)
25  , _sep_func(sep_func) {}
26 
28  template <typename... P>
29  auto operator()(P&&... p) {
30  if(EAGINE_LIKELY(!_first)) {
31  _sep_func();
32  } else {
33  _first = false;
34  }
35  return _func(std::forward<P>(p)...);
36  }
37 
38 private:
39  Func _func;
40  SepFunc _sep_func;
41  bool _first{true};
42 };
43 
44 template <typename Func, typename SepFunc>
45 interleaved_call(Func func, SepFunc sep_func)
46  -> interleaved_call<Func, SepFunc>;
47 
48 } // namespace eagine
49 
50 #endif // EAGINE_INTERLEAVED_CALL_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21
auto operator()(P &&... p)
The function call operator.
Definition: interleaved_call.hpp:29
interleaved_call(Func func, SepFunc sep_func)
Construction from the base function and the separator function.
Definition: interleaved_call.hpp:23
Callable class that interleaves calls to a function with a separator function.
Definition: interleaved_call.hpp:20

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).