@@ -77,7 +77,10 @@ class movable_box : public std::optional<t>
7777};
7878
7979template <boxable t>
80- requires std::copyable<t> || (std::is_nothrow_move_constructible_v<t> && std::is_nothrow_copy_constructible_v<t>)
80+ requires std::copyable<t>
81+ || (std::is_copy_constructible_v<t> && std::is_nothrow_move_constructible_v<t>
82+ && std::is_nothrow_copy_constructible_v<t>)
83+ || (!std::is_copy_constructible_v<t> && (std::movable<t> || std::is_nothrow_move_constructible_v<t>))
8184class movable_box <t>
8285{
8386private:
@@ -92,13 +95,39 @@ class movable_box<t>
9295 constexpr movable_box (movable_box &&) = default;
9396 constexpr ~movable_box () = default ;
9497
95- constexpr movable_box & operator =(movable_box const &) = default ;
98+ constexpr movable_box & operator =(movable_box const &)
99+ requires std::copyable<t>
100+ = default ;
96101
97- constexpr movable_box & operator =(movable_box &&) = default ;
102+ constexpr movable_box & operator =(movable_box &&)
103+ requires std::movable<t>
104+ = default ;
98105
99106 constexpr explicit movable_box (t const & other) noexcept (std::is_nothrow_copy_constructible_v<t>) : value{other}
100107 {}
101108
109+ constexpr movable_box & operator =(movable_box const & other) noexcept (std::is_nothrow_copy_constructible_v<t>)
110+ requires (!std::copyable<t> && std::copy_constructible<t>)
111+ {
112+ if (this != std::addressof (other))
113+ {
114+ value.~t ();
115+ std::construct_at (std::addressof (value), other.value );
116+ }
117+ return *this ;
118+ }
119+
120+ constexpr movable_box & operator =(movable_box && other) noexcept (std::is_nothrow_move_constructible_v<t>)
121+ requires (!std::movable<t>)
122+ {
123+ if (this != std::addressof (other))
124+ {
125+ value.~t ();
126+ std::construct_at (std::addressof (value), std::move (other.value ));
127+ }
128+ return *this ;
129+ }
130+
102131 constexpr explicit movable_box (t && other) noexcept (std::is_nothrow_move_constructible_v<t>) :
103132 value{std::move (other)}
104133 {}
0 commit comments