
From: "Yuval Ronen" <ronen_yuval@yahoo.com>
Wouldn't it be nicer if class any will have a member method like:
template <typename T> T get() const;
or maybe even:
template <typename T> const T& get() const; template <typename T> T& get();
So you'd prefer writing this:
boost::any<...> a(...); int i(a.template get<int>());
to this?
boost::any<...> a(...); int i(any_cast<int>(a));
The latter has the advantage of looking just like static_cast et al, avoiding the ugly template qualification of the member function invocation, and being shorter.
I blieve this a matter of point of view. I think of it as "extracting the inner object" within the any object, so get() sounds more intuitive. I'd much rather writing something like: int a = some_any.get<int>();
But you can't. You have to write the following, as I showed above: int a = some_any.template get<int>();
You think of it as a cast so any_cast sounds better to you. My guess that neither of us will be able to convince the other, so I'll suggest some sort of compromise: why don't we have both?
Do you still like your version? Yes, I think cast fits quite nicely, but I hate forcing the use of the "template" qualifier in function calls when I can avoid it. -- Rob Stewart stewart@sig.com Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;