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

How to get around matching Boost Variant return types?

Linked Question Suppose we have: boost::variant And, struct string_struct { string_struct(std::string const& name = "") : name(name) {} std::string name; } Is there some way to prevent the compiler from…
Dylan_Larkin
  • 503
  • 4
  • 15
0
votes
1 answer

No match for operator * when using boost::variant

I define my own variant type like so: typedef variant VariantData; One of my class methods gets this data type as a parameter and tries to do something like: void MyMethod(VariantData var){ //method body …
Jacobian
  • 10,122
  • 29
  • 128
  • 221
0
votes
1 answer

boost::variant with reference bounded type, not able to assign a value

I have a boost::variant: B is an incomplete type so I have two possibilitys to declare my variant typedef boost::variant vari; // this works typedef boost::variant vari; // this works also But now I have the following…
Ventu
  • 780
  • 1
  • 12
  • 25
0
votes
1 answer

how to implement arithmetic operator for boost::variant so that it supports different numeric types

For example, if I have the following variant and a static_visitor: typedef boost::variant DataType; And I'd like this to work: DataType x(1.2); DataType y(100); std::cout<
swang
  • 5,157
  • 5
  • 33
  • 55
0
votes
1 answer

Need pointer to example where apply_visitor() returns a value

My application uses variant as a data bucket to carry data from one object to another. The examples I've seen of using apply_visitor() to extract the bound data have void operator() so apply_visitor(), itself, doesn't return anything. Can anyone…
0
votes
2 answers

Get int from boost::variant generate segmentation fault

I am trying to get int value from boost::variant. Code generate segmentation fault - why? I put comments in code which lines generate error. I supposed that int numberInt = boost::get(v); will not working correctly so I changed it to int…
user2856064
  • 541
  • 1
  • 8
  • 25
0
votes
1 answer

Using std::vector, boost::variant, and types with reference fields together

I have the following two classes: struct A { A() : state(0) { } A(int state_arg) : state{ state_arg } { } int state; }; struct B { B(int state_arg, const int& ref) : state{ state_arg }, ref{ ref } { } int…
0
votes
1 answer

2-D vector of boost::variant in C++

I'm looking to store information from a data table with multiple rows and columns. Each column houses a differing type (int, double, std::string, etc), which would only be known at runtime. Is a 2-d vector of boost::variant the best way, or are…
Kevin
  • 16,549
  • 8
  • 60
  • 74
0
votes
1 answer

Representing JSON data in C++ using Boost Variants

I wrote the following code to represent JSON data in C++. I got some vague review comments that this may not be optimal and if we decide to parse JSON data directly into this structure then we might have trouble. I did not quite get the terse…
CppNoob
  • 2,322
  • 1
  • 24
  • 35
0
votes
2 answers

C++ boost::variant generic converter

I've been trying for the last three day to figure out how to implement a generic way of getting the value out of a boost::variant<...>, but it's been quite difficult. Here is the solution I could come up with, which it not at all generic: #include…
Bruno Santos
  • 724
  • 7
  • 19
0
votes
2 answers

Template isn't resolving type to correct overload

This is on Visual Studio 2010, utilizing Boost v1.48.0. I'm trying to get a boost::variant with some structs and shared pointers to structs to match the right members of a boost::static_visitor, without success... For my problem, let's establish…
Matthew Reddington
  • 1,409
  • 3
  • 13
  • 24
0
votes
0 answers

Retrieve data from boost::variant using static visitor

I have a static visitor setup like this struct visitor : public boost::static_visitor { obj& m_data; visitor(obj& data) : m_data(data) {} std::string& operator()(key_type_1& k1) const { return m_data.get(k1); } std::string&…
0
votes
1 answer

How to get a pointer to boost::variant's storage?

I have a use case where I'd like to process the element contained within a boost::variant without regard to its type. Is there a way to get a pointer to the variant's data without knowing the element's type?
Jared Hoberock
  • 11,118
  • 3
  • 40
  • 76
0
votes
1 answer

boost::variant, shared-ptr error in assignment

I'm have the following elements: #define TEMPLATE_PARAM boost::variant&, const std::vector&, const ITemplateLoop*, const std::vector&> class PostParam { ... const…
Alexis
  • 2,149
  • 2
  • 25
  • 39