简体   繁体   English

制作可变参数模板类的forward_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 ). 我有一个std::forward_list ,还有一个类Delegate (从此处获取 ),该类是带有可变参数类型签名的类( typename return_type, typename... Args )。

I want to make a std::forward_list out of these Delegate s. 我想从这些Delegate创建一个std::forward_list How would I go about doing so? 我将如何去做? I have tried: 我努力了:

std::forward_list<Delegate<void, typename...> > but it gives a syntax error. std::forward_list<Delegate<void, typename...> >但它给出语法错误。 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. 我可以保证每个列表(会有多个)仅具有将相同数量的参数存储在一起的Delegate类型。 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 . 这些列表实际上将位于std::unordered_map

First, it sounds like you should use unordered_multimap instead of a map with lists as the values. 首先,听起来您应该使用unordered_multimap而不是使用列表作为值的地图。

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. 就是说,如果您试图将类型存储在甚至很小的STL容器中,则需要制作一个基类并将它们存储为指向该基类的指针。 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. 您提到一个列表中的所有值将具有相同数量的参数,但是您未指定参数将完全相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM