David Abrahams wrote:

[...]

>>> Example:
>>> optional<int> i;
>>>
>>> new (i) int(17);
>>
>>
>> Ex. 1:
>> // Class Widget has a heavy copy constructor
>> optional<Widget> i;
>>
>> new (i) Widget(this, ...);
>
>
> Soo... what are you demonstrating here?  Please spell it out. Normal
> construction of a widget in optional<Widget> incurs a copy?

Yes, it incurs a copy.  Maybe struct A is not a good example, but
TrollTech's QT widgets are.

struct A
{
    A(int) { cout << "A(int)" << endl; }
    A(A const &) { cout << "A(A const &)" << endl; }
};

int main()
{
    optional<A> o(A(9));
}

[...]

> Soo... what are you demonstrating here?  Please spell it out. The
> bool in optional that indicates initialization incurs space/alignment
> overhead?

Yes, exactly.  Sorry if I wasn't precise enough.

The bool type will cancel type_with_alignment<> effects (at least on Intel
compatible platforms); i.e. unique alignment of each optional<T> type.



Philippe A. Bouchard




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

Reply via email to