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

Visit boost variant with extra arguments

I am trying to implement the Tseitin transformation over boolean formulas. The idea is that you transform boolean formulas in CNF, using transformation rules. For example, if the formula f = l OR r, we assign to each formula a new variable, let's…
3
votes
1 answer

How to return Template Value from boost::apply_visitor?

The following code correctly spits out the values 999 and "test" to the console but how do I return these values instead? Something like the commented line was my ultimate goal; return the value that I can then assign to an auto variable (since I…
jslmsca
  • 196
  • 1
  • 14
3
votes
1 answer

boost variant copy semantics

I was wondering what the copy semantics of boost variants are. I've checked the source code and it's a bit baffling to me so I was wondering, in the example code, if my getVal(name) function makes a copy of the underlying vector when it's returned?…
pezpezpez
  • 654
  • 8
  • 15
3
votes
2 answers

Is this visitor implementation correct?

I am implementing a visitor in order to use it with the boost variant library. I want to know if is correct to specialize boost::static_visitor<> with a const reference type. Note my question here is the following: There are any problem specializing…
3
votes
1 answer

C++ boost::spirit::karma rule for variants

I have a boost::variant in my program that takes types of double, uint16_t, std::string, etc. I'm storing these and I'd like to use boost::karma to generate/print them out. I'm new to boost::spirit, but I understand it works well with variants. What…
Kevin
  • 16,549
  • 8
  • 60
  • 74
3
votes
2 answers

Adding member functions to a Boost.Variant

In my C++ library I have a type boost::variant 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& var ). I know that this can also be…
Mathias Soeken
  • 1,293
  • 2
  • 8
  • 22
3
votes
1 answer

Having a static_visitor modify a Boost recursive variant while traversing it?

I am using Boost's variant type extensively to build trees. More precisely, I parse a tree from a grammar using Boost's Qi, and then I traverse the tree to annotate each node with an integer - at least that is what I want to do. I just realized that…
Jérémie
  • 1,353
  • 9
  • 19
3
votes
1 answer

decltype and boost::variant - retrieve current value

I have the following code: #include #include #include boost::variant variant; template auto bar(const std::type_info& variant_type_info)…
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
3
votes
2 answers

QVariant vs boost::any vs boost::variant

I need efficient way to store values of different types (int, float, QString or std::string, bool) in one of "generic" containers like QVariant. I want to archive less memory usage. I prefer a container that doesn't store type of the internal value…
tmporaries
  • 1,523
  • 8
  • 25
  • 39
3
votes
2 answers

Implement an object directory: boost::any, boost::variant, or?

I'd like to implement a directory object which stores different types of object. Need to be able access the objects by name, get the actual pointer type and serialize it. The object I have in mind looks like this: struct Object { std::string…
surfcode
  • 445
  • 1
  • 5
  • 20
3
votes
2 answers

Reading a boost::variant type from istream

I was going through boost::variant and wondering how can I make following to work ? typedef boost::variant myval; int main() { std::vector vec; std::ifstream fin("temp.txt"); //How following can be achieved…
P0W
  • 46,614
  • 9
  • 72
  • 119
3
votes
1 answer

Boost::variant with unordered map

Can someone tell me, how I can get boost::Variant work with unordered map? typedef boost::variant lut_value; unordered_map table; I think there is a hash-function for boost::variant missing, am I right? The…
moo
  • 486
  • 8
  • 22
3
votes
1 answer

using apply_visitor to filter from vector of variant

Yesterday I asked this question and "juanchopanza" answered my question, but unfortunately I cant caught one of bounded types. Since using a "visitor" is more robust, I'm also wondering of anyone could give me a solution using "visitor"? I am…
H'H
  • 1,638
  • 1
  • 15
  • 39
3
votes
1 answer

Is there a significant impact of the new standard's features on the boost library implementation in C++11?

Is there a significant impact of the new standard's features on the boost library implementation in C++11? Especially interested in boost::variant (BOOST_VARIANT_LIMIT_TYPES) and boost::spirit parts of the library in light of the presence of…
Tomilov Anatoliy
  • 15,657
  • 10
  • 64
  • 169
3
votes
2 answers

why is std::vector of boost::variant causing parsing issues in boost spirit?

Expanding on this earlier post, I thought I would try to capture a std::vector> instead of just boost::variant, but starting with the same-old-inputs first. Here is my output given inputs 'foo'…
kfmfe04
  • 14,936
  • 14
  • 74
  • 140