Boost logo

Boost :

From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2003-02-24 14:20:18


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


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