From: Peter Dimov (pdimov_at_[hidden])
Date: 2000-09-01 12:24:51
> >Yes, I see. So copy_to() can be implemented in terms of the public
> >of 'any' (to_ptr). Wouldn't this make it a candidate for a free function?
> Not really. Free functions are not that free: they are still part of the
> interface, so the interface is the same size, and if applied
> inappropriately they make the code harder not easier to follow. In this
> case the simplest place to put it is in the public interface.
Having copy_to as a free function makes it easier for somebody to make it
work with, say, ref<void> instead of any.
> As another point, I intend for the hacked VC6 version to not offer
> to_ptr and offer any_cast and copy_to as the sole means of accessing the
Don't do this. :) Look at the ref::is<T> workaround.
> >But note that the first example is already supported by ref<> (its op<
> >compares the types of the two objects)
> From what I can see, ref<> compares content and not type. It would be
> counterintuitive for it to compare types not values using < and ==,
ref<>'s operators compare types; if the types are equal they invoke the
corresponding operator on that type, supplying a default in the case where
no such operator is defined for the type.
So when you std::sort a vector of ref's, the contents are sorted by type,
then by value.
> >I was thinking of an example that
> >demonstrates the need for the type_info() function.
> Toy examples have to be liberalised a little to get the full effect, but
> the point is that not everything can be done with compile-time binding,
> which is what to_ptr offers, and some things need runtime binding, which
> is what type_info offers.
> Taking a step back, I would find it odd that a type that can hold
> anything and knows what it holds is gagged from being able to tell you
> its content!
Indeed. However, you can't do anything generic with an 'any', regardless of
whether you have its type_info or not, except getting its name() (which is
That's why I asked for an example that clearly demonstrates that the ability
to ask an 'any' for its type_info is a part of the minimal interface. So,
what are those things that need runtime binding? :)
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk