19 #include <bsoncxx/config/prelude.hpp>
21 #pragma push_macro("BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE")
22 #undef BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE
24 #if (defined(__cplusplus) && __cplusplus >= 201402L) || \
25 (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
26 #define BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE
30 #if !defined(BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE) || !defined(__cpp_lib_smart_ptr_for_overwrite)
33 #include <type_traits>
36 #include <bsoncxx/stdx/type_traits.hpp>
48 struct make_unique_impl {
50 template <
typename... Args,
52 typename = decltype(
new T(std::declval<Args>()...))>
53 static std::unique_ptr<T> make(std::true_type , Args&&... args) {
54 return std::unique_ptr<T>(
new T(std::forward<Args>(args)...));
58 template <
typename U = T,
62 typename = decltype(
new U)>
63 static std::unique_ptr<T> make(std::false_type ) {
64 return std::unique_ptr<T>(
new T);
69 template <
typename Elem>
70 struct make_unique_impl<Elem[]> {
71 template <
typename ShouldDirectInit,
73 typename = decltype(
new Elem[std::declval<std::size_t>()])>
74 static std::unique_ptr<Elem[]> make(ShouldDirectInit, std::size_t count) {
77 if (ShouldDirectInit()) {
78 return std::unique_ptr<Elem[]>(
new Elem[count]());
80 return std::unique_ptr<Elem[]>(
new Elem[count]);
86 template <
typename Elem, std::
size_t N>
87 struct make_unique_impl<Elem[N]> {};
91 struct make_unique_impl<T&> {};
95 struct make_unique_impl<T&&> {};
111 #if defined(BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE)
112 using ::std::make_unique;
116 template <
typename T,
118 typename Impl = detail::make_unique_impl<T>,
119 typename std::enable_if<!std::is_array<T>::value,
120 decltype(Impl::make(std::true_type{}, std::declval<Args>()...),
121 void())>::
type* =
nullptr>
123 return Impl::make(std::true_type{}, std::forward<Args>(args)...);
129 typename Impl = detail::make_unique_impl<T>,
130 typename std::enable_if<std::is_array<T>::value,
131 decltype(Impl::make(std::true_type{}, std::declval<std::size_t>()),
132 void())>::
type* =
nullptr>
134 return Impl::make(std::true_type{}, count);
141 #if defined(__cpp_lib_smart_ptr_for_overwrite)
142 using ::std::make_unique_for_overwrite;
146 template <
typename T,
147 typename Impl = detail::make_unique_impl<T>,
148 typename std::enable_if<!std::is_array<T>::value,
149 decltype(Impl::make(std::false_type{}),
void())>
::type* =
nullptr>
151 return Impl::make(std::false_type{});
157 typename Impl = detail::make_unique_impl<T>,
158 typename std::enable_if<std::is_array<T>::value,
159 decltype(Impl::make(std::false_type{}, std::declval<std::size_t>()),
160 void())>::
type* =
nullptr>
162 return Impl::make(std::false_type{}, count);
171 #pragma pop_macro("BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE")
173 #include <bsoncxx/config/postlude.hpp>
178 using ::bsoncxx::v_noabi::stdx::make_unique;
179 using ::bsoncxx::v_noabi::stdx::make_unique_for_overwrite;
std::unique_ptr< T > make_unique(Args &&... args)
Equivalent to std::make_unique<T>(args...) where T is a non-array type.
Definition: make_unique.hpp:122
std::unique_ptr< T > make_unique_for_overwrite()
Equivalent to std::make_unique_for_overwrite<T>() where T is a non-array type.
Definition: make_unique.hpp:150
type
An enumeration of each BSON type.
Definition: types.hpp:48
The top-level namespace for bsoncxx library entities.
Definition: element-fwd.hpp:19