Boost logo

Boost :

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


"Philippe A. Bouchard" <philippeb_at_[hidden]> wrote in message
news:b3e2cg$fdr$1_at_main.gmane.org...
> Fernando Cacciola (Home) wrote:
>
> [...]
>
> > I'm still not sure I understand what are you trying to do, but it
> > looks
> > like you want optional with in-place construction (which bypasses the
> > copy). In this case, I recently explored something which would look
> > like:
> >
> > 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?
>
> Yes, something like that. I am curious to know how in_place<> works.
>
Look at the thread "'optional' - request for extension"
Essentilly,

in_place<T>(a0,a1,a2...)

just creates a function object which holds onto the argument list:

template<class T, class A0, class A1>
struct in_place_factory2
{
  in_place_factory2( A0& a0, A1& a2) : m_a0(a0), m_a1(a1) {}

  A0& m_a0 ;
  A1& m_a1 ;
}

and which has the following function call operator:

void operator() ( void* address ) const
{
  new (address) T(m_a0,m_a1);
}

optional<> ctor just calls the function object passing its own m_storage as
a parameter.

--
Fernando Cacciola

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