Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:46

0001 //
0002 // MIT License
0003 // Copyright (c) 2020 Jonathan R. Madsen
0004 // Permission is hereby granted, free of charge, to any person obtaining a copy
0005 // of this software and associated documentation files (the "Software"), to deal
0006 // in the Software without restriction, including without limitation the rights
0007 // to use, copy, modify, merge, publish, distribute, sublicense, and
0008 // copies of the Software, and to permit persons to whom the Software is
0009 // furnished to do so, subject to the following conditions:
0010 // The above copyright notice and this permission notice shall be included in
0011 // all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
0012 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
0013 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
0014 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
0015 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0016 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
0017 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0018 //
0019 //
0020 // ---------------------------------------------------------------
0021 // Tasking class header file
0022 //
0023 // Class Description:
0024 //
0025 // This is the join function used by task groups
0026 //
0027 // ---------------------------------------------------------------
0028 // Author: Jonathan Madsen (Feb 13th 2018)
0029 // ---------------------------------------------------------------
0030 
0031 #pragma once
0032 
0033 #include "PTL/Types.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 }  // namespace PTL