"Joel de Guzman" <[EMAIL PROTECTED]> writes:

> ----- Original Message ----- 
> From: "Fernando Cacciola" <[EMAIL PROTECTED]>
>
>> > > optional captures the zero/one distinction, which, as its analogy to
>> > > pointers makes clear, is a very useful one.  A type which can contain
>> > > any number of different types would have a much more complicated
>> > > interface.  Maybe it's just a different library?
>> >
>> > Or perhaps, optional is just a limited add-on API over the variant?
>> > The low-level  implementation mechanism in place seems to be very
>> > similar and having 2 separate libraries will be redundant, I think.
>> >
>> Not so...
>> The low-level implementation is like a variant ONLY is the wrapped object is
>> not a POD.
>> When you have, say, optional<int>, the implementation uses: struct { int
>> m_value ; bool m_initialized }
>> As a result, value access, via operator*() is more efficient since it
>> doesn't dereference a pointer.
>
> That depends on how the variant is implemented. Which variant
> implementation are you referring to? I'm sorry. I'm confused with
> what you are saying. I can't see why it is more efficient. Neither do
> I see a dereference in any case.

I'm with Joel on this one. It seems to me that no special optimization
should be needed for PODs; all you should need is some aligned storage
in which to construct the contained object and one or more bits to
indicate which of the allowed types (if any) is held there.

-- 
                       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