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