Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
STLExtras.h
Go to the documentation of this file.
1 //===-- serialbox/core/STLExtras.h --------------------------------------------------*- C++ -*-===//
2 //
3 // S E R I A L B O X
4 //
5 // This file is distributed under terms of BSD license.
6 // See LICENSE.txt for more information
7 //
8 //===------------------------------------------------------------------------------------------===//
9 //
13 //===------------------------------------------------------------------------------------------===//
14 
15 #ifndef SERIALBOX_CORE_STLEXTRAS_H
16 #define SERIALBOX_CORE_STLEXTRAS_H
17 
19 #include <cstddef>
20 #include <memory>
21 #include <type_traits>
22 
23 //===------------------------------------------------------------------------------------------===//
24 // Extra additions to <memory>
25 //===------------------------------------------------------------------------------------------===//
26 
27 #if !defined(SERIALBOX_COMPILER_MSVC) && __cplusplus <= 201103L
28 
29 namespace std {
30 
31 // Implement make_unique according to N3656.
32 
41 template <class T, class... Args>
42 typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
43 make_unique(Args&&... args) {
44  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
45 }
46 
56 template <class T>
57 typename std::enable_if<std::is_array<T>::value && std::extent<T>::value == 0,
58  std::unique_ptr<T>>::type
59 make_unique(std::size_t n) {
60  return std::unique_ptr<T>(new typename std::remove_extent<T>::type[n]());
61 }
62 
64 template <class T, class... Args>
65 typename std::enable_if<std::extent<T>::value != 0>::type make_unique(Args&&...) = delete;
66 
67 } // namespace std
68 
69 #endif
70 
71 #endif
Definition: json.hpp:10517