File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed
src/beman/optional26/tests Expand file tree Collapse file tree 3 files changed +30
-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>);
@@ -511,6 +513,12 @@ inline constexpr optional<T>::~optional()
511513
512514// 22.5.3.4 Assignment[optional.assign]
513515
516+ template <class T >
517+ inline constexpr optional<T>& optional<T>::operator =(nullopt_t ) noexcept {
518+ reset ();
519+ return *this ;
520+ }
521+
514522template <class T >
515523inline constexpr optional<T>& optional<T>::operator =(const optional<T>& rhs)
516524 requires std::is_copy_constructible_v<T> && std::is_copy_assignable_v<T> &&
Original file line number Diff line number Diff line change @@ -898,3 +898,19 @@ TEST(OptionalTest, HashTest) {
898898 EXPECT_EQ (h1, h2);
899899 }
900900}
901+
902+ TEST (OptionalTest, CanHoldValueOfImmovableType) {
903+ using beman::optional26::tests::immovable;
904+
905+ beman::optional26::optional<immovable> o1 (beman::optional26::in_place);
906+ EXPECT_TRUE (o1);
907+
908+ // ...and can reset it with `nullopt`.
909+ static_assert (noexcept (o1 = beman::optional26::nullopt ));
910+ o1 = beman::optional26::nullopt ;
911+ EXPECT_FALSE (o1);
912+
913+ // Also, can construct with `nullopt`.
914+ beman::optional26::optional<immovable> o2 = beman::optional26::nullopt ;
915+ EXPECT_FALSE (o2);
916+ }
Original file line number Diff line number Diff line change @@ -65,6 +65,12 @@ class Point {
6565 bool operator ==(const Point&) const = default ;
6666};
6767
68+ struct immovable {
69+ explicit immovable () = default;
70+ immovable (const immovable&) = delete ;
71+ immovable& operator =(const immovable&) = delete ;
72+ };
73+
6874} // namespace beman::optional26::tests
6975
7076#endif // BEMAN_OPTIONAL26_TESTS_TEST_TYPES_HPP
You can’t perform that action at this time.
0 commit comments