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 7545969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:04:39+00:00 2026-05-30T09:04:39+00:00

I was writing some code where I have a class that can accept mixins

  • 0

I was writing some code where I have a class that can accept mixins as variadic template parameters. However, I also need the mixins to be able to access the base class through the CRTP idiom. Here’s a minimal example that cannot quite do what I want:

template <template <class> class... Mixins>
class Foo : Mixins<Foo<Mixins...>>... {};

However, a mixin that I might pass to Foo will, in general, have several template parameters, like so:

template <class Derived, class Type1, class Type2>
class Bar
{
    Derived& operator()()
    {
        return static_cast<Derived&>(*this);
    }
};

How can I change Foo so that I can have it inherit from a number of base classes, where I control the template parameters accepted by each base class? If I hand Foo a list of template-template parameters, along with a list of arguments to pass to them, then I don’t see how I would be able to associate each template-template parameter with its arguments. So far, I thought of something like this, but I don’t know how I would proceed.

template <template <class...> class T,
    template <class...> class... Ts>
class Foo : /* How do I retrieve the arguments? */
  • 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-05-30T09:04:41+00:00Added an answer on May 30, 2026 at 9:04 am

    I am not quite sure I understood the problem, so please let me rephrase it so that we can start on the right foot.

    You need to thread the derived type to the base classes, in a typical CRTP use case, while at the same time passing other template parameter to the various base classes.

    That is, a typical base class will be:

    template <typename Derived, typename X, typename Y>
    struct SomeBase {
    };
    

    And you want need to create your type so that you can control the X and Y and at the same time pass the complete Derived class.


    I think I would use the apply trick to generate the base class on the fly, from an adapter provided in the argument list of the Derived class.

    template <typename Derived, typename X, typename Y>
    struct SomeBase {};
    
    template <typename X, typename Y>
    struct SomeBaseFactory {
      template <typename Derived>
      struct apply { typedef SomeBase<Derived, X, Y> type; };
    };
    
    // Generic application
    template <typename Fac, typename Derived>
    struct apply {
      typedef typename Fac::template apply<Derived>::type type;
    };
    

    Then, you would create the type as:

    typedef MyFoo< SomeBaseFactory<int, float> > SuperFoo;
    

    Where Foo is defined as:

    template <typename... Args>
    struct Foo: apply<Args, Foo<Args...>>::type... {
    };
    

    And just because it’s been a while since I trudged so deeply in templates, I checked it worked.


    Of course, the Factory itself is not really a specific to a given type, so we can reuse the wrapper approach you had experimented:

    template <template <typename...> class M, typename... Args>
    struct Factory {
      template <typename Derived>
      struct apply { typedef M<Derived, Args...> type; };
    };
    

    And yes, it works too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that does some generic code for Writing to a Database.
I need some help writing a class that can go through other java files
I am writing a simple class that will basically accept 3 parameters, execute a
I have come across an annoying problem while writing some PHP4 code. I renamed
I have some code like this in a winforms app I was writing to
I am writing unit tests for some of my code and have run into
I have been messing around with writing some stored procedures in .NET code with
I'm writing a web page in ASP.NET. I have some JavaScript code, and I
Does anyone have some good hints for writing test code for database-backend development where
So I was writing some code today that basically looks like this: string returnString

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.