
On May 10, 2015 1:05:51 PM EDT, James Armstrong
I went ahead and modified the code to be templated over a sequence container. You can see the code here,
https://github.com/armstrhu/poly_adaptor
poly_adaptor.h defined the class and main.cpp has some code with use examples.
So, one issue is that the type erased types do not have the same methods to access their data. For instance, boost::any requires that you use a boost::any_cast<T> in order for you to get the value, whereas a boost::variant uses the get<T> function or you can access it with a stream. Basically, it will be hard to have a nice templated class for these, others, and newly developed type erased types without a common method to access the data.
Create customization points. Implement the default access method and permit customization for other types. You could provide some common specializations in separate headers so users don't always have to reinvent the same wheel.
The other thing, as you mentioned above, is that this will have to be limited to sequence containers. It would be nice to come up with something fully general, but it again comes down to methods to access data. For example, the method for getting data from an std::map is very different than from a sequence container.
There is no easy means to bridge that gap. Associative containers require a key. ___ Rob (Sent from my portable computation engine)