I wonder if it is possible to define a generic C++ container that stores items as follows:
template <typename T>
class Item{
typename T value;
}
I am aware that the declaration needs the definition of the item type such as:
std::vector<Item <int> > items;
Is there any pattern design or wrapper that may solve this issue?
With 9 types, your best shot is to use
boost::variant, in comparison toboost::anyyou gain:typeidinvocation)Just use this:
In order to invoke an operation on
boost::variant, the best way is to use create a static visitor, read about it in the documentation.