67
67
#include < optional>
68
68
#include < stdexcept>
69
69
#include < type_traits>
70
+
70
71
#include " smf_control.hpp"
71
72
72
73
template <class T >
@@ -85,15 +86,15 @@ union unsafe_optional_data {
85
86
constexpr unsafe_optional_data () noexcept : uninitialized () {}
86
87
template <class ... Args>
87
88
constexpr explicit unsafe_optional_data (std::in_place_t , Args&&... args)
88
- : val (std::forward <Args>(args)...) {}
89
+ : val (static_cast <Args&& >(args)...) {}
89
90
~unsafe_optional_data () = default ;
90
91
};
91
92
92
93
// The partial specialization is the same as the primary template except
93
94
// that the destructor is explicitly defined.
94
95
template <class T >
95
96
union unsafe_optional_data<T,
96
- std::enable_if_t <!std::is_trivially_destructible <T>{}() >
97
+ std::enable_if_t <!std::is_trivially_destructible_v <T>>
97
98
> {
98
99
friend unsafe_optional_impl<T>;
99
100
private:
@@ -103,7 +104,7 @@ union unsafe_optional_data<T,
103
104
constexpr unsafe_optional_data () noexcept : uninitialized () {}
104
105
template <class ... Args>
105
106
constexpr explicit unsafe_optional_data (std::in_place_t , Args&&... args)
106
- : val (std::forward <Args>(args)...) {}
107
+ : val (static_cast <Args&& >(args)...) {}
107
108
~unsafe_optional_data () {}
108
109
};
109
110
@@ -148,31 +149,31 @@ class unsafe_optional_impl {
148
149
constexpr unsafe_optional_impl (T&& v) : data(std::in_place, std::move(v)) {}
149
150
template <class ... Args>
150
151
constexpr explicit unsafe_optional_impl (std::in_place_t , Args&&... args)
151
- : data(std::in_place, std::forward <Args>(args)...) {}
152
+ : data(std::in_place, static_cast <Args&& >(args)...) {}
152
153
template <class U , class ... Args,
153
154
std::enable_if_t <
154
- std::is_constructible <T,std::initializer_list<U>&,Args&&...>{}() ,
155
+ std::is_constructible_v <T,std::initializer_list<U>&,Args&&...>,
155
156
int > = 0
156
157
>
157
158
constexpr explicit unsafe_optional_impl (
158
159
std::in_place_t , std::initializer_list<U> il, Args&&... args
159
160
)
160
- : data(std::in_place, il, std::forward <Args>(args)...) {}
161
+ : data(std::in_place, il, static_cast <Args&& >(args)...) {}
161
162
162
163
~unsafe_optional_impl () = default ;
163
164
164
165
unsafe_optional_impl& operator =(unsafe_optional_impl const &) = default ;
165
166
unsafe_optional_impl& operator =(unsafe_optional_impl&&) = default ;
166
167
167
168
template <class ... Args>
168
- void emplace (Args&&... args) {
169
- ::new (static_cast <void *>(std::addressof (data.val )))
170
- T (std::forward <Args>(args)...);
169
+ T& emplace (Args&&... args) {
170
+ return * ::new (static_cast <void *>(std::addressof (data.val )))
171
+ T (static_cast <Args&& >(args)...);
171
172
}
172
173
template <class U , class ... Args>
173
- void emplace (std::initializer_list<U> il, Args&&... args) {
174
- ::new (static_cast <void *>(std::addressof (data.val )))
175
- T (il, std::forward <Args>(args)...);
174
+ T& emplace (std::initializer_list<U> il, Args&&... args) {
175
+ return * ::new (static_cast <void *>(std::addressof (data.val )))
176
+ T (il, static_cast <Args&& >(args)...);
176
177
}
177
178
178
179
constexpr T const & value () const & noexcept { return data.val ; }
@@ -187,19 +188,19 @@ class unsafe_optional_impl {
187
188
188
189
template <class T >
189
190
class unsafe_optional : public
190
- delete_copy_ctor_if<!std::is_trivially_copy_constructible <T>{}() ,
191
- default_move_ctor_if<std::is_trivially_copy_constructible <T>{}() ,
192
- delete_copy_assign_if<!std::is_trivially_copy_assignable <T>{}() ,
193
- delete_move_assign_if<!std::is_trivially_move_assignable <T>{}() ,
191
+ delete_copy_ctor_if<!std::is_trivially_copy_constructible_v <T>,
192
+ default_move_ctor_if<std::is_trivially_copy_constructible_v <T>,
193
+ delete_copy_assign_if<!std::is_trivially_copy_assignable_v <T>,
194
+ delete_move_assign_if<!std::is_trivially_move_assignable_v <T>,
194
195
unsafe_optional_impl<T>
195
196
>>>> {
196
197
static_assert (sizeof (unsafe_optional_data<T>) == sizeof (T),
197
198
" The wrapper has unintended space overhead." );
198
199
static_assert (alignof (unsafe_optional_data<T>) == alignof (T),
199
200
" The wrapper has a different alignment from the wrapped type." );
200
- static_assert (!std::is_reference <T>{}() , " T cannot be a reference type." );
201
+ static_assert (!std::is_reference_v <T>, " T cannot be a reference type." );
201
202
// unsafe_optional_impl<unsafe_optional_impl> is quite useless.
202
- static_assert (!is_unsafe_optional <std::remove_cv_t <T>>{}() ,
203
+ static_assert (!is_unsafe_optional_v <std::remove_cv_t <T>>,
203
204
" T cannot be a unsafe_optional_impl." );
204
205
// unsafe_optional<std::in_place_t> and unsafe_optional<std::nullopt_t>
205
206
// are not disabled, but they may be a bit tricky to use.
@@ -211,17 +212,17 @@ class unsafe_optional : public
211
212
212
213
template <class T >
213
214
constexpr unsafe_optional<std::decay_t <T>> make_unsafe_optional (T&& v) {
214
- return unsafe_optional<std::decay_t <T>>(std::forward<T >(v));
215
+ return unsafe_optional<std::decay_t <T>>(static_cast <T&& >(v));
215
216
}
216
217
217
218
template <class T , class ...Args>
218
219
constexpr unsafe_optional<T> make_unsafe_optional (Args&&... args) {
219
- return unsafe_optional<T>(std::in_place, std::forward <Args>(args)...);
220
+ return unsafe_optional<T>(std::in_place, static_cast <Args&& >(args)...);
220
221
}
221
222
222
223
template <class T , class U , class ... Args>
223
224
constexpr unsafe_optional<T> make_unsafe_optional (
224
225
std::initializer_list<U> il, Args&&... args
225
226
) {
226
- return unsafe_optional<T>(std::in_place, il, std::forward <Args>(args)...);
227
+ return unsafe_optional<T>(std::in_place, il, static_cast <Args&& >(args)...);
227
228
}
0 commit comments