File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
src/beman/optional26/tests Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -299,6 +299,8 @@ class optional {
299299 requires (!std::is_trivially_destructible_v<T>);
300300
301301 // \ref{optional.assign}, assignment
302+ constexpr optional& operator =(nullopt_t ) noexcept ;
303+
302304 constexpr optional& operator =(const optional& rhs)
303305 requires std::is_copy_constructible_v<T> && std::is_copy_assignable_v<T> &&
304306 (!std::is_trivially_copy_assignable_v<T>);
@@ -514,6 +516,12 @@ inline constexpr optional<T>::~optional()
514516
515517// 22.5.3.4 Assignment[optional.assign]
516518
519+ template <class T >
520+ inline constexpr optional<T>& optional<T>::operator =(nullopt_t ) noexcept {
521+ reset ();
522+ return *this ;
523+ }
524+
517525template <class T >
518526inline constexpr optional<T>& optional<T>::operator =(const optional<T>& rhs)
519527 requires std::is_copy_constructible_v<T> && std::is_copy_assignable_v<T> &&
Original file line number Diff line number Diff line change @@ -868,3 +868,23 @@ TEST(OptionalTest, HashTest) {
868868 EXPECT_EQ (h1, h2);
869869 }
870870}
871+
872+ TEST (OptionalTest, CanHoldValueOfImmovableType) {
873+ struct immovable {
874+ explicit immovable () = default;
875+ immovable (const immovable&) = delete ;
876+ immovable& operator =(const immovable&) = delete ;
877+ };
878+
879+ beman::optional26::optional<immovable> o1 (beman::optional26::in_place);
880+ EXPECT_TRUE (o1);
881+
882+ // ...and can reset it with `nullopt`.
883+ static_assert (noexcept (o1 = beman::optional26::nullopt ));
884+ o1 = beman::optional26::nullopt ;
885+ EXPECT_FALSE (o1);
886+
887+ // Also, can construct with `nullopt`.
888+ beman::optional26::optional<immovable> o2 = beman::optional26::nullopt ;
889+ EXPECT_FALSE (o2);
890+ }
You can’t perform that action at this time.
0 commit comments