It seems that boost::factory<S*>
insists on its argument to be bound to a reference:
boost::factory<S*> factory;
factory(17); // error
int argument(17);
factory(argument); // OK
Based on this, it seems that boost::function<S*(int)>
passes the argument as int
without perfectly forwarding it while std::function<S*(int)>
seems to use perfect forwarding on the argument. As a result, the argument cannot be bound to boost::factory<S*>
argument.
When using gcc's std::function<...>
passing the argument by const&
works:
std::function<S*(int const&)> factory = boost::factory<S*>();
Unfortunately, the same work-around does not work with the std::function<...>
from libc++. Since you said that you tried to compile the code with gcc that may not be much of an issue, though.