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

boost::any with limited type support

I wish to have a type that acts similarily to boost::any but with a more limited type set. Something like this: limited_any x; // x is like boost::any but is guaranteed to contain only an int, a long, or a string How would you…
tohava
  • 5,344
  • 1
  • 25
  • 47
3
votes
1 answer

Cast boost::any instance to its real type

I recently started to use Boost C++ library and I am testing the any class which can hold any data type. Actually I am trying to define the operator<< to print easily the content of any variable of type any (and sure, the class of the content should…
webNeat
  • 2,768
  • 1
  • 20
  • 22
3
votes
2 answers

boost::any_cast(const any&) uses const_cast<> -- Isn't this potentially UB?

boost/any.hpp (version 1.55) defines (line 263) template inline const ValueType * any_cast(const any * operand) BOOST_NOEXCEPT { return any_cast(const_cast(operand)); } However, using const_cast<>, may…
Walter
  • 44,150
  • 20
  • 113
  • 196
3
votes
2 answers

QVariant vs boost::any vs boost::variant

I need efficient way to store values of different types (int, float, QString or std::string, bool) in one of "generic" containers like QVariant. I want to archive less memory usage. I prefer a container that doesn't store type of the internal value…
tmporaries
  • 1,523
  • 8
  • 25
  • 39
3
votes
2 answers

Implement an object directory: boost::any, boost::variant, or?

I'd like to implement a directory object which stores different types of object. Need to be able access the objects by name, get the actual pointer type and serialize it. The object I have in mind looks like this: struct Object { std::string…
surfcode
  • 445
  • 1
  • 5
  • 20
3
votes
2 answers

Is it possible to use Boost Program Options without RTTI?

I would like to disable RTTI in a project of mine. However, this project uses Boost Program Options which itself depends on Boost Any which does not support -fno-rtti. I was wondering if there was any solution to use Boost Program without RTTI ? By…
Baptiste Wicht
  • 7,472
  • 7
  • 45
  • 110
2
votes
1 answer

Is there a way get an integer out of boost::any if you don't know if original type was signed or unsigned

I'm using boost::any in combination with boost::any_cast<> to write some framework code which should take a set of arguments, almost like a function call, and convert them into an array of boost::any types. So far everything has been working great,…
DXM
  • 4,413
  • 1
  • 19
  • 29
2
votes
1 answer

Using std::memcpy to copy an object that contains a boost::any data member

I am trying to pass an object that contains a boost::any data member through a networking API to exchange data between two applications. I know that the API uses memcpy internally to copy the data, but I'm not sure if what I am trying to do is…
tjwrona1992
  • 8,614
  • 8
  • 35
  • 98
2
votes
2 answers

Why doesn't boost::any have a "getter"?

Using boost::any is very useful but it's very depressing that it has no getter, and always we have to use any_cast for casting it to type we want. But why it has no such thing? In my opinion the one bellow can be useful member. Is there some bad…
Mihran Hovsepyan
  • 10,810
  • 14
  • 61
  • 111
2
votes
2 answers

Error C2451 using boost::any

class A { public: void f() { cout << "A()" << endl; } }; class B { public: void f() { cout << "B()" << endl; } }; class C { public: void f() { cout << "C()" << endl; } }; void…
Adrian
  • 19,440
  • 34
  • 112
  • 219
2
votes
4 answers

c++ boost::any to define my own print ,

Am struggling a lot to find how to do to use boost::any to create a print function that can print any type using template first. template struct printer { void print(ostream& os, const boost::any& a); }; I need to define first…
2
votes
1 answer

Is it possible to use boost::any or boost::variant with a boost::pool?

boost::any: I tried to compile and run the following code to test this: #include #include int main() { boost::object_pool pool; boost::any *i = pool.malloc(); *i = 1; boost::any *j =…
wizurd
  • 3,541
  • 3
  • 33
  • 50
2
votes
1 answer

Boost Any to Boost Variant using Boost Preprocessor

In my projects I'm using boost::any and boost::variant exhaustively. For this a general conversion routine from boost::any to boost::variant was devised in my previous question Generic function to convert boost::any to boost::variant. Many thanks to…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
2
votes
3 answers

Polymorphic operator on a list of boost::any?

Suppose I have a list of type list that has some type in it that is unknown. Now suppose I want to apply some operation to the elements in the list that is polymorphic. In this case, consider the + operator. Suppose that I know that the…
Derek Thurn
  • 14,953
  • 9
  • 42
  • 64
2
votes
1 answer

Is there a way to remember(store) the return type of decltype?

I am storing the return values of a function call like this in a std::vector: This is a very rough estimate std::vector pressures; Printer printerObs1; Printer printerObs2; const int initialPressure = 1; auto pressure =…
Ivan
  • 7,448
  • 14
  • 69
  • 134