Boost logo

Boost :

Subject: Re: [boost] [Functional/Factory] Value factory not accepts rvalues?
From: Lin, Yi-Li (record.nctu.cis91_at_[hidden])
Date: 2013-11-12 06:26:09


2013/11/12 Rob Stewart <robertstewart_at_[hidden]>

> On Nov 12, 2013, at 2:34 AM, "Lin, Yi-Li" <record.nctu.cis91_at_[hidden]>
> wrote:
>
> > Sample code which compiler complains:
> > int get_value();
> > struct var {
> > var( );
> > explicit var(int);
> > };
> >
> > void caller() {
> > boost::value_factory<var> f;
> >
> > f(get_value());
> > }
>
> You don't show the error message, and I know nothing about value_factory,
> but var's converting constructor is explicit, so the int returned by
> get_value() cannot be converted to a var implicitly in the call of f.
>
> Perhaps you misinterpreted the error?
>

Hi Rob,

I'm sure this is not caused by 'explicit'. You'll get the same error even
if 'explicit' is removed.
Sorry that I didn't describe the detail.

Error message says:
"no match for call to ‘(boost::value_factory<var>) (int)’"

Error message for the overload takes single argument:
/usr/local/include/boost/functional/value_factory.hpp:61:24: note:
boost::value_factory<T>::result_type
boost::value_factory<T>::operator()(T0&) const [with T0 = int; T = var;
boost::value_factory<T>::result_type = var]
     inline result_type operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& a))
const
                        ^

It's caused by the 'T&' is non-const lvalue reference, which rvalue could
not implicitly convert to.
That is, 'get_value' returns rvalue and not accepted by
'value_factory::operator()(T0&)'.

I've modified the header to add another overloading accepts const lvalue
reference and it works.
But I'm not sure if it's designed to work like this?

Additionally, I'm using gcc 4.8.1 and error is same w/o '-std=c++11'.

Lin

>
> ___
> Rob
>
> (Sent from my portable computation engine)
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


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