Iterator for boost::variant

Posted by Ivan on Stack Overflow See other posts from Stack Overflow or by Ivan
Published on 2010-06-08T23:34:23Z Indexed on 2010/06/11 6:43 UTC
Read the original article Hit count: 418

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost