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
3
votes
0 answers

Clang-tidy false positive with boost::variant

When running clang-tidy on this minimal example posted below I get the (imho) false positive error from clang-tidy (full error trace at the end) Value assigned to field 'id' in implicit constructor is garbage or undefined…
user823255
  • 980
  • 9
  • 19
3
votes
0 answers

Linking error on a defined function taking a boost::variant

I'm experiencing a linking error that I can't understand, and that only happens to some developers (maybe because we are using some different library or compiler versions): undefined reference to…
3
votes
1 answer

Compilation error by switching to higher Boost Version 1.6.1

I switched my Boost version from 1.6.1 to >=1.6.2 and my boost::spirit parser code fails to compile. Actually, I thinking the problem has something to do with a bug fix in Boost Variant from version 1.6.1 to version 1.6.2. Release notes of version…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
3
votes
1 answer

How can I return a boost::variant made from a subset of the types contained in boost::varaint return type

I have 4 functions: boost::variantprocessFile(const char* file){ if(----expression that if true means I have to process as type 1----) return processType1(file); //this just returns type1 else…
MoustacheSpy
  • 743
  • 1
  • 6
  • 27
3
votes
2 answers

How to compare boost::variant in order to make it a key of std::map?

How to compare boost::variant in order to make it a key of std::map ? Seems that operator<() is not defined for boost::variant
user222202
  • 523
  • 4
  • 14
3
votes
1 answer

How to simplify type generated by make_variant_over

Boost variant has a function called make_variant_over that takes an MPL sequence (for example list) and produces a variant from those types. However if one looks carefully the type generated is never a simple variant. For example…
alfC
  • 14,261
  • 4
  • 67
  • 118
3
votes
1 answer

Classify Types in Boost Variant using Visitor does not compile

I'm using boost-variant throughout my projects. In one scenario I need to classify the types contained in my boost-variant into several classes. As I have quite a lot of types in my variant I came up to the idea of defining several variants inside…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
3
votes
1 answer

Inheriting from boost::variant and templatized AST

The following code crashes GCC and fails to compile with Clang. What's wrong with it? #include #include #include template struct wrapper1; template struct wrapper2; struct…
Igor R.
  • 14,716
  • 2
  • 49
  • 83
3
votes
3 answers

Clang fails to compile parameter pack expansion using template metaprogramming

I have a boost::variant of several ranges. In this context, a range is just a std::pair, where It is an iterator. I use this to store ranges of iterators satisfying certain properties. Since I don't know the iterator types, I use a little…
3
votes
1 answer

boost::make_recursive_variant has no member named 'apply_visitor'

First time using Boost, and trying to grok how to use boost::variant. Please find below an example program and the error message (GCC v5.3.0, -std=c++14) #include #include #include #include using…
Arandur
  • 727
  • 6
  • 19
3
votes
2 answers

Generic function to convert boost::any to boost::variant

Assume that you have a boost::any object and a boost::variant object. I'm looking for a generic function convert, that takes a template parameter T being a specialized boost::variant e.g. boost::variant and magically converts the…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
3
votes
0 answers

boost variant type collision

Follow-Up Question So, I've been playing with the Boost Mini C Tutorial What I have done is added a rule to parse string literals. The purpose is so that I can parse and compile programs like (functionality already built-in): int ret(int x) { …
Dylan_Larkin
  • 503
  • 4
  • 15
3
votes
1 answer

How to modify boost::apply_visitor to return a value?

I am trying to use boost::variant and boost::apply_visitor. This already works except when I try to make the Vistor's functions to return a (boolean) value. I saw a lot of examples on SO doing this but I wasn't able to create a working sample. This…
Semjon Mössinger
  • 1,798
  • 3
  • 22
  • 32
3
votes
1 answer

boost::variant construction weirdness - its ctor accepts everything

The subject is already touched in this boost-variant-ambiguous-construction question. But my issue is not with types convertible to each other, but with completely unrelated types. Simplified example: // types not related in any way class A…
PiotrNycz
  • 23,099
  • 7
  • 66
  • 112
3
votes
0 answers

Inline function is not defined

Using Variant and Visitor idioms for dealing with abstract syntax tree of mathematical expression I faced linker errors undefined reference to 'function_name' prepended with warnings inline function 'function_name' is not defined…
Tomilov Anatoliy
  • 15,657
  • 10
  • 64
  • 169