Botan 2.13.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 <botan/types.h>
12 #include <memory>
13
14 #if __cplusplus < 201402L
15 #include <cstddef>
16 #include <type_traits>
17 #include <utility>
18 #endif
19
20 BOTAN_FUTURE_INTERNAL_HEADER(stl_compatability.h)
21
22 namespace Botan
23 {
24 /*
25 * std::make_unique functionality similar as we have in C++14.
26 * C++11 version based on proposal for C++14 implemenatation by Stephan T. Lavavej
27 * source: https://isocpp.org/files/papers/N3656.txt
28 */
29 #if __cplusplus >= 201402L
30 template <typename T, typename ... Args>
31 constexpr auto make_unique(Args&&... args)
32 {
33 return std::make_unique<T>(std::forward<Args>(args)...);
34 }
35
36 template<class T>
37 constexpr auto make_unique(std::size_t size)
38 {
39 return std::make_unique<T>(size);
40 }
41
42 #else
43 namespace stlCompatibilityDetails
44 {
45 template<class T> struct _Unique_if
46 {
47 typedef std::unique_ptr<T> _Single_object;
48 };
49
50 template<class T> struct _Unique_if<T[]>
51 {
52 typedef std::unique_ptr<T[]> _Unknown_bound;
53 };
54
55 template<class T, size_t N> struct _Unique_if<T[N]>
56 {
57 typedef void _Known_bound;
58 };
59 } // namespace stlCompatibilityDetails
60
61 template<class T, class... Args>
62 typename stlCompatibilityDetails::_Unique_if<T>::_Single_object make_unique(Args&&... args)
63 {
64 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
65 }
66
67 template<class T>
68 typename stlCompatibilityDetails::_Unique_if<T>::_Unknown_bound make_unique(size_t n)
69 {
70 typedef typename std::remove_extent<T>::type U;
71 return std::unique_ptr<T>(new U[n]());
72 }
73
74 template<class T, class... Args>
75 typename stlCompatibilityDetails::_Unique_if<T>::_Known_bound make_unique(Args&&...) = delete;
76
77 #endif
78
79 } // namespace Botan
80 #endif
Botan::stlCompatibilityDetails::_Unique_if< T[]>::_Unknown_bound
std::unique_ptr< T[]> _Unknown_bound
Definition: stl_compatibility.h:52
Botan::stlCompatibilityDetails::_Unique_if< T[N]>::_Known_bound
void _Known_bound
Definition: stl_compatibility.h:57
Botan::make_unique
stlCompatibilityDetails::_Unique_if< T >::_Known_bound make_unique(Args &&...)=delete
type
MechanismType type
Definition: p11_mechanism.cpp:44
Botan::stlCompatibilityDetails::_Unique_if
Definition: stl_compatibility.h:45
Botan
Definition: alg_id.cpp:13
Botan::stlCompatibilityDetails::_Unique_if::_Single_object
std::unique_ptr< T > _Single_object
Definition: stl_compatibility.h:47
T
fe T
Definition: ge.cpp:37
BOTAN_FUTURE_INTERNAL_HEADER
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:139