@@ -291,7 +291,8 @@ concept enable_assign_from_other =
291
291
292
292
template <class T >
293
293
class optional {
294
- static_assert ((!std::is_same_v<T, std::remove_cv_t <in_place_t >>) && (!std::is_same_v<std::remove_cv_t <T>, nullopt_t >));
294
+ static_assert ((!std::is_same_v<T, std::remove_cv_t <in_place_t >>) &&
295
+ (!std::is_same_v<std::remove_cv_t <T>, nullopt_t >));
295
296
296
297
struct empty {};
297
298
union {
@@ -317,8 +318,7 @@ class optional {
317
318
using iterator = detail::contiguous_iterator<T, optional>; // see [optional.iterators]
318
319
using const_iterator = detail::contiguous_iterator<const T, optional>; // see [optional.iterators]
319
320
320
- constexpr optional () noexcept
321
- : _(), engaged_(false ) {}
321
+ constexpr optional () noexcept : _(), engaged_(false ) {}
322
322
323
323
constexpr ~optional ()
324
324
requires (!std::is_trivially_destructible_v<T>)
@@ -477,15 +477,13 @@ class optional {
477
477
478
478
// / Returns the stored value if there is one, otherwise returns `u`
479
479
template <class U >
480
- constexpr T value_or (U&& u) const &
481
- {
480
+ constexpr T value_or (U&& u) const & {
482
481
static_assert (std::is_copy_constructible_v<T> && std::is_convertible_v<U&&, T>);
483
482
return has_value () ? value () : static_cast <T>(std::forward<U>(u));
484
483
}
485
484
486
485
template <class U >
487
- constexpr T value_or (U&& u) &&
488
- {
486
+ constexpr T value_or (U&& u) && {
489
487
static_assert (std::is_move_constructible_v<T> && std::is_convertible_v<U&&, T>);
490
488
return has_value () ? std::move (value ()) : static_cast <T>(std::forward<U>(u));
491
489
}
@@ -541,7 +539,7 @@ class optional {
541
539
static_assert (!std::is_array_v<U>);
542
540
static_assert (!std::is_same_v<U, in_place_t >);
543
541
static_assert (!std::is_same_v<U, nullopt_t >);
544
- static_assert (std::is_object_v<U> || std::is_reference_v<U> ); // / References now allowed
542
+ static_assert (std::is_object_v<U> || std::is_reference_v<U>); // / References now allowed
545
543
return (has_value ()) ? optional<U>{std::invoke (std::forward<F>(f), value_)} : optional<U>{};
546
544
}
547
545
@@ -551,7 +549,7 @@ class optional {
551
549
static_assert (!std::is_array_v<U>);
552
550
static_assert (!std::is_same_v<U, in_place_t >);
553
551
static_assert (!std::is_same_v<U, nullopt_t >);
554
- static_assert (std::is_object_v<U> || std::is_reference_v<U> ); // / References now allowed
552
+ static_assert (std::is_object_v<U> || std::is_reference_v<U>); // / References now allowed
555
553
return (has_value ()) ? optional<U>{std::invoke (std::forward<F>(f), std::move (value_))} : optional<U>{};
556
554
}
557
555
@@ -561,7 +559,7 @@ class optional {
561
559
static_assert (!std::is_array_v<U>);
562
560
static_assert (!std::is_same_v<U, in_place_t >);
563
561
static_assert (!std::is_same_v<U, nullopt_t >);
564
- static_assert (std::is_object_v<U> || std::is_reference_v<U> ); // / References now allowed
562
+ static_assert (std::is_object_v<U> || std::is_reference_v<U>); // / References now allowed
565
563
return (has_value ()) ? optional<U>{std::invoke (std::forward<F>(f), value_)} : optional<U>{};
566
564
}
567
565
@@ -571,7 +569,7 @@ class optional {
571
569
static_assert (!std::is_array_v<U>);
572
570
static_assert (!std::is_same_v<U, in_place_t >);
573
571
static_assert (!std::is_same_v<U, nullopt_t >);
574
- static_assert (std::is_object_v<U> || std::is_reference_v<U> ); // / References now allowed
572
+ static_assert (std::is_object_v<U> || std::is_reference_v<U>); // / References now allowed
575
573
return (has_value ()) ? optional<U>{std::invoke (std::forward<F>(f), value_)} : optional<U>{};
576
574
}
577
575
@@ -658,17 +656,15 @@ class optional {
658
656
// / Constructs the value in-place, destroying the current one if there is
659
657
// / one.
660
658
template <class ... Args>
661
- constexpr T& emplace (Args&&... args)
662
- {
659
+ constexpr T& emplace (Args&&... args) {
663
660
static_assert (std::is_constructible_v<T, Args&&...>);
664
661
*this = nullopt ;
665
662
construct (std::forward<Args>(args)...);
666
663
return value ();
667
664
}
668
665
669
666
template <class U , class ... Args>
670
- constexpr T& emplace (std::initializer_list<U> il, Args&&... args)
671
- {
667
+ constexpr T& emplace (std::initializer_list<U> il, Args&&... args) {
672
668
static_assert (std::is_constructible_v<T, std::initializer_list<U>&, Args&&...>);
673
669
*this = nullopt ;
674
670
construct (il, std::forward<Args>(args)...);
@@ -1086,7 +1082,7 @@ class optional<T&> {
1086
1082
}
1087
1083
1088
1084
template <class U >
1089
- constexpr optional& operator =(optional<U>&& rhs) = delete ;
1085
+ constexpr optional& operator =(optional<U>&& rhs) = delete ;
1090
1086
1091
1087
template <class U >
1092
1088
requires (!detail::is_optional<std::decay_t <U>>)
0 commit comments