FairMQ  1.2.3
C++ Message Passing Framework
CppSTL.h
1 /********************************************************************************
2  * Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #ifndef FAIR_MQ_TOOLS_CPPSTL_H
10 #define FAIR_MQ_TOOLS_CPPSTL_H
11 
12 #include <functional>
13 #include <memory>
14 #include <type_traits>
15 
16 namespace fair
17 {
18 namespace mq
19 {
20 namespace tools
21 {
22 
23 // make_unique implementation, until C++14 is default
24 template<typename T, typename ...Args>
25 std::unique_ptr<T> make_unique(Args&& ...args)
26 {
27  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
28 }
29 
30 // provide an enum hasher to compensate std::hash not supporting enums in C++11
31 template<typename Enum>
32 struct HashEnum
33 {
34  auto operator()(const Enum& e) const noexcept
35  -> typename std::enable_if<std::is_enum<Enum>::value, std::size_t>::type
36  {
37  using _type = typename std::underlying_type<Enum>::type;
38  return std::hash<_type>{}(static_cast<_type>(e));
39  }
40 };
41 
42 } /* namespace tools */
43 } /* namespace mq */
44 } /* namespace fair */
45 
46 #endif /* FAIR_MQ_TOOLS_CPPSTL_H */
Definition: CppSTL.h:32
Definition: DeviceRunner.h:23