
Niels Dekker - mail address until 2008-12-31 skrev:
Thorsten Ottosen wrote:
No user expects swap to throw or invalidate iterators or references like the current implementation does.
I do agree that it's a pity that the current implementation of optional::swap might throw an exception. Still, like Andrey Semashev, I'd rather not have it require T to be default constructible. Because I can imagine that people typically use optional<T> for a non-DefaultConstructible T. (A nice thing about boost::optional<T> is that it provides a default constructor, even for those types T that don't have one.)
Right, this is certainly true, but this is not the same as "none of the functions in optional's interface can/should require default constructible".
What would you think of having boost::optional implemented by holding a pointer to T, instead of an aligned_storage object and a m_initialized flag? It would manage the memory that the pointer would point to. Having NULL would indicate being uninitialized. (I admit it's a rather theoretical question, because I don't even know if Fernando would like such an approach...)
Going for a heap based implementation is out of the question for performance reasons. -Thorsten