@@ -43,11 +43,9 @@ namespace detail {
43
43
44
44
// Trait for checking if a type is a cargo::expected
45
45
template <class T >
46
- struct is_expected_impl : std::false_type {} ;
46
+ static constexpr bool is_expected_v = false ;
47
47
template <class T , class E >
48
- struct is_expected_impl <expected<T, E>> : std::true_type {};
49
- template <class T >
50
- using is_expected = is_expected_impl<std::decay_t <T>>;
48
+ static constexpr bool is_expected_v<expected<T, E>> = true ;
51
49
52
50
template <class T , class E , class U >
53
51
using expected_enable_forward_value =
@@ -69,16 +67,13 @@ using expected_enable_from_other =
69
67
!std::is_convertible_v<const expected<U, G> &, T> &&
70
68
!std::is_convertible_v<const expected<U, G> &&, T>>;
71
69
72
- template <class T , class U >
73
- using is_void_or = std::conditional_t <std::is_void_v<T>, std::true_type, U>;
74
-
75
70
template <class T >
76
- using is_copy_constructible_or_void =
77
- is_void_or<T, std::is_copy_constructible<T> >;
71
+ static constexpr bool is_copy_constructible_or_void_v =
72
+ std::is_void_v<T> || std::is_copy_constructible_v<T >;
78
73
79
74
template <class T >
80
- using is_move_constructible_or_void =
81
- is_void_or<T, std::is_move_constructible<T> >;
75
+ static constexpr bool is_move_constructible_or_void_v =
76
+ std::is_void_v<T> || std::is_move_constructible_v<T >;
82
77
83
78
struct no_init_t {};
84
79
static constexpr no_init_t no_init{};
@@ -95,9 +90,11 @@ struct expected_storage_base {
95
90
constexpr expected_storage_base () : m_val(T{}), m_has_val(true ) {}
96
91
constexpr expected_storage_base (no_init_t ) : m_no_init(), m_has_val(false ) {}
97
92
93
+ // NOLINTBEGIN(modernize-type-traits)
98
94
template <
99
95
class ... Args,
100
96
std::enable_if_t <std::is_constructible_v<T, Args &&...>> * = nullptr >
97
+ // NOLINTEND(modernize-type-traits)
101
98
constexpr expected_storage_base (in_place_t , Args &&...args)
102
99
: m_val(std::forward<Args>(args)...), m_has_val(true ) {}
103
100
@@ -143,9 +140,11 @@ struct expected_storage_base<T, E, true, true> {
143
140
constexpr expected_storage_base () : m_val(T{}), m_has_val(true ) {}
144
141
constexpr expected_storage_base (no_init_t ) : m_no_init(), m_has_val(false ) {}
145
142
143
+ // NOLINTBEGIN(modernize-type-traits)
146
144
template <
147
145
class ... Args,
148
146
std::enable_if_t <std::is_constructible_v<T, Args &&...>> * = nullptr >
147
+ // NOLINTEND(modernize-type-traits)
149
148
constexpr expected_storage_base (in_place_t , Args &&...args)
150
149
: m_val(std::forward<Args>(args)...), m_has_val(true ) {}
151
150
@@ -184,9 +183,11 @@ struct expected_storage_base<T, E, true, false> {
184
183
constexpr expected_storage_base () : m_val(T{}), m_has_val(true ) {}
185
184
constexpr expected_storage_base (no_init_t ) : m_no_init(), m_has_val(false ) {}
186
185
186
+ // NOLINTBEGIN(modernize-type-traits)
187
187
template <
188
188
class ... Args,
189
189
std::enable_if_t <std::is_constructible_v<T, Args &&...>> * = nullptr >
190
+ // NOLINTEND(modernize-type-traits)
190
191
constexpr expected_storage_base (in_place_t , Args &&...args)
191
192
: m_val(std::forward<Args>(args)...), m_has_val(true ) {}
192
193
@@ -230,9 +231,11 @@ struct expected_storage_base<T, E, false, true> {
230
231
constexpr expected_storage_base () : m_val(T{}), m_has_val(true ) {}
231
232
constexpr expected_storage_base (no_init_t ) : m_no_init(), m_has_val(false ) {}
232
233
234
+ // NOLINTBEGIN(modernize-type-traits)
233
235
template <
234
236
class ... Args,
235
237
std::enable_if_t <std::is_constructible_v<T, Args &&...>> * = nullptr >
238
+ // NOLINTEND(modernize-type-traits)
236
239
constexpr expected_storage_base (in_place_t , Args &&...args)
237
240
: m_val(std::forward<Args>(args)...), m_has_val(true ) {}
238
241
@@ -342,19 +345,21 @@ struct expected_operations_base : expected_storage_base<T, E> {
342
345
343
346
template <class ... Args>
344
347
void construct (Args &&...args) noexcept {
345
- new (std::addressof (this ->m_val )) T (std::forward<Args>(args)...);
348
+ new (static_cast <void *>(std::addressof (this ->m_val )))
349
+ T (std::forward<Args>(args)...);
346
350
this ->m_has_val = true ;
347
351
}
348
352
349
353
template <class Rhs >
350
354
void construct_with (Rhs &&rhs) noexcept {
351
- new (std::addressof (this ->m_val )) T (std::forward<Rhs>(rhs).get ());
355
+ new (static_cast <void *>(std::addressof (this ->m_val )))
356
+ T (std::forward<Rhs>(rhs).get ());
352
357
this ->m_has_val = true ;
353
358
}
354
359
355
360
template <class ... Args>
356
361
void construct_error (Args &&...args) noexcept {
357
- new (std::addressof (this ->m_unexpect ))
362
+ new (static_cast < void *>( std::addressof (this ->m_unexpect ) ))
358
363
unexpected<E>(std::forward<Args>(args)...);
359
364
this ->m_has_val = false ;
360
365
}
@@ -429,7 +434,7 @@ struct expected_operations_base<void, E> : expected_storage_base<void, E> {
429
434
430
435
template <class ... Args>
431
436
void construct_error (Args &&...args) noexcept {
432
- new (std::addressof (this ->m_unexpect ))
437
+ new (static_cast < void *>( std::addressof (this ->m_unexpect ) ))
433
438
unexpected<E>(std::forward<Args>(args)...);
434
439
this ->m_has_val = false ;
435
440
}
@@ -463,9 +468,9 @@ struct expected_operations_base<void, E> : expected_storage_base<void, E> {
463
468
// This class manages conditionally having a trivial copy constructor
464
469
// This specialization is for when T and E are trivially copy constructible
465
470
template <class T , class E ,
466
- bool =
467
- is_void_or<T, std::is_trivially_copy_constructible <T>>::value &&
468
- std::is_trivially_copy_constructible_v<E>>
471
+ bool = (std::is_void_v<T> ||
472
+ std::is_trivially_copy_constructible_v <T>) &&
473
+ std::is_trivially_copy_constructible_v<E>>
469
474
struct expected_copy_base : expected_operations_base<T, E> {
470
475
using expected_operations_base<T, E>::expected_operations_base;
471
476
};
@@ -492,9 +497,9 @@ struct expected_copy_base<T, E, false> : expected_operations_base<T, E> {
492
497
493
498
// This class manages conditionally having a trivial move constructor
494
499
template <class T , class E ,
495
- bool =
496
- is_void_or<T, std::is_trivially_move_constructible <T>>::value &&
497
- std::is_trivially_move_constructible_v<E>>
500
+ bool = (std::is_void_v<T> ||
501
+ std::is_trivially_move_constructible_v <T>) &&
502
+ std::is_trivially_move_constructible_v<E>>
498
503
struct expected_move_base : expected_copy_base<T, E> {
499
504
using expected_copy_base<T, E>::expected_copy_base;
500
505
};
@@ -519,15 +524,14 @@ struct expected_move_base<T, E, false> : expected_copy_base<T, E> {
519
524
};
520
525
521
526
// This class manages conditionally having a trivial copy assignment operator
522
- template <
523
- class T , class E ,
524
- bool =
525
- is_void_or<T, conjunction<std::is_trivially_copy_assignable<T>,
526
- std::is_trivially_copy_constructible<T>,
527
- std::is_trivially_destructible<T>>>::value &&
528
- std::is_trivially_copy_assignable_v<E> &&
529
- std::is_trivially_copy_constructible_v<E> &&
530
- std::is_trivially_destructible_v<E>>
527
+ template <class T , class E ,
528
+ bool = (std::is_void_v<T> ||
529
+ (std::is_trivially_copy_assignable_v<T> &&
530
+ std::is_trivially_copy_constructible_v<T> &&
531
+ std::is_trivially_destructible_v<T>)) &&
532
+ std::is_trivially_copy_assignable_v<E> &&
533
+ std::is_trivially_copy_constructible_v<E> &&
534
+ std::is_trivially_destructible_v<E>>
531
535
struct expected_copy_assign_base : expected_move_base<T, E> {
532
536
using expected_move_base<T, E>::expected_move_base;
533
537
};
@@ -549,15 +553,14 @@ struct expected_copy_assign_base<T, E, false> : expected_move_base<T, E> {
549
553
};
550
554
551
555
// This class manages conditionally having a trivial move assignment operator
552
- template <
553
- class T , class E ,
554
- bool = is_void_or<
555
- T, conjunction<std::is_trivially_destructible<T>,
556
- std::is_trivially_move_constructible<T>,
557
- std::is_trivially_move_assignable<T>>>::value &&
558
- std::is_trivially_destructible_v<E> &&
559
- std::is_trivially_move_constructible_v<E> &&
560
- std::is_trivially_move_assignable_v<E>>
556
+ template <class T , class E ,
557
+ bool = (std::is_void_v<T> ||
558
+ (std::is_trivially_destructible_v<T> &&
559
+ std::is_trivially_move_constructible_v<T> &&
560
+ std::is_trivially_move_assignable_v<T>)) &&
561
+ std::is_trivially_destructible_v<E> &&
562
+ std::is_trivially_move_constructible_v<E> &&
563
+ std::is_trivially_move_assignable_v<E>>
561
564
struct expected_move_assign_base : expected_copy_assign_base<T, E> {
562
565
using expected_copy_assign_base<T, E>::expected_copy_assign_base;
563
566
};
0 commit comments