I am trying to use the boost::variant in c++11 to create this but I m not sure how. So I have this structure of the templated class data<>
typedef boost::variant< data<A>,data<B>> dataVar;
stored in a
std::map<string,dataVar> dataMap
It would be great if I could retrieve the type for data somehow so I can assign the values but I have no idea how to make this work elegantly
void registerDataFor(string str)
{
auto itr = dataMap.find(str);
if(itr == dataMap.end())
return;
dataVar = itr->second;
data<v.which()> itemData= boost::get<v.which()>(v);
someArray.push_back(itemData.getIntegerValue());
registerDataFor(itemData.getString());
}
This doesn't compile since the template brackets require a static type.
I ve seen other responses proposing a visitor design but I also need the type for data<> to get the item.
Aucun commentaire:
Enregistrer un commentaire