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

  • Home
  • SEARCH
  • 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 7496641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:42:29+00:00 2026-05-29T18:42:29+00:00

Keeping the old question. See below for resolution. It is probably something simple, but

  • 0

Keeping the old question. See below for resolution.
It is probably something simple, but still. I have the following C++11 code fragment:

#include <vector>

template <typename... Ts>
struct typelist
{
};

template <typename T>
struct EventContainer
{
    typedef T Type;
    /// TODO. Ring buffer
    std::vector<T> container;

    void push(const T& t)
    {
        EventContainer<T>::container.push_back(t);
    }

    virtual ~EventContainer()
    {
    }
};


template <template <typename...> class TL>
class EventStorage:
        public EventContainer<Ts>...
{

};

class Event1
{
};

class Event2
{
};

typedef typelist<Event1,Event2> Events12;

int main()
{
    EventStorage<Events12> ev;

    return 0;
}

How can I make EventStorage inherit EventContainer templeted with each of the types in the typelist. I could do it with Loki:: library, but I want to use C++11 with variadic templates.
Thank you.

Resolution1: Fixing EventStorage template template issue. This will make EventStorage, multiple inherit all EventContainer templated with each type of Ts.

template <typename...>
class EventStorage
{
};

template <typename... Ts>
class EventStorage < typelist<Ts...> >:
        public EventContainer<Ts>...
{

};

Now I have compile time error, on the following main():

int main()
{
    EventStorage<Events12> ev;
    Event1 ev1;
    ev.push(ev1);

    return 0;
}

In function ‘int main()’:
error: request for member ‘push’ is ambiguous
error: candidates are: void EventContainer<T>::push(const T&) [with T = Event2]
error: void EventContainer<T>::push(const T&) [with T = Event1]

Why the compiler is confused? After all I push with specific type.
GCC 4.6.1 here.

Resolution2:
As @Matthieu M. suggested I can present a forwarding method int EventStorage, but at a cost of one extra functin call:

template <typename T>
void push(const T& t)
{
    EventContainer<T>::push(t);
}

According to Alexandrescu, the compiler will optimize this forward call as long as parameters are references.
Now the question is officially closed 🙂

  • 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-29T18:42:31+00:00Added an answer on May 29, 2026 at 6:42 pm

    Is there any reason for introducing the typelist in the first place ?

    template <typename T> struct Template { void push(T) {} };
    
    template <typename... Args>
    class Storage: public Template<Args>...
    {
    public:
      // forwarding...
      template <typename T>
      void push(T t) {
        Template<T>& me = *this;
        me.push(t);
      }
    };
    
    int main() {
      Storage< int, char > storage;
    }
    

    This works and you can typedef the whole Storage<...> bit.

    EDIT: Following on comments regarding the possibility to “combine” types.

    There are two solutions:

    template <typename...> struct CombineStorage;
    
    template <typename... A, typename... B>
    struct CombineStorage<Storage<A...>, Storage<B...>> {
      typedef Storage<A..., B...> type;
    };
    

    Or simply provide a typelist adapter:

    template <typename... Args>
    class Storage<typelist<Args...>>: public Storage<Args...> {};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a newbie question: Can the following HTML/JavaScript code be further simplified by
This is probably a really stupid newbie-sounding question to you developer type people, but
I have a wonderful opportunity to refactor out old and smelly code into a
I have a project where I create reports and I am keeping the old
Is keeping JMS connections / sessions / consumer always open a bad practice? Code
I'm curious about keeping source code around reliably and securely for several years. From
What are the advantages/disadvantages of keeping SQL in your C# source code or in
MAJOR EDIT I have restructured my question to be more appropriate and less arbitrary,
Here is question for all those who have delivered WCF solutions to their clients/customers
This question is in continuation of this one . The deal is simple. Given:

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.