Botan  2.4.0
Crypto and TLS for C++11
stl_compatibility.h
Go to the documentation of this file.
1 /*
2 * STL standards compatibility functions
3 * (C) 2017 Tomasz Frydrych
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_STL_COMPATIBILITY_H_
9 #define BOTAN_STL_COMPATIBILITY_H_
10 
11 #include <memory>
12 
13 #if __cplusplus < 201402L
14 #include <cstddef>
15 #include <type_traits>
16 #include <utility>
17 #endif
18 
19 namespace Botan
20 {
21 /*
22 * std::make_unique functionality similar as we have in C++14.
23 * C++11 version based on proposal for C++14 implemenatation by Stephan T. Lavavej
24 * source: https://isocpp.org/files/papers/N3656.txt
25 */
26 #if __cplusplus >= 201402L
27 template <typename T, typename ... Args>
28 constexpr auto make_unique(Args&&... args)
29  {
30  return std::make_unique<T>(std::forward<Args>(args)...);
31  }
32 
33 template<class T>
34 constexpr auto make_unique(std::size_t size)
35  {
36  return std::make_unique<T>(size);
37  }
38 
39 #else
40 namespace stlCompatibilityDetails
41 {
42 template<class T> struct _Unique_if
43  {
44  typedef std::unique_ptr<T> _Single_object;
45  };
46 
47 template<class T> struct _Unique_if<T[]>
48  {
49  typedef std::unique_ptr<T[]> _Unknown_bound;
50  };
51 
52 template<class T, size_t N> struct _Unique_if<T[N]>
53  {
54  typedef void _Known_bound;
55  };
56 } // namespace stlCompatibilityDetails
57 
58 template<class T, class... Args>
60  {
61  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
62  }
63 
64 template<class T>
66  {
67  typedef typename std::remove_extent<T>::type U;
68  return std::unique_ptr<T>(new U[n]());
69  }
70 
71 template<class T, class... Args>
73 
74 #endif
75 
76 } // namespace Botan
77 #endif
MechanismType type
stlCompatibilityDetails::_Unique_if< T >::_Single_object make_unique(Args &&... args)
Definition: alg_id.cpp:13
fe T
Definition: ge.cpp:37