What are the advantages of using boost.any library ? Could you please give me some real life examples ? Why the same functionality couldn\'t be achieved by having some gener
We use boost.any as the carrier type for a type-safe tagged variadic container. Here's what that means:
We have a "raft" object, which travels through a set of filters. When a filter wants to add data to the raft, it can do something like this:
raft.addTaggedData(3.0);
raft.addTaggedData("a string")`;
std::string str = raft.getTaggedData();
int a = raft.getTaggedData(); // <-- Compile error
Where ETag1
and ETag2
are members of an enum, and we use a traits template to map tags to types.
The raft class is using a list
of pair
as a backing store. Boost.any saved us the pain of managing raw buffers for various types.