Boost logo

Boost :

From: Darin Adler (darin_at_[hidden])
Date: 2001-10-26 11:57:07


Fernando,

I am excited about the possibility of a more-efficient numeric_cast.
Recently, when discussing the smart_ptr library, we established that boost
libraries are primarily aiming for clarity and correctness, and less for
optimization. But in this case I think some extra complexity is probably
warranted because efficiency and correctness are related.

I have some thoughts about the cast macros in general that apply to
numeric_cast, but I decided to mention those in a separate message to reduce
confusion.

Here's a first cut of nitpicky editorial comments about the proposal:

I'd call the traits class "numeric_conversion_traits". While the traits are
being used for numeric_cast, they can also be used for other kinds of
numeric conversions. The name numeric_cast is used to emphasize that we use
the same interface as the other kinds of casts, but cast is not a general
name for all conversions, I don't think.

> // static const int numeric_cast_traits<T,S>::mixture
> // static const int numeric_cast_traits<T,S>::sign_mixture

Is there a reason that these are of type int rather than an enum type?

> // type numeric_cast_traits<T,S>::super_type
> // type numeric_cast_traits<T,S>::sub_type

Since the words are "supertype" and "subtype", not "super type" and "sub
type", I think the identifiers should be "supertype" and "subtype", not
"super_type" and "sub_type".

> // type numeric_cast_traits<T,S>::arg_type
> // type numeric_cast_traits<T,S>::ret_type

I'd suggest skipping the abbreviation, and using "argument_type" and
"result_type".

> // static int out_of_range ( arg_type s ) ;

Same int/enum question.

> // static void assert_in_range ( arg_type s ) ;

The word assert has a specific meaning in C++ libraries as defined in
<cassert>. I think you should find another word to use in the name of this
function. I'd suggest throw_if_out_of_range, if you can't think of something
nicer.

> // static ret_type cvt ( arg_type s ) ;

How about "convert" instead of "cvt"?

    -- Darin


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