
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.) 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...) Kind regards, -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center