Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
MakeUnique.hxx
Go to the documentation of this file.
1
14// Check if we are building with less than C++14 and if so we need to define
15// the std::make_unique() API.
16#if __cplusplus < 201402L
17
18#include <memory>
19#include <type_traits>
20#include <utility>
21
22namespace std
23{
24
25template <typename T, typename... Args>
26unique_ptr<T> make_unique_helper(false_type, Args&&... args)
27{
28 return unique_ptr<T>(new T(forward<Args>(args)...));
29}
30
31template <typename T, typename... Args>
32unique_ptr<T> make_unique_helper(true_type, Args&&... args)
33{
34 static_assert(extent<T>::value == 0,
35 "make_unique<T[N]>() is forbidden, please use make_unique<T[]>().");
36
37 typedef typename remove_extent<T>::type U;
38 return unique_ptr<T>(new U[sizeof...(Args)]{forward<Args>(args)...});
39}
40
41template <typename T, typename... Args>
42unique_ptr<T> make_unique(Args&&... args)
43{
44 return make_unique_helper<T>(is_array<T>(), forward<Args>(args)...);
45}
46
47}
48
49#endif // __cplusplus < 201402L
50