Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-10-01 10:52:32

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()? 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

Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at