I have declared a 3D vector vector<vector<vector<boost::variant<string, float>>>> masterList;
which is going be filled with heterogeneous data (strings & float) is this the correct way? because I'm facing problem later with the instruction masterList.push_back(tokens);
whereby I defined std::vector<vector<string>> tokens;
A vector of variants is what you need to store; this is not compatible with a vector of one of the variant's types. In other words, you could do this:
vector<vector<vector<boost::variant<string, float>>>> masterList;
std::vector<vector<boost::variant<string, float>>> tokens;
masterList.push_back(tokens);
But if your data is such that the "variance" only happens at the outer dimension, you could instead do this:
vector<boost::variant<vector<vector<string>>, vector<vector<float>>>> masterList;
std::vector<vector<string>> tokens;
masterList.push_back(tokens);
You might also reconsider whether you need the full flexibility (and concomitant overhead) of a vector of vectors of vectors. If your data is rectangular (not jagged), you can improve the situation as outlined here: https://stackoverflow.com/a/17005753/4323
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.