Option: Simplify release_value
This avoids copying + we don't need to destroy the item if we move it, since it either gets emptied by moving it or doesn't have anything to destroy.
This commit is contained in:
parent
19a4e2ab58
commit
32c8869973
@ -50,10 +50,8 @@ template <typename T> class Option
|
||||
T release_value()
|
||||
{
|
||||
expect(has_value(), "Option::release_value called on an empty Option");
|
||||
T item = m_storage.fetch_reference();
|
||||
m_has_value = false;
|
||||
m_storage.destroy();
|
||||
return move(item);
|
||||
return move(m_storage.fetch_reference());
|
||||
}
|
||||
|
||||
T value_or(const T& other) const
|
||||
|
Loading…
Reference in New Issue
Block a user