"Fernando Cacciola" <[EMAIL PROTECTED]> writes:

> Currently, the non-POD case implementation goes like this:
>
> (this is a sketch actually)
>
> template<class T>
> class optional1
> {
>   optional1 ( T const& v ) { p = new (buffer.address()) T(v) ; }
>
>   T const& operator *() { return *p; } // Dereference here
>
>   aligned_storage<T> buffer ;
>   T* p ;
> }  ;

There's no need to store p. You can just use
static_cast<T*>(buffer.address())

> OTOH, when T is a POD, so there is no need to bypass its ctor
> (since it has a trivial ctor),
> the implementation goes like this:
>
> template<class T>
> class optional2
> {
>   optional2 ( T const& val ) v(val) {}
>
>   T const& operator *() { return val; } // No Dereference here
>
>   T val ;
> } ;
>
> Anyway, if yoy know how to make an efficient implementation like
> the second one with an aligned storage I'll be happy to use it.

Why do you think that will be any more efficient than the other
implementation when T is POD?

-- 
                       David Abrahams
   [EMAIL PROTECTED] * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to