Skip to content

Instantly share code, notes, and snippets.

@vinniefalco
Created October 17, 2019 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinniefalco/23e29719f4d0a54f01f8929c2b86f72d to your computer and use it in GitHub Desktop.
Save vinniefalco/23e29719f4d0a54f01f8929c2b86f72d to your computer and use it in GitHub Desktop.
void
value::
swap(value& other)
{
if(*get_storage() != *other.get_storage())
{
value temp1(
std::move(*this),
other.get_storage());
value temp2(
std::move(other),
this->get_storage());
other.~value();
::new(&other) value(pilfer(temp1));
this->~value();
::new(this) value(pilfer(temp2));
}
else
{
value tmp(pilfer(*this));
this->~value();
::new(this) value(pilfer(other));
other.~value();
::new(&other) value(pilfer(tmp));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment