I want to create a function that can take different types of iterators which store the same type of object:
The first is a std::map containing shared_ptr<Foo> (typedef-ed as FooMap) and the other is a std::list which also contains shared_ptr<Foo> (FooList).
I really like the solution MSalters suggested for a similar question and tried t...
Given two identical boost::variant types a and b, the expression ( a == b ) is permitted.
However ( a != b ) seems to be undefined. Why is this?
...
boost::variant claims that it is a value type. Does this mean that it's safe to simply write out the raw representation of a boost::variant and load it back later, as long as it only contains POD types? Assume that it will be reloaded by code compiled by the same compiler, and same version of boost, on the same architecture.
Also, (prob...
Hello,
I'm having trouble choosing between Boost.Any and Boost.Variant.
When should I use each one?
What are the advantages and disadvantages of each?
I am basically looking to store some states from external sources.
Thanks,
Omer
...
I need to store a collection of ints and doubles (representing nominal and real valued data) in c++. I could obviously store them all in a std::vector<double> , but this feels a bit wrong and doesn't get the aesthetics bonus points.
I could also cook up something based on polymorphism, but I also need the collection to be really efficie...
I'm using a boost variant to hold some generated types, right now my code generator creates a header with the types and a variant capable of holding them. At initialization time, I'd like to iterate over the allowable types in the variant, not the types the variant is holding at the moment.
Can I do this with a variant?
...
I have a boost variant with 7 types in it. When I try to use the last two types, the linker segfaults. I am using g++ (gcc version 3.3.3 on SuSE Linux) on a 64 bit linux machine and the error that I get is
collect2: ld terminated with signal 11 [Segmentation fault]
It doesnt matter what order I put the types in, the last two will cau...
In my C++ library I have a type boost::variant<A,B> and lots of algorithms getting this type as an input. Instead of member functions I have global functions on this type, like void f( boost::variant<A,B>& var ). I know that this can also be achieved with templates, but this is not suitable for my design.
I am very fine with this style ...
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...
struct A
{
std::string get_string();
};
struct B
{
int value;
};
typedef boost::variant<A,B> var_types;
std::vector<var_types> v;
A a;
B b;
v.push_back(a);
v.push_back(b);
How can I iterate iterate through the elements of v to get access to the a and b objects ?
I'm able to do it with boost::get b...
How would you check for the object type when looping std::list?
class A
{
int x; int y;
public:
A() {x = 1; y = 2;}
};
class B
{
double x; double y;
public:
B() {x = 1; y = 2;}
};
class C
{
float x; float y;
public:
C() {x = 1; y = 2;}
};
int main()
{
A a; B b; C c;
list <boost::variant<A, B, C>> l;
...
Hi, I would like to use a boost.variant<T0,T1,T2> as a parameter to a template 'Visitor' class which would provide visitor operators as required by the boost.variant visitor mechanism, in this case all returning void i.e.,
void operator()(T0 value);
void operator()(T1 value);
void operator()(T2 value);
The template would also have fo...
As a personal exercise, I want to implement the visitor pattern using shared_ptr. I am familiar with Robert Martin's acyclic visitor paper but find the intrusive nature of the virtual accept() and necessary creation of an {X}Visitor class for each {X} class unpleasant. I like the boost::static_visitor class as it encapsulates all the l...