FairMQ  1.4.14
C++ Message Queuing Library and 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 // make_unique implementation (array variant), until C++14 is default
31 template<typename T>
32 std::unique_ptr<T> make_unique(std::size_t size)
33 {
34  return std::unique_ptr<T>(new typename std::remove_extent<T>::type[size]());
35 }
36 
37 // provide an enum hasher to compensate std::hash not supporting enums in C++11
38 template<typename Enum>
39 struct HashEnum
40 {
41  auto operator()(const Enum& e) const noexcept
42  -> typename std::enable_if<std::is_enum<Enum>::value, std::size_t>::type
43  {
44  using _type = typename std::underlying_type<Enum>::type;
45  return std::hash<_type>{}(static_cast<_type>(e));
46  }
47 };
48 
49 } /* namespace tools */
50 } /* namespace mq */
51 } /* namespace fair */
52 
53 #endif /* FAIR_MQ_TOOLS_CPPSTL_H */
Definition: CppSTL.h:39
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23

privacy