@@ -288,7 +288,8 @@ concept enable_assign_from_other =
288
288
template <class T >
289
289
class optional {
290
290
static_assert ((!std::is_same_v<T, std::remove_cv_t <in_place_t >>) &&
291
- (!std::is_same_v<std::remove_cv_t <T>, nullopt_t >));
291
+ (!std::is_same_v<std::remove_cv_t <T>, nullopt_t >),
292
+ " T must not be in_place_t or nullopt_t" );
292
293
293
294
struct empty {};
294
295
union {
@@ -487,7 +488,7 @@ class optional {
487
488
template <class F >
488
489
constexpr auto and_then (F&& f) & {
489
490
using U = std::invoke_result_t <F, T&>;
490
- static_assert (detail::is_optional<std::remove_cvref_t <U>>);
491
+ static_assert (detail::is_optional<std::remove_cvref_t <U>>, " F must return an optional " );
491
492
if (has_value ()) {
492
493
return std::invoke (std::forward<F>(f), value_);
493
494
} else {
@@ -498,7 +499,7 @@ class optional {
498
499
template <class F >
499
500
constexpr auto and_then (F&& f) && {
500
501
using U = std::invoke_result_t <F, T&&>;
501
- static_assert (detail::is_optional<std::remove_cvref_t <U>>);
502
+ static_assert (detail::is_optional<std::remove_cvref_t <U>>, " F must return an optional " );
502
503
if (has_value ()) {
503
504
return std::invoke (std::forward<F>(f), std::move (value_));
504
505
} else {
@@ -509,7 +510,7 @@ class optional {
509
510
template <class F >
510
511
constexpr auto and_then (F&& f) const & {
511
512
using U = std::invoke_result_t <F, const T&>;
512
- static_assert (detail::is_optional<std::remove_cvref_t <U>>);
513
+ static_assert (detail::is_optional<std::remove_cvref_t <U>>, " F must return an optional " );
513
514
if (has_value ()) {
514
515
return std::invoke (std::forward<F>(f), value_);
515
516
} else {
@@ -520,7 +521,7 @@ class optional {
520
521
template <class F >
521
522
constexpr auto and_then (F&& f) const && {
522
523
using U = std::invoke_result_t <F, const T&&>;
523
- static_assert (detail::is_optional<std::remove_cvref_t <U>>);
524
+ static_assert (detail::is_optional<std::remove_cvref_t <U>>, " F must return an optional " );
524
525
if (has_value ()) {
525
526
return std::invoke (std::forward<F>(f), std::move (value_));
526
527
} else {
@@ -532,40 +533,44 @@ class optional {
532
533
template <class F >
533
534
constexpr auto transform (F&& f) & {
534
535
using U = std::invoke_result_t <F, T&>;
535
- static_assert (!std::is_array_v<U>);
536
- static_assert (!std::is_same_v<U, in_place_t >);
537
- static_assert (!std::is_same_v<U, nullopt_t >);
538
- static_assert (std::is_object_v<U> || std::is_reference_v<U>); // / References now allowed
536
+ static_assert (!std::is_array_v<U>, " U must not be an array" );
537
+ static_assert (!std::is_same_v<U, in_place_t >, " U must not be an inplace type" );
538
+ static_assert (!std::is_same_v<U, nullopt_t >, " U must not be nullopt_t" );
539
+ static_assert (std::is_object_v<U> || std::is_reference_v<U>,
540
+ " U must be either an object or a reference" ); // / References now allowed
539
541
return (has_value ()) ? optional<U>{std::invoke (std::forward<F>(f), value_)} : optional<U>{};
540
542
}
541
543
542
544
template <class F >
543
545
constexpr auto transform (F&& f) && {
544
546
using U = std::invoke_result_t <F, T&&>;
545
- static_assert (!std::is_array_v<U>);
546
- static_assert (!std::is_same_v<U, in_place_t >);
547
- static_assert (!std::is_same_v<U, nullopt_t >);
548
- static_assert (std::is_object_v<U> || std::is_reference_v<U>); // / References now allowed
547
+ static_assert (!std::is_array_v<U>, " U must not be an array" );
548
+ static_assert (!std::is_same_v<U, in_place_t >, " U must not be an inplace type" );
549
+ static_assert (!std::is_same_v<U, nullopt_t >, " U must not be nullopt_t type" );
550
+ static_assert (std::is_object_v<U> || std::is_reference_v<U>,
551
+ " U must be either an objecy or a reference" ); // / References now allowed
549
552
return (has_value ()) ? optional<U>{std::invoke (std::forward<F>(f), std::move (value_))} : optional<U>{};
550
553
}
551
554
552
555
template <class F >
553
556
constexpr auto transform (F&& f) const & {
554
557
using U = std::invoke_result_t <F, const T&>;
555
- static_assert (!std::is_array_v<U>);
556
- static_assert (!std::is_same_v<U, in_place_t >);
557
- static_assert (!std::is_same_v<U, nullopt_t >);
558
- static_assert (std::is_object_v<U> || std::is_reference_v<U>); // / References now allowed
558
+ static_assert (!std::is_array_v<U>, " U must not be an array" );
559
+ static_assert (!std::is_same_v<U, in_place_t >, " U must not be an inplace type" );
560
+ static_assert (!std::is_same_v<U, nullopt_t >, " U must not be nullopt_t type" );
561
+ static_assert (std::is_object_v<U> || std::is_reference_v<U>,
562
+ " U must be either an objecy or a reference" ); // / References now allowed
559
563
return (has_value ()) ? optional<U>{std::invoke (std::forward<F>(f), value_)} : optional<U>{};
560
564
}
561
565
562
566
template <class F >
563
567
constexpr auto transform (F&& f) const && {
564
568
using U = std::invoke_result_t <F, const T&>;
565
- static_assert (!std::is_array_v<U>);
566
- static_assert (!std::is_same_v<U, in_place_t >);
567
- static_assert (!std::is_same_v<U, nullopt_t >);
568
- static_assert (std::is_object_v<U> || std::is_reference_v<U>); // / References now allowed
569
+ static_assert (!std::is_array_v<U>, " U must not be an array" );
570
+ static_assert (!std::is_same_v<U, in_place_t >, " U must not be an inplace type" );
571
+ static_assert (!std::is_same_v<U, nullopt_t >, " U must not be nullopt_t type" );
572
+ static_assert (std::is_object_v<U> || std::is_reference_v<U>,
573
+ " U must be either an objecy or a reference" ); // / References now allowed
569
574
return (has_value ()) ? optional<U>{std::invoke (std::forward<F>(f), value_)} : optional<U>{};
570
575
}
571
576
@@ -653,7 +658,7 @@ class optional {
653
658
// / one.
654
659
template <class ... Args>
655
660
constexpr T& emplace (Args&&... args) {
656
- static_assert (std::is_constructible_v<T, Args&&...>);
661
+ static_assert (std::is_constructible_v<T, Args&&...>, " each parameter pack must be constructible to T " );
657
662
*this = nullopt ;
658
663
construct (std::forward<Args>(args)...);
659
664
return value ();
@@ -675,7 +680,7 @@ class optional {
675
680
// / valueless.
676
681
constexpr void swap (optional& rhs) noexcept (std::is_nothrow_move_constructible<T>::value &&
677
682
std::is_nothrow_swappable<T>::value) {
678
- static_assert (std::is_move_constructible_v<T>);
683
+ static_assert (std::is_move_constructible_v<T>, " T must be move-constructible " );
679
684
using std::swap;
680
685
if (has_value ()) {
681
686
if (rhs.has_value ()) {
@@ -1138,7 +1143,7 @@ class optional<T&> {
1138
1143
template <class F >
1139
1144
constexpr optional or_else (F&& f) const {
1140
1145
using U = std::invoke_result_t <F>;
1141
- static_assert (std::is_same_v<std::remove_cvref_t <U>, optional>);
1146
+ static_assert (std::is_same_v<std::remove_cvref_t <U>, optional>, " F must return an optional " );
1142
1147
return has_value () ? *value_ : std::forward<F>(f)();
1143
1148
}
1144
1149
0 commit comments