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

C++ Switch on Data Type

I have an Attribute class that has an Enum specifying the type of the attribute (INT_64, UINT 64, INT_32, STRING, DOUBLE, etc.). This Attribute class uses boost::any to hold a vector of the types specified by the enum. At the moment in order to work…
Samuel O'Malley
  • 3,471
  • 1
  • 23
  • 41
2
votes
1 answer

boost::spirit::hold_any memory corruption

I have a large code base that can use boost::any or boost::spirit::hold_any (depending on a macro definition). hold_any seems to be compatible with boost::any (e.g. How to print boost::any to a stream? or Type erasure - Part IV) and faster (Why you…
manlio
  • 18,345
  • 14
  • 76
  • 126
2
votes
2 answers

Boost::any reference to stored value not compiling

I'm trying to write a generic configuration class that holds parameters like this (simplified greatly): class Parameter { public: Parameter(boost::any value, bool isRequired) : value(value), isRequired(isRequired) {} bool isSet; bool…
Fadecomic
  • 1,220
  • 1
  • 10
  • 23
2
votes
1 answer

nullptr as flag value for boost::any map

If I set up a generic container map using boost::any, and use the new nullptr from C++11 as an initialization value akin to an isset() type operation, are there any potential pitfalls? For example: std::map map; map["A"] =…
Fadecomic
  • 1,220
  • 1
  • 10
  • 23
2
votes
1 answer

Boost MSM, transition won't happen despite boost::any being used as an event

I'm developing a state machine using boost MSM framework. Their tutorial states that boost::any can be used as a "Kleene event", allowing transition on any event being fired, if the current state is the source state. This doesn't work for me,…
Kikosha
  • 343
  • 6
  • 16
2
votes
1 answer

Is it possible to avoid overhead while using boost_any?

I'd like to use boost::any as a universal type to store in a container and to pass to different functions. But inside these functions I always know the real type, so in runtime I don't need any type safety checks and the imposed overhead,…
lizarisk
  • 7,562
  • 10
  • 46
  • 70
2
votes
1 answer

Is Adding boost::any in a boost::property_tree Possible?

I am trying to store a boost::any type to a boost property tree. Here is some runnable example: #include #include #include #include #include #include #include…
Subhamoy S.
  • 6,566
  • 10
  • 37
  • 53
2
votes
1 answer

use `(boost::any a)` instead of `(const boost::any& a)` to prevent reference-to-reference

First comes the definition of our new function object, contains_t. It could have inherited from the helper class std::unary_function (part of the C++ Standard Library, intended to facilitate the creation of the correct typedefs) and have the…
q0987
  • 34,938
  • 69
  • 242
  • 387
2
votes
1 answer

Can boost::any_cast(any&) be sped up?

It looks like calls to boost::any_cast(any&) call some expensive typechecking to make sure that the cast is valid. Specifically, it calls performs the following test to make sure the cast is legal: std::strcmp(operand->type().name(),…
BenRI
  • 724
  • 6
  • 17
1
vote
1 answer

C++ container of any/variant each element having unchanging type

I am using std::map to store my library's settings. Each setting only uses a single underlying value type and I want to enforce this during configuration calls to set() or similar. Settings are initialized with default…
paperjam
  • 8,321
  • 12
  • 53
  • 79
1
vote
1 answer

Recovering a function pointer from a boost::any

I want to use boost::any to store heterogeneous function pointers. I get an exception when I try to use boost::any_cast to recast to the function pointer. Is what I want to do even allowed? .h: typedef void(*voidFunction)(void); struct…
Smash
  • 3,722
  • 4
  • 34
  • 54
1
vote
0 answers

Understanding Boost::any with function parameters, pointers, and proper casting

I have a fundamental understanding of using boost::any, but I've inherited some code that perplexes me. I am trying to understand the implementation and whether there is a better/correct way to implement. Basically, I have a series of functions…
striker
  • 11
  • 1
1
vote
1 answer

Implementing boost any like class

I am trying to emulate boost::any for a toy language of mine, following the accepted answer from the following question, Accessing Values in a Class Similar to boost::any I can have, Element e1 = 11; Element e2 = 12.1; now I would like to overload…
Hamza Yerlikaya
  • 49,047
  • 44
  • 147
  • 241
1
vote
1 answer

boost::any_cast to my custom class

I'm new to some boost feature and I'm facing some issues trying to cast a reference to boost::any to a reference to a custom class (for now it's empty, I'm still figuring out the content of the class). Shortly, I have: class MyClass { public: …
XectX
  • 36
  • 4
1
vote
3 answers

boost::any compare value?

I have a vector of boost::any and would like to find the index of a 'any' in this vector. Something like this : vector values; any valueISearch = ...; find(valueISearch); For this I try to compare 2 any values with the following method : …
Spectral
  • 717
  • 2
  • 12
  • 28