From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-06-03 08:08:37
I think for a general case, it would be better to have a virtual function "visit" that receives a visitor functor whose type is templated by the template parameter of the "templated any type", runs the functor on the data of the holder, and returns the resultant functor. This also frees the user from having to know the details of how the any is implemented. All they have to know is that the visitor functor handles the operation to be done. Using switch-case it is possible to use this functor to perform any number of operations (tell the functor what type of operation it is in the constructor, and later switch on this enum type value, to perform the right operation).
Perhaps it would be possible to be more fancy and use typelists, "any" would receive as the template parameter a typelist of visitor functor types, and implement the above for each of the possible functor types in the list (depending on which types it got in the typelist). The default "any", in this case, uses just the empty typelist.
Besides, I think your use of friend templated parameter types is not standard, according to what I read here: http://groups.yahoo.com/group/boost/message/23877
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk