| Home | Libraries | People | FAQ | More

#### Moved-from `optional`

When an optional object that contains a value is moved from (is a source of move constructor or assignment) it still contains a value and its contained value is left in a moved-from state. This can be illustrated with the following example.

    optional<std::unique_ptr<int>> opi {std::make_unique<int>(1)};
    optional<std::unique_ptr<int>> opj = std::move(opi);
    assert (opi);
    assert (*opi == nullptr);

Quite a lot of people expect that when an object that contains a value is moved from, its contained value should be destroyed. This is not so, for performance reasons. Current semantics allow the implementation of `boost::optional<T>` to be trivially copyable when `T` is trivial.