Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions stl/inc/any
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,14 @@ public:

// Assignment [any.assign]
any& operator=(const any& _That) {
_Assign(_That);
any _Tmp = _That;
_Reset_and_move_from(_Tmp);
return *this;
}

any& operator=(any&& _That) noexcept {
_Assign(_STD move(_That));
any _Tmp = _STD move(_That);
_Reset_and_move_from(_Tmp);
return *this;
}

Expand All @@ -190,7 +192,8 @@ public:
int> = 0>
any& operator=(_ValueType&& _Value) {
// replace contained value with an object of type decay_t<_ValueType> initialized from _Value
_Assign(_STD forward<_ValueType>(_Value));
any _Tmp = _STD forward<_ValueType>(_Value);
_Reset_and_move_from(_Tmp);
return *this;
}

Expand Down Expand Up @@ -230,11 +233,9 @@ public:
}

void swap(any& _That) noexcept {
any _Old = _STD move(*this);
reset();
_Move_from(_That);
_That.reset();
_That._Move_from(_Old);
any _Tmp = _STD move(*this);
_Reset_and_move_from(_That);
_That._Reset_and_move_from(_Tmp);
}

// Observers [any.observers]
Expand Down Expand Up @@ -288,6 +289,7 @@ private:
}

void _Move_from(any& _That) noexcept {
_STL_INTERNAL_CHECK(_Storage._TypeData == 0); // !has_value()
_Storage._TypeData = _That._Storage._TypeData;
switch (_Rep()) {
case _Any_representation::_Small:
Expand All @@ -306,13 +308,14 @@ private:
}
}

void _Assign(any _That) noexcept { // intentionally pass by value
void _Reset_and_move_from(any& _That) noexcept {
reset();
_Move_from(_That);
}

template <class _Decayed, class... _Types>
_Decayed& _Emplace(_Types&&... _Args) { // emplace construct _Decayed
_STL_INTERNAL_CHECK(_Storage._TypeData == 0); // !has_value()
if constexpr (_Any_is_trivial<_Decayed>) {
// using the _Trivial representation
auto& _Obj = reinterpret_cast<_Decayed&>(_Storage._TrivialData);
Expand Down