I need to maintain a list of vector(int), vector(char) and vector(float). Is this possible?
I am not sure I understand your question.
Is boost::variant
what you are looking for? It will allow you to store the elements with different types in a single container.
Some sample code (not tested):
typedef boost::variant <
std::vector<int>,
std::vector<char>,
std::vector<float>
> VectorOfIntCharOrFloat;
std::list<VectorOfIntCharOrFloat> vec;
and then iterate over it / access elements as:
std::list<VectorOfIntCharOrFloat>::iterator itr = vec.begin();
while(itr != vec.end()) {
if(std::vector<int> * i = boost::get<std::vector<int> >(itr)) {
std::cout << "int vector"<< std::endl;
} else if(std::vector<float> * f = boost::get<std::vector<float> >(itr)) {
std::cout << "float vector" << std::endl;
} else if(std::vector<char> * c = boost::get<std::vector<char> >(itr)){
std::cout << "char vector" << std::endl;
}
++itr;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With