Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 1998-12-01 14:34:46

Sean Corfield (sean.corfield_at_[hidden]) wrote:

>Any other classes that might be worth exploring? Anything within the
>standard library that we think might usefully be 'adapted' in a
>future-standard way?

Here are a few simple but extremely useful things I've already
implemented, but which my employer holds a copyright on. If someone else
wanted to make a public implementation I'd be happy to review it and
provide help.

NonCopyable -
  A simple class which, when derived from, prevents copy construction and

EqualityComparable<>, LessThanComparable<>
  Implements the standard meanings for operator!=, or >, >=, and <=
respectively based on operator== and operator< member functions,
respectively. std::relops is useless for this purpose now. Derive T from
LessThanComparable<T> for example. Uses the "Barton and Nackman trick".

  Here's the interface I've implemented. An important extension to this
would use a uniform interface to return the minimum representable value
of T. Note that numeric_limits fails to do what you might expect for
floating point numbers.

template <class T>
class numeric_traits
        static const bool is_specialized = false;
        typedef T value_type; // The parameter type
        static value_type zero(); // Zero of that type
        static value_type one(); // One, of that type
        static value_type portable_min(); // The minimum portably representable
        static value_type portable_max(); // The maximum portably representable
        static const bool has_abs_difference_type = false; //
abs_difference_type defined?
        static const bool has_difference_type = false; // difference_type
                                                                                                        // for all T values t1 and t2:
        typedef unsigned char abs_difference_type; // A type that can represent
        typedef short difference_type; // A type that can represent t1-t2
        // Supports nudge up/down?
        static const bool nudgeable = false;
        // Computes the next greater representable value after 'x'
        static T nudge_up( value_type x );
        // Computes the next lesser representable value after 'x'
 static T nudge_down( value_type x );

 Represents a half-open range such as is used with STL random-access
iterators, but which can be used with numeric types as well. Supports
combination with other ranges and a number of other useful operations.

David Abrahams * Mark of the Unicorn, Inc. * abrahams_at_[hidden]

Free Web-based e-mail groups --

Boost list run by bdawes at, gregod at, cpdaniel at, john at