|
Boost : |
From: Darin Adler (darin_at_[hidden])
Date: 2000-02-08 12:54:00
Dave Abrahams:
>> Do we really have a function called boost::implicit_cast<>? That's
>> an oxymoron if I've ever met one!
Beman:
> Well, we have one, but I think its days are numbered. I have an
> action item to review a long thread from a couple of months ago;
> seems like it has so many problems we may well just remove it.
Here's why implicit_cast is a reasonable name, although not perfect:
The implicit_cast function template is intended to do only conversions that
are also implicitly done by the language as part of an assignment or
initialization. It provides an explicit way to invoke these conversions.
The implicit_cast function template can't do any other kinds of conversions,
and (if Beman makes a change based on the long thread that I started) does
not cause any behavior different from what implicit conversion would do.
Typically, it saves the programmer from naming and defining a temporary of
the desired type.
There are all sorts of other possible names, but Stroustrup suggested the
name implicit_cast for this in C++PL3. I would have preferred a name like
convert<> or gentle_cast<> or mild_cast<> (I'm sure there are better names),
but explicit_cast<> is even worse than implicit_cast<>, since all casts are
explicit. The name explicit_cast<> would give no sense of how this is
different from the other cast operators/function templates.
I don't think we need to remove it. I don't think that the "many problems"
exist in our best attempt at implementing it. To be specific, I don't know
of any problems with this implementation:
template<typename T>
struct mirror_type
{ typedef T type; };
template<typename T>
inline T implicit_cast( typename mirror_type<T>::type t )
{ return t; }
-- Darin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk