|
Boost : |
From: cppljevans_at_[hidden]
Date: 2003-10-01 11:19:12
On 10/01/2003 10:52 AM, David Abrahams wrote:
> Gregory Colvin <gregory.colvin_at_[hidden]> writes:
>
[snip]
>>>
>>> template<typename T> shifted_ptr<T> make_shifted_ptr(cont T& t) {
>>> return shifted_ptr(new(so) T(t));
>>> }
>>>
>>> ... make_shifted_ptr(Stuff()) ...
>>>
>>>are compilers allowed to optimize away the copy and construct the
>>>Stuff in place?
>
[snip]
> Oh, wait. You meant the copy of Stuff()? It's not meant to be a T
> neccessarily. It's just any old argument to T's constructor. You
> need a bunch of overloads for make_shifted_ptr to make the example
> complete.
>
Why couldn't the shifted_ptr(T*) be replaced with
shifted_ptr(make_shifted_ptr<T>&), where make_shifted_ptr<T> is
simply derived from auto_ptr but has no make_shifted_ptr(T*) CTOR?
No copy is needed and it simply turns over the T* to shifted_ptr<T>.
Just as David points out, there would need to be a bunch of
overloads for every T CTOR or at least those which
the user wants to put into shifted_ptr.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk