Hy there,
I'm trying to adapt an existing code to boost::variant. The idea is to use boost::variant for a heterogeneous vector. The problem is that the rest of the code use iterators to access the elements of the vector. Is there a way to use the boost::variant with iterators?
I've tried
typedef boost::variant<Foo, Bar> Variant;
std::vector<Variant> bag;
std::vector<Variant>::iterator it;
for(it= bag.begin(); it != bag.end(); ++it){
cout<<(*it)<<endl;
}
But it didn't work.
EDIT: Thank you for your help! But in my design, I need to get one element from the list and pass it around other parts of the code (and that can be nasty, as I'm using GSL). The idea of using an iterator is that I can pass the iterator to a function, and the function will operate on the return data from that specific element. I can't see how to do that using for_each. I need to do something similar to that:
for(it=list.begin(); it!=list.end();++it) {
for(it_2=list.begin(); it_2!=list.end();++it_2) {
if(it->property() != it_2->property()) {
result = operate(it,it_2);
}
}
}
Thanks!