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
1 answer

Compare two variant with boost static_visitor

I started to use the boost library a few days ago so my question is maybe trivial. I want to compare two same type variants with a static_visitor. I tried the following, but it don't want to compile. struct compare:public…
Zozzzzz
  • 183
  • 1
  • 7
3
votes
1 answer

Boost::variant could not resolve operator<< for std::ostream

I don't really understand what is going on. I'm using MSVC 2012, Boost 51. This code is expected to work fine, but it does not get compiled: #include "stdafx.h" #include #include namespace…
svv
  • 436
  • 2
  • 12
3
votes
1 answer

Boost.Spirit with Boost.Variant and C++11: Expecting a zero-argument constructor

I'm trying to compile a simple grammar using Boost.Spirit. I'm using g++ 4.7.0 and boost 1.49.0-1.1 on Arch Linux x86_64. The eventual goal here is an assembler. There will be multiple operands with one class each. All the operand types together are…
jhaberku
  • 175
  • 7
2
votes
1 answer

Forward-declared class in boost::ptr_list

for a small science project I set up a Simulation class which holds all simulated Objects in a ptr_list. Because I need to have fast access to all Particles I added an additional ptr_list. Now boost complains, because it doesn't like forward…
2
votes
1 answer

boost variant destructors results in segmentation fault

I faced a problem using a Boost variant. I have a segmentation fault when the variant gets destructed. The weird thing is that this segmentation fault occurs only when I do not activate the optimizations of the compiler (GCC in my case). For…
Baptiste Wicht
  • 7,472
  • 7
  • 45
  • 110
2
votes
1 answer

boost::variant comparison not working correctly with a nan value

So I have encountered a weird problem I have a boost variant boost::variant I doing some calculations and storing the result in the variant described above. Than I have some code where it is used like…
2
votes
1 answer

Construct a std::variant out of a boost::variant

I'm trying to construct a std::variant out of a boost::variant. In practice, I'm trying to define a function with the following signature: template std::variant boostvar2stdvar(boost::variant input); I've…
cnewbie
  • 177
  • 5
2
votes
0 answers

Boost IPC - Is it safe to use a boost::variant of PODs in shared memory?

I would love to use boost variant with boost IPC shared memory. I'm aware that one should only use pointer free items in shared memory, so was wondering if its safe to use a boost variant as a data type for shared memory. My understanding of boost…
Tom
  • 1,235
  • 9
  • 22
2
votes
1 answer

How to load a serialized boost::variant?

I'm not able to use boost::serialization because it has library dependencies so I'm trying to figure out a way to do it myself. It doesn't matter if that means copying from boost::serialization. After reading this answer to a similar question, I had…
foraidt
  • 5,519
  • 5
  • 52
  • 80
2
votes
1 answer

Boost variant with custom type failing when using custom visitor (derived from boost::static_visitor)

I am experimenting with boost::variant and printing with standard types like the below, works. typedef boost::variant myVariant; myVariant my; my = "Hello"; std::cout << my << endl; But when I introduced custom type struct…
2
votes
1 answer

Transitioning Boost Spirit parser from boost::variant to std::variant

I'm currently trying to move some code away from using boost::variant in favour of std::variant, but have run into a problem that I can't figure out. Below is a minimal test case: #include #include #include…
Tim Angus
  • 983
  • 11
  • 26
2
votes
1 answer

requirements on boost::static_visitor

I am a bit confused on the application of boost::static_visitor for variants and structures. I have included a test case below. For the commented out sections in "s_visitor", I do not understand why the following error message occurs or how to…
dan10400
  • 23
  • 3
2
votes
1 answer

using same datatype in boost variant

Can we explicitly typecast the value which is to be stored in boost varaint?? Example: typedef int abc; typedef int asd; typedef boost::variant link_try1; int main() { link_try1 qw; qw = static_cast(1234); …
ankith13
  • 371
  • 1
  • 3
  • 10
2
votes
4 answers

Variant visitor with different return types

Consider the following piece of code that uses boost::variant (but should apply perfectly well to std::variant as well). #include #include int main() { boost::variant, std::vector > vr …
Dan Tony
  • 63
  • 5
2
votes
1 answer

Boost::Variant "Error: no match for call to [...]" on visitor operator overload

I'm trying to implement a function to pass from an AST from an expression grammar to a string, and then test if it's correct comparing it with the correct string. To do that I implemented a visitor to visit a Boost::Variant variable and overloaded a…
Reynau
  • 194
  • 9