Boost logo

Boost :

From: Ed Brey (brey_at_[hidden])
Date: 1999-09-20 11:03:31


Valentin Bonnard wrote:
>
> C. Green wrote:
>
> > The principle to keep in mind is to define the most narrow casting
> > functions that are as specific as possible.
>
> Keep in mind that exact_cast<OriginalType, TargetType> (lvalue)
> is the most specific cast possible, but maybe it's _too_
> specific. Definition of exact_cast follows:
>
> template <typename OriginalType, typename TargetType>
> TargetType exact_cast (OriginalType& x)
> { return (TargetType)x; }
>
> being too specific doesn't help either.

"Specific" applies to the nature of the cast, i.e. between numerics,
classes in a hierarchy, etc. Clearly, as you point out, providing
specifics down to a particular type is not useful.

However, I don't see any harm as long in making casts as specific as
possible, as long as they always deal with a class of C++ types (here
class means "group of related items", not C++ class).


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk