I don't know exactly why --in this context-- the second placeholder cannot be "expanded" but I found out that wrapping the expression boost::mpl::inherit
solved my problem.
So here you are, this AbstractFactory
in a nutshell:
We encapsulate the implementation in a namespace Impl
:
namespace Impl
{
template
<
class TypeSequence,
template <class> class ProductStorage,
template <class, template <class> class> class Unit
>
struct AbstractFactory
{
private:
template <class T, class U>
struct Inherit : boost::mpl::inherit< T, Unit< U, ProductStorage > >
{};
public:
typedef typename boost::mpl::inherit_linearly
<
TypeSequence,
// the trick is on the following line
Inherit< boost::mpl::_1, boost::mpl::_2 >
>
::type Type;
};
} // namespace Impl
and we derive from it like so:
template
<
class TypeSequence,
template <class> class ProductStorage = RawPointerStorage,
template <class, template <class> class> class Unit = AbstractFactoryUnit
>
struct AbstractFactory
: Impl::AbstractFactory< TypeSequence, ProductStorage, Unit >::Type
{
typedef TypeSequence Products;
template <class T>
auto create() -> typename ProductStorage< T >::StoredType
{
Unit< T, ProductStorage >& unit = *this;
return unit.doCreate(ProductStorage< T >());
}
};