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

Is it possible to create Boost multi_index MEM_FUN key extractors for a container of Boost variant?

I am attempting to implement a multi_index container of Boost::variant objects. The variant consists of two derived classes of one common base object. I have implemented a virtual function in each derived class ("extractKey()") which returns a…
0
votes
1 answer

Can boost variants safely be used with pointers to forward declared classes?

Can boost variant safely accept pointers to classes that are forward declared without any unintended implications such as using them with visitors? class A; class B; typedef boost::variant Variant; class A { public: A() {} }; class B…
Tom
  • 1,235
  • 9
  • 22
0
votes
0 answers

call arbitrary functions as First Class Functions in C++

My intention was to use arbitrary functions as First Class Variables. I used the visitor pattern (at least i think that's what that is) to achieve effectively arbitrary functions as First Class Variables. Is there a better way to achieve…
0
votes
1 answer

Boost::variant with a object which references the same variant

How can I have a variant of different objects A, B, C where C has a reference to the variant? class A { ... }; class B { ... }; class C { ... std::vector storage; // reference to variant ... }; boost::variant
Tom
  • 1,235
  • 9
  • 22
0
votes
1 answer

How to change raw pointer to unique_ptr in container of pointers wrapped by boost::variant

Live code example I am trying to hold a variant of pointers to templated versions of a base class in a vector. The boost::variant of pointers happens to be contained in a struct. It works fine if these pointers are raw pointers, but things start…
tomocafe
  • 1,425
  • 4
  • 20
  • 35
0
votes
1 answer

how to set a value for parameter of type boost::varivant * to be equal to some A*?

say I have class A { }; class B { }; using AOrB = boost::variant ; A* ptr2a = .... AOrB* another_ptr2a = a;//this doesn't compile for me, what is the correct way to do it? is using boost::variant* a bad practice?
0
votes
1 answer

boost::variant - simplest way to apply arithmetic on variants

recently I have been experimenting with boost::variant. I am attempting to apply arithmetic to two variant objects of types as such: typedef boost::variant VariableValue; VariableValue var1 = 2; VariableValue var2 =…
Tom
  • 1,235
  • 9
  • 22
0
votes
1 answer

Does std::variant provide functionality similar to boost::variant<>::types?

boost::variant exposes its list of variant types via boost::variant<>::types, which can be conveniently used with boost::mpl::for_each. std::variant is missing such a member. I see std::variant_alternative is provided. Can this be used to produce a…
Braden
  • 1,448
  • 10
  • 11
0
votes
0 answers

boost::apply_visitor and lvalue reference

Is it safe (I wonder about lifetime of x): boost::apply_visitor([this](const auto& arg) { someClass.method(arg); }, x); apply_visitor takes lvalue reference (non-const) but lambda has const auto& so is it safe?
peter55555
  • 1,413
  • 1
  • 19
  • 36
0
votes
1 answer

google test EXPECT_EQ and boost::make_recursive_variant

I have a boost recursive variant as below. When I compare two recursive variant object using assert, it works fine but with EXPECT_EQ, it gives compile error. typedef boost::make_recursive_variant
rjoshi
  • 1,645
  • 1
  • 20
  • 31
0
votes
1 answer

apply_visitor does not change object

I have inherited from boost::static_visitor<> and defined a class as follows: class move_visitor : public boost::static_visitor<> { private: double m_dx, m_dy; public: move_visitor() : m_dx(0.0), m_dy(0.0) {} move_visitor(double dx,…
Mutating Algorithm
  • 2,604
  • 2
  • 29
  • 66
0
votes
1 answer

C++ Templates access a function with different types

So What I'm trying to do is something like this. I have a template struct like this one: template struct TemplateTest { void test(T a) { switch (typeid(boost::any_cast(a))) { case typeid(int): …
Vali
  • 629
  • 2
  • 6
  • 14
0
votes
1 answer

Adding debugging facilities to boost variant visitor

I'm using boost-variant throughout my projects and I'm considering it to be one the most useful and versatile tools of boost. But if it comes to complicated use of the visitor pattern with recursively nested variants the debugging is sometimes…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
0
votes
1 answer

Compiler Warning 4456 using VS 2015

If I compile the following small programm with Visual Studio 2015, I get the following compiler warning in line 9: warning C4456: Declaration of "iter" shadows previous declaration This is my small program: #include #include…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
0
votes
1 answer

How to resolve an apply_visitor within another static_visitor in boost::variant?

I get a compiler regarding apply_visitor within the current operator. I tested all the apply_visitor outside of that method and it works perfectly fine. Just when trying to use it within that method it runs into a bunch of issues. The error…
Leruce
  • 187
  • 1
  • 8