Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9168009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:31:45+00:00 2026-06-17T15:31:45+00:00

Say I have these types: template < class T, template <class> class Storage >

  • 0

Say I have these 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 lol types:

struct Foo {};
struct Bar {};
struct Baz {};

A lol storage:

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 bit confused since it compiles just fine when AbstractFactoryUnit accepts only one template parameter. My guess is the compiler cannot “resolve” the second placeholder, but I should admit I don’t know why — since I don’t know well how boost invokes apply on placeholders.

I use VS2012 with either vc100 or vc110.

Any idea?
(yes, I was playing with the AbstractFactory described in modern C++ design)

EDIT: I finally decided to provide my whole AbstractFactory code without disguises in both my question and my answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:31:46+00:00Added an answer on June 17, 2026 at 3:31 pm

    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 >());
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have the following class: template<class T> struct A { static int value;
Let's say I have these class hierarchy : public abstract class Parent { }
Let's say we have these two classes: public class Base { public static int
Let's say I have these models: class A(models.Model): name = models.CharField(max_length=32) b = models.ForeignKey(B,
Say I have a class that can use different types of distance functions (Euclidean
Say I have two Template classes. template<class T> class baseclass1 { template<class> friend class
I have the following setup: A templated class SpecialModel: template<typename A, typename B> class
Say I have the following classes: template <class T> class Base { protected: T
Say I have a macro, FOO(name), and some template class Bar<> that takes one
Say i have a templated class template<class T> class A; template<> class A<int> {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.