19 #include <type_traits>
22 #include <bsoncxx/stdx/type_traits.hpp>
24 #include <bsoncxx/config/prelude.hpp>
27 inline namespace v_noabi {
37 struct make_unique_impl {
39 template <
typename... Args,
41 typename = decltype(
new T(std::declval<Args>()...))>
42 static std::unique_ptr<T> make(std::true_type , Args&&... args) {
43 return std::unique_ptr<T>(
new T(std::forward<Args>(args)...));
47 template <
typename U = T,
51 typename = decltype(
new U)>
52 static std::unique_ptr<T> make(std::false_type ) {
53 return std::unique_ptr<T>(
new T);
58 template <
typename Elem>
59 struct make_unique_impl<Elem[]> {
60 template <
typename ShouldDirectInit,
62 typename = decltype(
new Elem[std::declval<std::size_t>()])>
63 static std::unique_ptr<Elem[]> make(ShouldDirectInit, std::size_t count) {
66 if (ShouldDirectInit()) {
67 return std::unique_ptr<Elem[]>(
new Elem[count]());
69 return std::unique_ptr<Elem[]>(
new Elem[count]);
75 template <
typename Elem, std::
size_t N>
76 struct make_unique_impl<Elem[N]> {};
80 struct make_unique_impl<T&> {};
84 struct make_unique_impl<T&&> {};
91 typename Impl = detail::make_unique_impl<T>,
92 typename std::enable_if<!std::is_array<T>::value,
93 decltype(Impl::make(std::true_type{}, std::declval<Args>()...),
94 void())>::
type* =
nullptr>
96 return Impl::make(std::true_type{}, std::forward<Args>(args)...);
102 typename Impl = detail::make_unique_impl<T>,
103 typename std::enable_if<std::is_array<T>::value,
104 decltype(Impl::make(std::true_type{}, std::declval<std::size_t>()),
105 void())>::
type* =
nullptr>
107 return Impl::make(std::true_type{}, count);
111 template <
typename T,
112 typename Impl = detail::make_unique_impl<T>,
113 typename std::enable_if<!std::is_array<T>::value,
114 decltype(Impl::make(std::false_type{}),
void())>
::type* =
nullptr>
116 return Impl::make(std::false_type{});
122 typename Impl = detail::make_unique_impl<T>,
123 typename std::enable_if<std::is_array<T>::value,
124 decltype(Impl::make(std::false_type{}, std::declval<std::size_t>()),
125 void())>::
type* =
nullptr>
127 return Impl::make(std::false_type{}, count);
134 #include <bsoncxx/config/postlude.hpp>
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:95
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:115
type
An enumeration of each BSON type.
Definition: types.hpp:50
The top-level namespace for bsoncxx library entities.
Definition: element.hpp:24