Questions tagged [boost-any]

Boost.Any is a C++ library that offers a safe, generic container for single values of different value types.

Boost.Any is a C++ library that offers a safe, generic container for single values of different value types.

118 questions
1
vote
2 answers

Different key type in a map

for a particular requirement I want to have a map with keys in different type. Similar to boost:any. (I have an old gcc version) map aMap; //in runtime : aMap[1] = "aaa"; aMap["myKey"] = "bbb"; is this something possible with the…
1
vote
0 answers

variable return type in function that returns held object of boost::any

Say I have a class C with a field of type std::vector. I have index operator const boost::any C::operator[](const size_t i); but what if I wanted C::operator[](const size_t i) to return the object held by the any object at index i rather…
lo tolmencre
  • 3,804
  • 3
  • 30
  • 60
1
vote
1 answer

Why don't the any_cast function overloads cause ambiguity?

Boost's has: template ValueType any_cast(any & operand); template inline ValueType any_cast(const any & operand); (among other variants.) Shouldn't this combination cause ambiguity in calls…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
vote
0 answers

Helper Function to extract values from boost::variant inside a boost::any

I'm using different boost::variant types throughout my projects. For example I have typedef boost::variant TA; typedef boost::variant TB; typedef boost::variant TC; In order to transport these different boost::variant…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
1
vote
1 answer

Does std::any employ type erasure, sub-typing, or polymorphism?

While reading the documentation on boost any and experimental any, I did not see any mention of type erasure. I'm trying to understand the concept of "type erasure" as it applies to C++. Is it correct to say that the "any" type uses "type…
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
1
vote
2 answers

boost::any, variants, calling functions based on arrays of them

Given a set of functions, such as: template Void Go(A1 a); template Void Go(A1 a1, A2 a2); template Void Go(A1 a1, A2 a2, A3 a3); Is it possible to take an array of some variant type and…
Robinson
  • 9,666
  • 16
  • 71
  • 115
1
vote
1 answer

boost::any constructors - const type overload resolution

boost::any has a perfect forward constructor declared as: template any(ValueType&& value , typename boost::disable_if >::type* = 0 // disable if value has type `any&` , typename…
tukra
  • 921
  • 8
  • 13
1
vote
1 answer

How to print a vector of boost::any, when i have the element types stored in another vector of strings?

I'm using a vector of boost::any to store different data types, to construct a symbol table from a given program file. I'm also storing their datatypes in a separate vector as strings. while trying to print the boost::any using…
Tauseef
  • 55
  • 10
1
vote
1 answer

Type un-erasure from a boost::program_options value

I'm trying to retrofit my program with boost::program_options. Among other things, I've written a function which I just can't get to compile. Here's a sort-of-minimal .cpp file which fails compilation: #include template…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
vote
1 answer

template copy constructor in boost::any

template copy constructor in boost::any I am confused with these codes in any.hpp of boost. template any(const ValueType & value) : content(new holder< BOOST_DEDUCED_TYPENAME…
izual
  • 247
  • 1
  • 2
  • 6
1
vote
1 answer

How to get a const reference to data held by boost::any?

I am having trouble maintaining const correctness after trying to retrieve a boost::any instance through boost::any_cast reference casting. My code: MyMap paramMapToSet; MyMap& paramMap = ¶mMapToSet; const MyMap& constParamMap =…
MatrixAndrew
  • 265
  • 3
  • 13
1
vote
1 answer

Storing objects in the array

I want to save boost signals objects in the map (association: signal name → signal object). The signals signature is different, so the second type of map should be boost::any. map mSignalAssociation; The question is how to store…
Max Frai
  • 61,946
  • 78
  • 197
  • 306
1
vote
1 answer

Polymorphism, variadic template inheritance, slicing, boost::any type cast

This program compiles, but the boost::any cast fails. I suspect that slicing a template class this way confuses pointer arithmetic. The idea is that what is stored in the container std::vector pressures; are of different types, for…
Ivan
  • 7,448
  • 14
  • 69
  • 134
1
vote
1 answer

Trying to learn BOOST::ANY Q1

This program segfaults on the call p->Change(1999); When I run it in the debugger, it appears that I enter the Change function, but on inspecting the this pointer is 0x00. I am obviously using BOOST::any incorrectly, but I am not sure what I am…
Ivan
  • 7,448
  • 14
  • 69
  • 134
1
vote
1 answer

Boost::any assign string value

IDE - Clion, C++11, Boost Version 1.57.0 Why doesn't work this code? #include "boost/any.hpp" ... boost::any var = 1550; // Works var = "String"; // Error But works fine this one: #include "boost/any.hpp" ... boost::any var = 1550; //…
Person.Junkie
  • 1,816
  • 4
  • 21
  • 31