Questions tagged [boost-variant]

Boost.Variant is a C++ library containing a safe, generic, stack-based discriminated union container, offering a simple solution for manipulating an object from a heterogeneous set of types in a uniform manner.

Boost.Variant is a C++ library containing a safe, generic, stack-based discriminated union container, offering a simple solution for manipulating an object from a heterogeneous set of types in a uniform manner.

Whereas standard containers such as std::vector may be thought of as "multi-value, single type," boost::variant is "multi-type, single value."

317 questions
2
votes
0 answers

boost::get() vs boost::apply_visitor performance comparison

I am using boost::variant and wanted to know which is a better(in terms of performance) approach to extract the values from the variant. With my performance benchmark, on a sample data, I found that apply visitor is faster, but I didnt find any…
Ishita
  • 489
  • 5
  • 15
2
votes
2 answers

Function to compare contents of variant fails to compile

In my projects I'm using boost-variant exhaustively. Hence, for my unit tests I need to check the contents of a variant against a certain T with a certain content t. So I deviced the function cmpVariant for this sole purpose and to remove clutter…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
2
votes
2 answers

Pass an object of a type aggregated by a boost::variant to a function that accepts that boost::variant

Suppose I have: class TypeA { }; class TypeB { }; typedef boost::variant Type; This is ok: void foo(Type t) { }; int main(){ TypeA a; foo(a); } This does not compile: void foo(Type &t) { }; int main(){ TypeA a; …
Francesco Feltrinelli
  • 1,589
  • 1
  • 10
  • 14
2
votes
0 answers

Error passing boost::variant derived class

Why copying foo instance generates error: error: call of overloaded 'convert_construct(foo&, long int)' is ambiguous ? #include #include #include struct foo : public boost::variant { …
Michal
  • 2,078
  • 19
  • 29
2
votes
1 answer

Is it possible to use boost::any or boost::variant with a boost::pool?

boost::any: I tried to compile and run the following code to test this: #include #include int main() { boost::object_pool pool; boost::any *i = pool.malloc(); *i = 1; boost::any *j =…
wizurd
  • 3,541
  • 3
  • 33
  • 50
2
votes
3 answers

Recursive using declaration with boost variant

I am trying to represent a tree-like recursive data structure where each node may be one of two different data types. I employ the boost variant to "house" the two types that might be present at each node. However, I run into a problem. I'm…
rkemp
  • 278
  • 3
  • 14
2
votes
2 answers

Applying a boost::mpl::list to the template parameter of a type

I have a class that requires a boost::variant containing shared pointers to various types as follows: template class ToyPicker { typedef std::pair< ToySharedPtrVariant, …
Andrew Hundt
  • 2,551
  • 2
  • 32
  • 64
2
votes
1 answer

Why is boost::recursive_wrapper not working in this case

I have the following three rules: unary_expression = ( '(' > expression > ')' ) | int_; operator_expression = unary_expression >> *(operators > expression); expression = ( '(' > expression > ')' ) |…
2
votes
1 answer

boost.variant derived type: cannot use copy constructor

I have a type that derives from boost::variant. I do the following, and I cannot use the copy constructor, I cannot figure out why, some SFINAE seems to fail. Looks that the boost::variant construction is swallowing a T as…
Germán Diago
  • 7,473
  • 1
  • 36
  • 59
2
votes
1 answer

tree-like containers of boost::variant -- are there any drawbacks?

Apparently it is possible to have ordered maps and sets of boost::variant, like this: typedef boost::variant key_type; std::map m; m.insert(std::make_pair(std::string("a"), 3)); m.insert(std::make_pair(1,…
lo tolmencre
  • 3,804
  • 3
  • 30
  • 60
2
votes
1 answer

Boost Any to Boost Variant using Boost Preprocessor

In my projects I'm using boost::any and boost::variant exhaustively. For this a general conversion routine from boost::any to boost::variant was devised in my previous question Generic function to convert boost::any to boost::variant. Many thanks to…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
2
votes
3 answers

Why doesn't this boost::variant::operator= call compile?

Why doesn't v = 42 compile here? It seems the compiler is trying to call the copy assignment operator of Foo, why? How can I get it to compile? #include struct Foo { Foo(Foo&&) { } }; int main() { boost::variant
Emil Laine
  • 41,598
  • 9
  • 101
  • 157
2
votes
1 answer

string to Boolean expression is not working c++

I have a following code to evaluate a Boolean string based on an string input. The code supposed to work like this: Boolean string: "((0|1)&3);" Sting input: "101" how's it working? each character in the input string is supposed to be…
H'H
  • 1,638
  • 1
  • 15
  • 39
2
votes
1 answer

How to retrieve a boost::variant value for a templated class

I am trying to use the boost::variant in c++11 to create this but I m not sure how. So I have this structure of the templated class data<> typedef boost::variant< data,data> dataVar; stored in a std::map dataMap It would be…
T.Zak
  • 309
  • 2
  • 14
2
votes
2 answers

Static Polymorphism for method and object selection in C++

Trying to get compile time method and object selection without base class and virtual calls. Here is the case: struct A { void f1()const { cout << "A::f1" << endl;} void f2()const { cout << "A::f2" << endl;} }; struct B { void f1()const…
Amir Kirsh
  • 12,564
  • 41
  • 74