Geant4-11
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 <cstdint>
36#include <deque>
37#include <functional>
38#include <future>
39#include <list>
40#include <vector>
41
42namespace PTL
43{
44template <typename JoinT, typename JoinArg>
46{
47public:
48 using Type = std::function<JoinT(JoinT&, JoinArg&&)>;
49
50public:
52
53 template <typename Func>
54 JoinFunction(Func&& func)
55 : m_func(std::forward<Func>(func))
56 {}
57
58 template <typename... Args>
59 JoinT& operator()(Args&&... args)
60 {
61 return std::move(m_func(std::forward<Args>(args)...));
62 }
63
64private:
65 Type m_func = [](JoinT& lhs, JoinArg&&) { return lhs; };
66};
67
68//--------------------------------------------------------------------------------------//
69
70template <typename JoinArg>
71struct JoinFunction<void, JoinArg>
72{
73public:
74 using Type = std::function<void(JoinArg)>;
75
76public:
78
79 template <typename Func>
80 JoinFunction(Func&& func)
81 : m_func(std::forward<Func>(func))
82 {}
83
84 template <typename... Args>
85 void operator()(Args&&... args)
86 {
87 m_func(std::forward<Args>(args)...);
88 }
89
90private:
91 Type m_func = [](JoinArg) {};
92};
93
94//--------------------------------------------------------------------------------------//
95
96template <>
97struct JoinFunction<void, void>
98{
99public:
100 using Type = std::function<void()>;
101
102public:
104
105 template <typename Func>
106 JoinFunction(Func&& func)
107 : m_func(std::forward<Func>(func))
108 {}
109
110 void operator()() { m_func(); }
111
112private:
113 Type m_func = []() {};
114};
115
116} // namespace PTL
G4double(* function)(G4double)
static char ** args
Definition: G4Xt.cc:51
#define PTL_DEFAULT_OBJECT(NAME)
Definition: Types.hh:56
Definition: AutoLock.hh:254
std::function< void(JoinArg)> Type
Definition: JoinFunction.hh:74
void operator()(Args &&... args)
Definition: JoinFunction.hh:85
std::function< void()> Type
JoinT & operator()(Args &&... args)
Definition: JoinFunction.hh:59
JoinFunction(Func &&func)
Definition: JoinFunction.hh:54
std::function< JoinT(JoinT &, JoinArg &&)> Type
Definition: JoinFunction.hh:48