Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2003-02-24 17:07:46


"David Abrahams" <dave_at_[hidden]> wrote in message
news:u3cmdid8l.fsf_at_boost-consulting.com...
> "Fernando Cacciola \(Home\)" <fernando_cacciola_at_[hidden]> writes:
>
> > optional<Window> opt( in_place<Window>(point(0,0),point(10,10)));
> >
> > here, in_place() is used to forward T's ctor argument to optional<> so
that
> > T is effectively constructed in-place right within the aligned storage.
> >
> > Is this what you want?
>
> I have to say that I like the idea of using placement-new with an
> optional<> argument better, since it doesn't get you involved with
> the const ref/non-const ref/rvalue forwarding problem.
>
I thougth about placement new as a way to achieve
in-place optional construction, precisely because of the forwarding
problem, but I couldn't get it to really work.
What would it be like, exactly?

I considered:

(a)

 optional<int> opt ( new ( optional_tag ) int(1) ) ;

this won't work because 'opt.m_storge' doesn't exist yet inside placement
new.

(b)

optional<int> opt ;
new (opt) int(2);

this would be close, but what should I do with the 'int*'
which is the result of the new?

int* p = new (opt) int(2) ?

But this is just: int v=2; int* p=&v;

--
Fernando Cacciola

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