@@ -30,35 +30,51 @@ class conv_result
30
30
T value_;
31
31
};
32
32
public:
33
+
34
+ // value constructors
35
+ conv_result (const T& value)
36
+ : has_value_(true )
37
+ {
38
+ construct (value);
39
+ }
40
+
41
+ conv_result (T&& value) noexcept
42
+ : has_value_(true )
43
+ {
44
+ construct (std::move (value));
45
+ }
46
+
33
47
conv_result (std::error_code ec) noexcept
34
48
: has_value_(false ), ec_{ec}
35
49
{
36
50
}
37
51
38
52
// copy constructors
39
53
conv_result (const conv_result<T>& other)
40
- : has_value_(false ), ec_{ other.ec_ }
54
+ : has_value_(other.has_value_)
41
55
{
42
56
if (other)
43
57
{
44
- construct (*other);
58
+ construct (other.value_ );
59
+ }
60
+ else
61
+ {
62
+ ec_ = other.ec_ ;
45
63
}
46
64
}
47
65
48
66
// move constructors
49
- conv_result (conv_result<T>&& other)
50
- : has_value_(false ), ec_{ other.ec_ }
51
- {
67
+ conv_result (conv_result<T>&& other) noexcept
68
+ : has_value_(other.has_value())
69
+ {
52
70
if (other)
53
71
{
54
72
construct (std::move (other.value_ ));
55
73
}
56
- }
57
-
58
- // value constructors
59
- conv_result (T&& value) // (8)
60
- : has_value_(true ), value_(std::move(value))
61
- {
74
+ else
75
+ {
76
+ ec_ = other.ec_ ;
77
+ }
62
78
}
63
79
64
80
~conv_result () noexcept
@@ -74,7 +90,8 @@ class conv_result
74
90
}
75
91
else
76
92
{
77
- reset ();
93
+ destroy ();
94
+ ec_ = other.ec_ ;
78
95
}
79
96
return *this ;
80
97
}
@@ -87,7 +104,8 @@ class conv_result
87
104
}
88
105
else
89
106
{
90
- reset ();
107
+ destroy ();
108
+ ec_ = other.ec_ ;
91
109
}
92
110
return *this ;
93
111
}
@@ -178,17 +196,23 @@ class conv_result
178
196
conv_result& source = contains_a_value ? *this : other;
179
197
conv_result& target = contains_a_value ? other : *this ;
180
198
target = conv_result<T>(*source);
181
- source.reset ();
199
+ source.destroy ();
200
+ source.ec_ = target.ec_ ;
182
201
}
183
202
}
184
203
private:
185
204
constexpr const T& get () const { return this ->value_ ; }
186
205
T& get () { return this ->value_ ; }
187
206
188
- template <typename ... Args>
189
- void construct (Args&&... args)
207
+ void construct (const T& value)
190
208
{
191
- ::new (static_cast <void *>(&this ->value_ )) T (std::forward<Args>(args)...);
209
+ ::new (&value_) T (value);
210
+ has_value_ = true ;
211
+ }
212
+
213
+ void construct (T&& value) noexcept
214
+ {
215
+ ::new (&value_) T (std::move (value));
192
216
has_value_ = true ;
193
217
}
194
218
@@ -221,109 +245,6 @@ swap(conv_result<T>& lhs, conv_result<T>& rhs) noexcept
221
245
lhs.swap (rhs);
222
246
}
223
247
224
- template <class T1 , typename T2>
225
- constexpr bool operator ==(const conv_result<T1>& lhs, const conv_result<T2>& rhs) noexcept
226
- {
227
- return lhs.has_value () == rhs.has_value () && (!lhs.has_value () || *lhs == *rhs);
228
- }
229
-
230
- template <class T1 , typename T2>
231
- constexpr bool operator !=(const conv_result<T1>& lhs, const conv_result<T2>& rhs) noexcept
232
- {
233
- return lhs.has_value () != rhs.has_value () || (lhs.has_value () && *lhs != *rhs);
234
- }
235
-
236
- template <class T1 , typename T2>
237
- constexpr bool operator <(const conv_result<T1>& lhs, const conv_result<T2>& rhs) noexcept
238
- {
239
- return rhs.has_value () && (!lhs.has_value () || *lhs < *rhs);
240
- }
241
-
242
- template <class T1 , typename T2>
243
- constexpr bool operator >(const conv_result<T1>& lhs, const conv_result<T2>& rhs) noexcept
244
- {
245
- return lhs.has_value () && (!rhs.has_value () || *lhs > *rhs);
246
- }
247
-
248
- template <class T1 , typename T2>
249
- constexpr bool operator <=(const conv_result<T1>& lhs, const conv_result<T2>& rhs) noexcept
250
- {
251
- return !lhs.has_value () || (rhs.has_value () && *lhs <= *rhs);
252
- }
253
-
254
- template <class T1 , typename T2>
255
- constexpr bool operator >=(const conv_result<T1>& lhs, const conv_result<T2>& rhs) noexcept
256
- {
257
- return !rhs.has_value () || (lhs.has_value () && *lhs >= *rhs);
258
- }
259
-
260
- template <class T1 , typename T2>
261
- constexpr bool operator ==(const conv_result<T1>& lhs, const T2& rhs) noexcept
262
- {
263
- return lhs ? *lhs == rhs : false ;
264
- }
265
- template <class T1 , typename T2>
266
- constexpr bool operator ==(const T1& lhs, const conv_result<T2>& rhs) noexcept
267
- {
268
- return rhs ? lhs == *rhs : false ;
269
- }
270
-
271
- template <class T1 , typename T2>
272
- constexpr bool operator !=(const conv_result<T1>& lhs, const T2& rhs) noexcept
273
- {
274
- return lhs ? *lhs != rhs : true ;
275
- }
276
- template <class T1 , typename T2>
277
- constexpr bool operator !=(const T1& lhs, const conv_result<T2>& rhs) noexcept
278
- {
279
- return rhs ? lhs != *rhs : true ;
280
- }
281
-
282
- template <class T1 , typename T2>
283
- constexpr bool operator <(const conv_result<T1>& lhs, const T2& rhs) noexcept
284
- {
285
- return lhs ? *lhs < rhs : true ;
286
- }
287
- template <class T1 , typename T2>
288
- constexpr bool operator <(const T1& lhs, const conv_result<T2>& rhs) noexcept
289
- {
290
- return rhs ? lhs < *rhs : false ;
291
- }
292
-
293
- template <class T1 , typename T2>
294
- constexpr bool operator <=(const conv_result<T1>& lhs, const T2& rhs) noexcept
295
- {
296
- return lhs ? *lhs <= rhs : true ;
297
- }
298
- template <class T1 , typename T2>
299
- constexpr bool operator <=(const T1& lhs, const conv_result<T2>& rhs) noexcept
300
- {
301
- return rhs ? lhs <= *rhs : false ;
302
- }
303
-
304
- template <class T1 , typename T2>
305
- constexpr bool operator >(const conv_result<T1>& lhs, const T2& rhs) noexcept
306
- {
307
- return lhs ? *lhs > rhs : false ;
308
- }
309
-
310
- template <class T1 , typename T2>
311
- constexpr bool operator >(const T1& lhs, const conv_result<T2>& rhs) noexcept
312
- {
313
- return rhs ? lhs > *rhs : true ;
314
- }
315
-
316
- template <class T1 , typename T2>
317
- constexpr bool operator >=(const conv_result<T1>& lhs, const T2& rhs) noexcept
318
- {
319
- return lhs ? *lhs >= rhs : false ;
320
- }
321
- template <class T1 , typename T2>
322
- constexpr bool operator >=(const T1& lhs, const conv_result<T2>& rhs) noexcept
323
- {
324
- return rhs ? lhs >= *rhs : true ;
325
- }
326
-
327
248
} // reflect
328
249
} // jsoncons
329
250
0 commit comments