Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2002-12-11 13:23:58


----- Original Message -----
From: "David Abrahams" <dave_at_[hidden]>
To: "Boost mailing list" <boost_at_[hidden]>
Sent: Wednesday, December 11, 2002 12:46 PM
Subject: Re: [boost] Formal review: Optional library

> "Fernando Cacciola" <fernando_cacciola_at_[hidden]> writes:
>
> Why do you think aligned_storage<T> will be any less-efficient than T
> when T is a POD?
>
> > If you still don't see it I can show you the typical machine
> > generated code for both implementations for operator*().
>
> I'm not surprised the non-POD version is slower as long as you're
> storing a separate pointer. If you use the static_cast form I show
> above, there's no reason for it to be any worse, AFAICT.
>
Well, I actually changed the implementation of pointer_based_optional<>
to use the static_cast<> directy from the aligned_storage, and
beyond any doubts, it is **exactly** as efficient
as the value-based implementation, just like you (and Joel) said.

In fact, after some thinking it was clear that the extra pointer data member
was introducing an additional !unnecesary! indirection.
Thus, the POD optimization was just needed becasue the NonPOD implementation
was plain wrong :-)

There is no need for two implementations any more!

Thanks Joel and David!

Fernando Cacciola


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk