Boost logo

Boost :

From: Gregory Colvin (gregory.colvin_at_[hidden])
Date: 2003-10-01 11:38:41


On Wednesday, Oct 1, 2003, at 09:52 America/Denver, David Abrahams
wrote:

> Gregory Colvin <gregory.colvin_at_[hidden]> writes:
>
>> Still wondering.
>>
>> On Tuesday, Sep 30, 2003, at 11:09 America/Denver, Gregory Colvin
>> wrote:
>>> Given
>>>
>>> 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?
>
> The copy of the shifted_ptr? Yes, of course. That's the RVO.
>
>>> If so, do they?
>
> Some do; some don't.
>
> Oh, wait. You meant the copy of Stuff()?

Yes.

> 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.

I was wondering if the infinite series of overloads can be dispensed
with
in favor of requiring that T have an accessible copy constructor. Peter
says that his compilers fail to optimize away the extra copy of T, but I
don't whether the standard allows the optimization.


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