Botan 2.19.1
Crypto and TLS for C&
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
20BOTAN_FUTURE_INTERNAL_HEADER(stl_compatability.h)
21
22namespace 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
30template <typename T, typename ... Args>
31constexpr auto make_unique(Args&&... args)
32 {
33 return std::make_unique<T>(std::forward<Args>(args)...);
34 }
35
36template<class T>
37constexpr auto make_unique(std::size_t size)
38 {
39 return std::make_unique<T>(size);
40 }
41
42#else
43namespace stlCompatibilityDetails
44{
45template<class T> struct _Unique_if
46 {
47 typedef std::unique_ptr<T> _Single_object;
48 };
49
50template<class T> struct _Unique_if<T[]>
51 {
52 typedef std::unique_ptr<T[]> _Unknown_bound;
53 };
54
55template<class T, size_t N> struct _Unique_if<T[N]>
56 {
57 typedef void _Known_bound;
58 };
59} // namespace stlCompatibilityDetails
60
61template<class T, class... Args>
63 {
64 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
65 }
66
67template<class T>
69 {
70 typedef typename std::remove_extent<T>::type U;
71 return std::unique_ptr<T>(new U[n]());
72 }
73
74template<class T, class... Args>
76
77#endif
78
79} // namespace Botan
80#endif
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:136
fe T
Definition: ge.cpp:37
Definition: alg_id.cpp:13
stlCompatibilityDetails::_Unique_if< T >::_Known_bound make_unique(Args &&...)=delete
MechanismType type