Search code examples
c++templatesc++11forward-list

Making a forward_list of a variadic template class


I have a std::forward_list and a I have a class Delegate (taken from here) that has is a class with a variadic type signature (typename return_type, typename... Args).

I want to make a std::forward_list out of these Delegates. How would I go about doing so? I have tried:

std::forward_list<Delegate<void, typename...> > but it gives a syntax error. I would also like to add to this list later. I can guarantee that each of these lists (there will be multiple) will only have Delegate types that take the same number of parameters stored together. However, each list may have a list of methods that take different parameters than the methods in other lists.

These lists are actually going to be inside of a std::unordered_map.


Solution

  • First, it sounds like you should use unordered_multimap instead of a map with lists as the values.

    That said, if you're trying to store types in an STL container which differ even a little, you'll need to make a base class and store them as pointers to that base class. You mentioned that all the values in one list will have the same number of parameters, but you didn't specify the parameters will be completely identical.