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
68
votes
3 answers

How do boost::variant and boost::any work?

How do variant and any from the boost library work internally? In a project I am working on, I currently use a tagged union. I want to use something else, because unions in C++ don't let you use objects with constructors, destructors or overloaded…
salvador p
  • 2,905
  • 5
  • 26
  • 26
56
votes
1 answer

Boost.Any vs. Boost.Variant

I'm having trouble choosing between Boost.Any and Boost.Variant. When should I use each one? What are the advantages and disadvantages of each? I am basically looking to store some states from external sources.
the_drow
  • 18,571
  • 25
  • 126
  • 193
22
votes
4 answers

Does C++11 standard provide something like boost::any?

for example boost::function is moved almost entirely to std::function, the same is with boost::shared_ptr But I can't find std::any? Was it renamed or was not it placed in new standard at all by any reason?
dev_null
  • 1,907
  • 1
  • 16
  • 25
20
votes
9 answers

How to print boost::any to a stream?

I have a Map std::map, which comes from the boost::program_options package. Now I would like to print the content of that map: for(po::variables_map::const_iterator it = vm.begin(); it != vm.end(); ++it) { std::cerr <<…
Frank
  • 64,140
  • 93
  • 237
  • 324
13
votes
4 answers

C++ - boost::any serialization

As far as I understand, there is no serialization (boost::serialization, actually) support for boost::any placeholder. Does someone know if there is a way to serialize a custom boost::any entity? The problem here is obvious: boost::any uses…
Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148
9
votes
2 answers

Building boost::options from a string/boost::any map

I have a map which represents a configuration. It's a map of std::string and boost::any. This map is initialized at the start and I'd like the user to be able to override these options on the command line. What I'd love to do is build the program…
Moo-Juice
  • 38,257
  • 10
  • 78
  • 128
9
votes
2 answers

Use of typeid to handle different types

I am trying to use boost::any to encapsulate the sqlite return values. I then tried to write a loop to print these. My first thought was to do something like: for(boost::any field: row) { switch(field.type()) { case typeid(double): …
ted
  • 4,791
  • 5
  • 38
  • 84
8
votes
5 answers

Compare boost::any contents

I am using a container to hold a list of pointers to anything: struct Example { std::vector elements; } To insert elements in this container, I had written a couple of helper functions (members of the struct Example): void…
d83
  • 195
  • 1
  • 1
  • 8
7
votes
2 answers

Boost any usage

how can I insert my own class objects into ptr_map from boost. The objects are templated so I can't use some static typename in the map. So I did: ptr_map someMap; My class inherits the boost::noncopyable. someMap.insert("Test", new…
Max Frai
  • 61,946
  • 78
  • 197
  • 306
7
votes
1 answer

How can I see a value of boost::any if I know the type with gdb

I have a core dump and I am looking at the core dump with gdb. I was wondering if there is a way to be able to examine the value of a boost::any value in gdb? In the core, I had the address to the boost any and so I tried casting it to a placeholder…
bbazso
  • 1,959
  • 6
  • 22
  • 30
7
votes
2 answers

Obtain void* pointer to content of boost::any

I am using an external library that has a method which accepts a void* I want this void* to point to an object contained within a boost::any object. Is it possible to get at the address of the content of a boost::any object? I'm trying to play with…
user1488777
  • 125
  • 4
6
votes
1 answer

how to use boost::any_cast to cast to base types?

I am using boost::any to have polymorphic types, I need to be able to cast an object to its base type. class A { public: int x; virtual int foo()= 0; }; class B : public A { public: int foo() { return x +…
Michel
  • 163
  • 1
  • 2
  • 7
6
votes
5 answers

How can I pass "Any kind of data" to a function in C++

Lets say I have a class Handler with some subclasses like stringhandler, SomeTypeHandler, AnotherTypeHandler. The class Handler defines a method "handle" as a common interface for all the subclasses. The logic to "handle" is ofcourse completely…
W. Goeman
  • 1,674
  • 2
  • 15
  • 31
5
votes
2 answers

How do I initialize boost::any with a reference to an object?

I want to store a reference to an object in a boost::any object. How do I initialize the boost::any object? I tried std::ref(), but boost::any gets initialized with std::reference_wrapper<>. For example, the following #include…
keveman
  • 8,427
  • 1
  • 38
  • 46
5
votes
1 answer

Better handling of missing/wrong key in boost::program_options

Is there a way to know which key was involved when a call like the following fails ? boost::program_options::variables_map vm; ... int foo_bar = vm["some_key"].as(); If the key is missing from the map, or is not convertible to int, I get a…
Marco Righele
  • 2,702
  • 3
  • 23
  • 23
1
2 3 4 5 6 7 8