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)
48struct 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);
69template <
typename Elem>
70struct 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]);
86template <
typename Elem, std::
size_t N>
87struct make_unique_impl<Elem[N]> {};
91struct make_unique_impl<T&> {};
95struct make_unique_impl<T&&> {};
111#if defined(BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE)
112using ::std::make_unique;
119 typename Impl = detail::make_unique_impl<T>,
120 typename std::enable_if<!std::is_array<T>::value,
121 decltype(Impl::make(std::true_type{}, std::declval<Args>()...),
122 void())>::type* =
nullptr>
124 return Impl::make(std::true_type{}, std::forward<Args>(args)...);
132 typename Impl = detail::make_unique_impl<T>,
133 typename std::enable_if<std::is_array<T>::value,
134 decltype(Impl::make(std::true_type{}, std::declval<std::size_t>()),
135 void())>::type* =
nullptr>
137 return Impl::make(std::true_type{}, count);
145#if defined(__cpp_lib_smart_ptr_for_overwrite)
146using ::std::make_unique_for_overwrite;
151 typename Impl = detail::make_unique_impl<T>,
152 typename std::enable_if<!std::is_array<T>::value,
153 decltype(Impl::make(std::false_type{}),
void())>::type* =
nullptr>
154std::unique_ptr<T> make_unique_for_overwrite() {
155 return Impl::make(std::false_type{});
161 typename Impl = detail::make_unique_impl<T>,
162 typename std::enable_if<std::is_array<T>::value,
163 decltype(Impl::make(std::false_type{}, std::declval<std::size_t>()),
164 void())>::type* =
nullptr>
165std::unique_ptr<T> make_unique_for_overwrite(std::size_t count) {
166 return Impl::make(std::false_type{}, count);
175#pragma pop_macro("BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE")
182using ::bsoncxx::v_noabi::stdx::make_unique;
183using ::bsoncxx::v_noabi::stdx::make_unique_for_overwrite;
195#if defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
206template <
typename T,
typename... Args>
225template <
typename T,
typename... Args>
The bsoncxx macro guard postlude header.
The bsoncxx macro guard prelude header.
std::unique_ptr< T > make_unique(Args &&... args)
bsoncxx::v_noabi::stdx::make_unique(Args&&... args)
std::unique_ptr< T > make_unique(Args &&... args)
Equivalent to std::make_unique for non-array types.
The top-level namespace within which all bsoncxx library entities are declared.
Provides <type_traits>-related polyfills for internal use.