Trying to implement abstract factory with Boost Factory, classes of the hierarchy have c-tor params, already looked this discussion: Passing arguments in constructor with boost factory
My example is the following:
struct base {
virtual ~base() = default;
virtual void method() = 0;
};
struct derived1 : public base {
derived1(int a1, int a2) {}
virtual ~derived1() = default;
virtual void method() {}
};
Create factory and try to create an instance
std::map<uint8_t, boost::function<base*(int, int)>> my_factory;
my_factory[0] = boost::bind(boost::factory<derived1*>(), _1, _2) ;
std::unique_ptr<base> derived_instance(my_factory.at(0)(1, 2));
Problem it does not compile at all with the error in boost::bind cannot convert argument 1 from 'int' to 'int &'
I understand the nature of the error, boost::bind expect non-const reference for some reasons, but I'm passing rvalue that could not be referenced. Of course, after changing constructor params derived1 to references everything compiles but it would look ugly. What is correct usage of this pattern?
More abstract question - is it worth to use Boost Factory with C++14? Implementations seems a bit out-of-date, I expected something variadic-based
C++ Compiler Visual Studio 2015
Boost 1.61