|
Boost : |
From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2002-07-17 18:53:25
"David B. Held" <dheld_at_[hidden]> wrote in message
news:ah4sgt$il$1_at_main.gmane.org...
> "Philippe A. Bouchard" <philippeb_at_[hidden]> wrote in message
> news:ah4p6i$nba$1_at_main.gmane.org...
>
> template <typename P1>
> count_wrapper(P1 const& p1)
> { new (m_buffer) value_type(p1); }
>
> template <typename P1, typename P2>
> count_wrapper(P1 const& p1, P2 const& p2)
> { new (m_buffer) value_type(p1, p2); }
One little thing: the parameters P1, P2, ... will be copied. This will
remove some optimizations with the copy constructor. Currently A(A(A(A(A(1,
2, 3))))) is equivalent to A(1, 2, 3) (of course A(A(A... will never happen
but you may have a series of r-values). Now I'm not sure if template <>
count_wrapper(A const &) will start creating temporaries (?).
> boost::instrusive_ptr<A> p(new count_wrapper<A>(1, 2, 3));
>
> which is functionally equivalent to:
>
> squad_ptr<A> p(new squad_ptr<A>::element_type);
> new (p.get()) A(1, 2, 3);
>
> not to mention much easier to read.
I haven't checked intrusive_ptr<> in depth yet but before, what do you think
of:
{
squad_ptr<A> p = squad_ptr<A>::reinterpret(new (new
squad_ptr<A>::element_type) A(1, 2, 3));
}
Or:
#define SQUAD_PTR(_Tp, _Constructor) \
squad_ptr<_Tp>::reinterpret(new (new squad_ptr<_Tp>::element_type)
_Constructor)
{
squad_ptr<A> p = SQUAD_PTR(A, A(1, 2, 3));
}
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