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
0
votes
2 answers

boost library and held value

I have been using boost for a while but am still a novice. I think I fall for boost::any as I don't need to use template much anymore to handle typed objects used or returned. Yet one thing I find it still inconvenient to me is a smoother function…
Mikhail Lucas
  • 11
  • 1
  • 5
0
votes
1 answer

Casting from any

I'm packing some classes into ptr_map with any typed value. class EventManager { ptr_map mSomeMap; public: typedef signals2::signal KeyEvent; EventManager() { …
Max Frai
  • 61,946
  • 78
  • 197
  • 306
0
votes
1 answer

How to return different types from same function?

For study purpose, I make own Any type. I don't understand, how to return Type or Type * depending on the conditions. This is my sketch of class: class any { public: template any(T & d) { data_container = new…
Denis
  • 3,595
  • 12
  • 52
  • 86
0
votes
1 answer

Why is Boost.Any an application of Adapter pattern?

Why is Boost.Any an application of the Adapter pattern? Who would be the Adaptee? I'm confused. Thanks!
user3020233
  • 327
  • 3
  • 10
0
votes
1 answer

C++ Generic Data Type

Whats the best approach to a fast generic data type in C++. I have an event system that needs to be able to pass event information around the program. sendEvent(123, "a String", aFloat, aVec3, etc); // sendEvent(EventID, EventArg, EventArg…
user245019
0
votes
2 answers

set/access jagged map values made with map

I've been shown how to create a jagged multidimensional std::map by using boost::any. However, I'm having trouble setting the values like in this answer. When I use accounts["bank"]["cash"] = 100; gcc gives this error error: no match for…
user1382306
0
votes
7 answers

Can I avoid all this multiples try/catch

I have a vector of many boost::any In this vector I need to perform some operations on std::vector and on the elements of type IContainer class IContainer { public: virtual ~IContainer(){} virtual const boost::any operator[](std::string) const…
Alexis
  • 2,149
  • 2
  • 25
  • 39
0
votes
2 answers

Is it a good idea to use boost::any?

I'm developing a few image-processing algorithms in C++. To make my code more generalized and to be able to configure everything without recompiling the whole project I've came up with an idea to split the processing algorithms into small parts…
lizarisk
  • 7,562
  • 10
  • 46
  • 70
0
votes
1 answer

boost::any number cast

I put positive 'int' to my any variable. Then I am trying to cast it to 'unsigned long'. And I got an exception about bad any cast. How I can make the use of 'boost::any_cast' more flexible conserning integer data.
user14416
  • 2,922
  • 5
  • 40
  • 67
0
votes
1 answer

convert ‘double*’ to ‘boost::any*’

I have a variable boost::any* items. My requirement is to: assign items with list of values which can be of type int,double or any other datatype. But at a given time the data-type will be unique. The issue: For single values i can assign using…
Pinaki
  • 1
  • 1
0
votes
4 answers

single get method which return different type variables

I want to make a class that will have a single get template method which will receive an std::string to find in a std::map the right variable and return it. The std::map should store any type of variable, so I used boost::any, so far the std::map…
Sassa
  • 1,673
  • 2
  • 16
  • 30
-2
votes
1 answer

How do I get the name of the type currently held by an `any`?

Suppose I have either: A boost::any or An std::any (and I'm using C++17) the type of which I don't know. Is it possible for me to print, or get as a string, the name of the type that's being held by the any? Note: Even a mangled type name - the…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
-4
votes
1 answer

boost::any_cast and std::optional's

I use boost::any, and have some function which retrieves such a value, but may fail, so it actually returns std::optional (well, for now it's std::experimental::optional). Now, without the optional, I get my typed value back using…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1 2 3 4 5 6 7
8