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

Using boost::visitor with a boost::variant of unique_ptr

I have two types of std::unique_ptr which are held inside a boost::variant. I'm trying to write a subclass of boost::static_visitor to extract a const reference to to the underlying object the two unique_ptr variants my boost::variant is templated…
MattyZ
  • 1,541
  • 4
  • 24
  • 41
2
votes
1 answer

'boost::detail::variant::visitation_impl': none of the 2 overloads could convert all the argument types

I'm not able to build two of my projects with Boost libraries 1.61.0 and Visual Studio 2015 Update 3. These projects used to build fine for years with various combinations of Visual Studio and Boost versions, and I didn't change anything in my code…
2
votes
3 answers

Get boost::variant's type index with boost::mpl

boost::variant has member types which is some kind of boost::mpl structure. Is there a way to get an index of type in that structure at compile time, so late in in runtime i could do if(myVariantInstance.which() == typeIndex) { /*...*/ } Instead…
K117
  • 118
  • 1
  • 7
2
votes
1 answer

Boost variant visitor with variadic template arguments

In one of my projects I'm actively using boost::variant and I stumbled upon a question I couldn't resolve on my own. I have a boost::variant that might contain atomic datatypes and STL containers of these atomic datatypes. Now, I wanted to compute…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
2
votes
1 answer

Increment boost::variant value

I have a variant variable where the different types all implement operator++. I would like to apply incrementation directly on the variant variable. Is there an easy way to do that ? Or have I to apply it in a switch on each type ? Simple example…
Caduchon
  • 4,574
  • 4
  • 26
  • 67
2
votes
1 answer

Forward boost::variant from a visitor to another

I want to call a visitor on a boost variant from inside another visitor. Consider the following code: struct visitor1 : boost::static_visitor<> { void operator()(const int& i) const { std::cout << "visitor1:" << i; } void operator()(const…
0xFF
  • 4,140
  • 7
  • 41
  • 58
2
votes
0 answers

Is there a way to get Boost Variant's types vector (recursives expanded)

Boost Variant class has a member type types. Its a Boost MPL Sequence for types used in template parameters. In the recursive cases such as : typename boost::make_recursive_variant>::type; will create a…
2
votes
2 answers

Using Boost assign to initialize JSON-like map with variant values

I'm looking for a way to store the JSON structure { "foo" : "FOO" , "fuu" : "FUU" , "bar" : { "no" : "abc" , "yes" : "ABC" } , "baa" : { "no" : "xyz" , "yes" : "XYZ" } } as a…
Olumide
  • 5,397
  • 10
  • 55
  • 104
2
votes
2 answers

Iterate std::list

How would you check for the object type when looping std::list? class A { int x; int y; public: A() {x = 1; y = 2;} }; class B { double x; double y; public: B() {x = 1; y = 2;} }; class C { float x; float y; public: C() {x…
cpx
  • 17,009
  • 20
  • 87
  • 142
2
votes
4 answers

boost::variant implicit cast to string

I have a boost::variant with different types, where one is a (const) void pointer and another a string. boost::variant; The problem is, if i want to use it with a c-string it casts it to the void pointer instead the…
user1810087
  • 5,146
  • 1
  • 41
  • 76
2
votes
2 answers

How to iterate through a sequence of bounded types with Boost.Variant

struct A { std::string get_string(); }; struct B { int value; }; typedef boost::variant var_types; std::vector v; A a; B b; v.push_back(a); v.push_back(b); How can I iterate iterate through the…
anno
  • 5,970
  • 4
  • 28
  • 37
2
votes
2 answers

boost::variant as friend class

For a type Foo, which I want to use in a boost::variant, I wanted to set the default constructor to private, since it only should be allowed to be called by boost::variant. Sadly I could not yet figure out the declaration magic of boost::variant and…
abergmeier
  • 13,224
  • 13
  • 64
  • 120
2
votes
1 answer

Possible bug in boost visitation

I have the following error message: /usr/include/boost/variant/detail/visitation_impl.hpp:207: typename Visitor::result_type boost::detail::variant::visitation_impl(int, int, Visitor &, VPCV, mpl::true_, NBF, W *, S *) [W = mpl_::int_<20>, S =…
justanothercoder
  • 1,830
  • 1
  • 16
  • 27
2
votes
1 answer

Const Boost Variant with Pointer types in a map

i am searching for a way to store different type of pointers in a map without using void* for obvious reasons. I actually know the types of the pointers at compile-time and these pointers as well as their types need to be const while their values…
2
votes
1 answer

Storing function pointers with different types c++ boost::bind

I have dug around quite a bit today and have come up empty. Is there any way to store a functor that is returned from a boost::bind with different types? I found an example that used boost::variants but not sure that this is needed. (Foo and Bar…