Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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>
59 typename stlCompatibilityDetails::_Unique_if<T>::_Single_object make_unique(Args&&... args)
60 {
61 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
62 }
63
64 template<class T>
65 typename stlCompatibilityDetails::_Unique_if<T>::_Unknown_bound make_unique(size_t n)
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>
72 typename stlCompatibilityDetails::_Unique_if<T>::_Known_bound make_unique(Args&&...) = delete;
73
74 #endif
75
76 } // namespace Botan
77 #endif
Botan::stlCompatibilityDetails::_Unique_if< T[]>::_Unknown_bound
std::unique_ptr< T[]> _Unknown_bound
Definition: stl_compatibility.h:49
Botan::stlCompatibilityDetails::_Unique_if< T[N]>::_Known_bound
void _Known_bound
Definition: stl_compatibility.h:54
type
MechanismType type
Definition: p11_mechanism.cpp:43
Botan::stlCompatibilityDetails::_Unique_if
Definition: stl_compatibility.h:42
Botan
Definition: alg_id.cpp:13
Botan::stlCompatibilityDetails::_Unique_if::_Single_object
std::unique_ptr< T > _Single_object
Definition: stl_compatibility.h:44
Botan::make_unique
stlCompatibilityDetails::_Unique_if< T >::_Single_object make_unique(Args &&...args)
Definition: stl_compatibility.h:59