Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
JoinFunction.hh
Go to the documentation of this file.
1//
2// MIT License
3// Copyright (c) 2020 Jonathan R. Madsen
4// Permission is hereby granted, free of charge, to any person obtaining a copy
5// of this software and associated documentation files (the "Software"), to deal
6// in the Software without restriction, including without limitation the rights
7// to use, copy, modify, merge, publish, distribute, sublicense, and
8// copies of the Software, and to permit persons to whom the Software is
9// furnished to do so, subject to the following conditions:
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
12// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
13// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
15// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
17// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18//
19//
20// ---------------------------------------------------------------
21// Tasking class header file
22//
23// Class Description:
24//
25// This is the join function used by task groups
26//
27// ---------------------------------------------------------------
28// Author: Jonathan Madsen (Feb 13th 2018)
29// ---------------------------------------------------------------
30
31#pragma once
32
33#include "PTL/Types.hh"
34
35#include <functional>
36#include <utility>
37
38namespace PTL
39{
40template <typename JoinT, typename JoinArg>
42{
43public:
44 using Type = std::function<JoinT(JoinT&, JoinArg&&)>;
45
46public:
48
49 template <typename Func>
50 JoinFunction(Func&& func)
51 : m_func(std::forward<Func>(func))
52 {}
53
54 template <typename... Args>
55 JoinT& operator()(Args&&... args)
56 {
57 return std::move(m_func(std::forward<Args>(args)...));
58 }
59
60private:
61 Type m_func = [](JoinT& lhs, JoinArg&&) { return lhs; };
62};
63
64//--------------------------------------------------------------------------------------//
65
66template <typename JoinArg>
67struct JoinFunction<void, JoinArg>
68{
69public:
70 using Type = std::function<void(JoinArg)>;
71
72public:
74
75 template <typename Func>
76 JoinFunction(Func&& func)
77 : m_func(std::forward<Func>(func))
78 {}
79
80 template <typename... Args>
81 void operator()(Args&&... args)
82 {
83 m_func(std::forward<Args>(args)...);
84 }
85
86private:
87 Type m_func = [](JoinArg) {};
88};
89
90//--------------------------------------------------------------------------------------//
91
92template <>
93struct JoinFunction<void, void>
94{
95public:
96 using Type = std::function<void()>;
97
98public:
100
101 template <typename Func>
102 JoinFunction(Func&& func)
103 : m_func(std::forward<Func>(func))
104 {}
105
106 void operator()() { m_func(); }
107
108private:
109 Type m_func = []() {};
110};
111
112} // namespace PTL
#define PTL_DEFAULT_OBJECT(NAME)
Definition: Types.hh:86
Definition: AutoLock.hh:255
std::function< void(JoinArg)> Type
Definition: JoinFunction.hh:70
void operator()(Args &&... args)
Definition: JoinFunction.hh:81
std::function< void()> Type
Definition: JoinFunction.hh:96
JoinT & operator()(Args &&... args)
Definition: JoinFunction.hh:55
JoinFunction(Func &&func)
Definition: JoinFunction.hh:50
std::function< JoinT(JoinT &, JoinArg &&)> Type
Definition: JoinFunction.hh:44