[Functional/Factory] Value factory not accepts rvalues?

I found that boost::value_factory did not accept rvalues in some case. In my case, temporary value is produced and passed to value factory directly. But boost::value_factory<T>::operator() did not accept rvalue, they take lvaue reference instead. Maybe it'll be better to provide another version of operator takes const lvalue? (Additionally, use std::forward to forward universal reference in C++11?) Sample code which compiler complains: int get_value(); struct var { var( ); explicit var(int); }; void caller() { boost::value_factory<var> f; f(get_value()); }

On Nov 12, 2013, at 2:34 AM, "Lin, Yi-Li"
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? ___ Rob (Sent from my portable computation engine)

2013/11/12 Rob Stewart
On Nov 12, 2013, at 2:34 AM, "Lin, Yi-Li"
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
participants (2)
-
Lin, Yi-Li
-
Rob Stewart