This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: std::function with std::unique_ptr argument
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Rodolfo Lima <rodolfo at rodsoft dot org>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Fri, 5 Jun 2009 21:49:43 +0100
- Subject: Re: std::function with std::unique_ptr argument
- References: <h0b0go$1ue$1@ger.gmane.org>
2009/6/5 Rodolfo Lima:
> Hi, I'm trying to use a std::function with std::unique_ptr arguments but
> the std::function invocation ends up using std::unique_ptr copy ctor,
> which is private/deleted.
>
> Since std::function is a forward call wrapper, its operator() should
> have forwarded properly its arguments to the wrapped function, but
>
> M_invoker(_M_functor, __args...);
>
> and
>
> (*_Base::_M_get_pointer(__functor))(__args...);
>
>
> doesn't seem to do that. IMHO it should be
>
> _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...);
>
> (*_Base::_M_get_pointer(__functor))(std::forward<_ArgTypes>(__args)...);
>
>
> Any objections?
You're right it should forward the args, but see c++/34022 - it would
be dangerous to correctly forward rvalues, as you could end up passing
a dangling reference to the function.
Jonathan