Boost logo

Boost Users :

Subject: Re: [Boost-users] [smart_ptr] make_shared imposes const ref.
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2011-11-29 08:04:01


On Tue, Nov 29, 2011 at 11:46 AM, Igor R <boost.lists_at_[hidden]> wrote:
>> Why is make_shared declared as
>>
>> template<typename T, typename Arg1 > shared_ptr<T> make_shared( Arg1
>> const & arg1 );
>>
>> rather than
>>
>> template<typename T, typename Arg1 > shared_ptr<T> make_shared( Arg1 arg1 );
>>
>> since the effect is that if you have a constructor that takes
>> non-const references you cannot use make_shared( ) on it.
>
>
> I guess it's because your compiler doesn't support && (i.e. perfect
> forwarding is impossible).
> http://www.boost.org/doc/libs/1_48_0/libs/smart_ptr/make_shared.html#functions
> <<The prototypes shown above are used if your compiler supports rvalue
> references and variadic templates. They perfectly forward the args
> parameters to the constructors of T.
> Otherwise, the implementation will fall back on forwarding the
> arguments to the constructors of T as const references. If you need to
> pass a non-const reference to a constructor of T, you may do so by
> wrapping the parameter in a call to boost::ref. >>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

Ah yes, thanks, I'd failed to notice the informative comment answering
my exact question!

- Rob.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net