Let's say I have the following types:
template < class T, template <class> class Storage > struct AbstractFactoryUnit { virtual ~AbstractFactoryUnit() {} virtual typename Storage< T >::StoredType doCreate(Storage< T >) = 0; };
and
template < class TypeSequence, template <class> class ProductStorage, template <class, template <class> class> class Unit = AbstractFactoryUnit > struct AbstractFactory : boost::mpl::inherit_linearly < TypeSequence, boost::mpl::inherit < boost::mpl::_1, Unit< boost::mpl::_2, ProductStorage > > >::type { typedef TypeSequence Products; template <class T> auto create() -> typename ProductStorage< T >::StoredType { Unit< T, ProductStorage >& unit = *this; unit.doCreate(ProductStorage< T >()); } };
Now I want to implement le AbstractFactory ...
Some types of lol:
struct Foo {}; struct Bar {}; struct Baz {};
Repository lol:
template <class T> struct RawPointerStorage { typedef T* StoredType; };
and finally, the implementation:
struct FooBarBaz : AbstractFactory< boost::mpl::set< Foo, Bar, Baz >, RawPointerStorage > { A* doCreate(RawPointerStorage< Foo >) override { return new A; } B* doCreate(RawPointerStorage< Bar >) override { return new B; } C* doCreate(RawPointerStorage< Baz >) override { return new C; } };
Unfortunately, the compiler complains:
1>C:\Libs\boost\boost_1_51_0\boost/mpl/aux_/preprocessed/plain/inherit.hpp(20): error C2500: 'boost::mpl::inherit2<T1,T2>' : 'AbstractFactoryUnit<T,ProductStorage>' is already a direct base class 1> with 1> [ 1> T1=AbstractFactoryUnit<boost::mpl::_2,RawPointerStorage>, 1> T2=AbstractFactoryUnit<boost::mpl::_2,RawPointerStorage> 1> ] 1> and 1> [ 1> T=boost::mpl::_2, 1> ProductStorage=RawPointerStorage 1> ]
I'm a little confused as it compiles just fine when AbstractFactoryUnit accepts only one template parameter. My assumption is that the compiler cannot “resolve” the second placeholder, but I have to admit that I don’t know why - because I don’t know how boost calls apply on placeholders.
I am using VS2012 with vc100 or vc110.
Any idea? (yes, I played with AbstractFactory described in modern C ++ design)
EDIT : I finally decided to provide all the AbstractFactory code without disguise in both my question and my answer.