Warning, file /include/Geant4/PTL/JoinFunction.hh was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #pragma once
0032
0033 #include "PTL/Macros.hh"
0034
0035 #include <functional>
0036 #include <utility>
0037
0038 namespace PTL
0039 {
0040 template <typename JoinT, typename JoinArg>
0041 struct JoinFunction
0042 {
0043 public:
0044 using Type = std::function<JoinT(JoinT&, JoinArg&&)>;
0045
0046 public:
0047 PTL_DEFAULT_OBJECT(JoinFunction)
0048
0049 template <typename Func>
0050 JoinFunction(Func&& func)
0051 : m_func(std::forward<Func>(func))
0052 {}
0053
0054 template <typename... Args>
0055 JoinT& operator()(Args&&... args)
0056 {
0057 return std::move(m_func(std::forward<Args>(args)...));
0058 }
0059
0060 private:
0061 Type m_func = [](JoinT& lhs, JoinArg&&) { return lhs; };
0062 };
0063
0064
0065
0066 template <typename JoinArg>
0067 struct JoinFunction<void, JoinArg>
0068 {
0069 public:
0070 using Type = std::function<void(JoinArg)>;
0071
0072 public:
0073 PTL_DEFAULT_OBJECT(JoinFunction)
0074
0075 template <typename Func>
0076 JoinFunction(Func&& func)
0077 : m_func(std::forward<Func>(func))
0078 {}
0079
0080 template <typename... Args>
0081 void operator()(Args&&... args)
0082 {
0083 m_func(std::forward<Args>(args)...);
0084 }
0085
0086 private:
0087 Type m_func = [](JoinArg) {};
0088 };
0089
0090
0091
0092 template <>
0093 struct JoinFunction<void, void>
0094 {
0095 public:
0096 using Type = std::function<void()>;
0097
0098 public:
0099 PTL_DEFAULT_OBJECT(JoinFunction)
0100
0101 template <typename Func>
0102 JoinFunction(Func&& func)
0103 : m_func(std::forward<Func>(func))
0104 {}
0105
0106 void operator()() { m_func(); }
0107
0108 private:
0109 Type m_func = []() {};
0110 };
0111
0112 }