visual c++ - Help needed with container for a generic item in C++ -


I wonder if it is possible to define the general C + container that stores the item as follows:

  template & lt; Typename T & gt; Square item {typename t value; }  

I know that the item type definition is required to declare such as:

  std :: vector & lt; Item & lt; Int & gt; & Gt; item;  

Is there a pattern design or wrapper that can solve this problem?

with 9 types, of boost :: variant Your best shot is to use: boost :: any you get: <

  • Speed ​​(like a union, a heap allocation, a typeid / ul>

    Just use this:

      typedef boost :: version & lt; Type0, Type1, Type2, Type3, Type4, Type5, Type6, Type7, Type8 & gt; item; Typedef std :: vector & lt; Items & gt; ItemsVector; To take an action on   

    boost :: variant , the best way to create a permanent visitor is to read about it.

    >

  • Comments