11 #include <daw/daw_traits.h>
16 #include <type_traits>
17 #include <unordered_map>
59 template<
typename... Args>
60 [[nodiscard]]
inline constexpr
auto operator( )( Args &&... args )
const
61 noexcept( std::is_nothrow_constructible_v<T, Args...> )
62 -> std::enable_if_t<std::is_constructible_v<T, Args...>, T> {
64 return T( std::forward<Args>( args )... );
67 template<
typename... Args>
68 [[nodiscard]]
inline constexpr
auto operator( )( Args &&... args )
const
69 noexcept( daw::traits::is_nothrow_list_constructible_v<T, Args...> )
70 -> std::enable_if_t<(not std::is_constructible_v<T, Args...> and
71 daw::traits::is_list_constructible_v<T, Args...>),
74 return T{ std::forward<Args>( args )... };
78 template<
typename K,
typename V,
typename H,
typename E,
typename Alloc>
79 struct default_constructor<std::unordered_map<K, V, H, E, Alloc>> {
80 inline std::unordered_map<K, V, H, E, Alloc> operator( )( )
const
81 noexcept( noexcept( std::unordered_map<K, V, H, E, Alloc>( ) ) ) {
85 template<
typename Iterator>
86 inline std::unordered_map<K, V, H, E, Alloc>
87 operator( )( Iterator first, Iterator last,
88 Alloc
const &alloc = Alloc{ } )
const
89 noexcept( noexcept( std::unordered_map<K, V, H, E, Alloc>( first, last, 0,
92 return std::unordered_map<K, V, H, E, Alloc>( first, last, 0, H{ }, E{ },
107 using value_type = T;
109 [[nodiscard]] DAW_ATTRIBUTE_FLATTEN constexpr std::optional<T>
110 operator( )( )
const noexcept {
111 return std::optional<T>( );
114 template<
typename... Args>
115 [[nodiscard]] DAW_ATTRIBUTE_FLATTEN
inline constexpr
auto
116 operator( )( Args &&... args )
const
117 noexcept( std::is_nothrow_constructible_v<std::optional<T>,
118 std::in_place_t, Args...> )
120 ((
sizeof...( Args ) > 0 ) and
121 std::is_constructible_v<T, std::in_place_t, Args...>),
124 return std::optional<T>( std::in_place, std::forward<Args>( args )... );
127 template<
typename... Args>
128 [[nodiscard]] DAW_ATTRIBUTE_FLATTEN
inline constexpr
auto
129 operator( )( Args &&... args )
const
130 noexcept( daw::traits::is_nothrow_list_constructible_v<T, Args...>
131 and std::is_nothrow_move_constructible_v<T> )
133 ((
sizeof...( Args ) > 0 ) and
134 not std::is_constructible_v<T, std::in_place_t, Args...> and
135 daw::traits::is_list_constructible_v<T, Args...>),
138 return std::optional<T>( T{ std::forward<Args>( args )... } );
142 template<
typename T,
typename Deleter>
143 struct nullable_constructor<std::unique_ptr<T, Deleter>> {
144 using value_type = T;
146 constexpr std::unique_ptr<T, Deleter> operator( )( )
const noexcept {
147 return std::unique_ptr<T, Deleter>{ };
150 template<
typename... Args>
151 [[nodiscard]] DAW_ATTRIBUTE_FLATTEN
inline auto
152 operator( )( Args &&... args )
const
153 noexcept( std::is_nothrow_constructible_v<T, Args...> )
154 -> std::enable_if_t<(
sizeof...( Args ) > 0 and
155 std::is_constructible_v<T, Args...>),
156 std::unique_ptr<T, Deleter>> {
158 return std::unique_ptr<T, Deleter>(
159 new T( std::forward<Args>( args )... ) );
162 template<
typename... Args>
163 [[nodiscard]] DAW_ATTRIBUTE_FLATTEN
inline auto
164 operator( )( Args &&... args )
const
165 noexcept( daw::traits::is_nothrow_list_constructible_v<T, Args...> )
166 -> std::enable_if_t<((
sizeof...( Args ) > 0 ) and
167 not std::is_constructible_v<T, Args...> and
168 daw::traits::is_list_constructible_v<T, Args...>),
169 std::unique_ptr<T, Deleter>> {
171 return std::unique_ptr<T, Deleter>(
172 new T{ std::forward<Args>( args )... } );
185 template<
typename Char,
typename CharTrait,
typename Allocator>
187 std::basic_string<Char, CharTrait, Allocator>> : std::true_type {};