Boost logo

Boost :

From: Darin Adler (darin_at_[hidden])
Date: 1999-12-10 16:19:27

> | There is a std::abs() template function, for the complex class.
> | Therefore it is both legal to put the rational abs() function in the
> ^^^^^
> | std namespace and highly recommended since a generic algorithm should
> | be able to use std::abs() on any numeric type including user defined
> | types.
> 'legal' on which basis? If it is by the Standard, the chapter and verse. "It is undefined for a C++ program to add declarations or
definitions to namespace std or namespaces within namespace std unless
otherwise specified. A program may add template specializations for any
standard library template to namespace std. Such a specialization (complete
or partial) of a standard library template results in undefined behavior
unless the declaration depends on a user-defined name of external linkage
and unless the specialization meets the standard library requirements for
the original template."

Programs are definitely allowed (and recommended) to specialize function
templates like std::swap and std::less; in fact my recent change to
smart_ptr.hpp does just that. But it's a bit less clear for std::abs, which
is the name for both some non-template functions in the standard and for a
template (for complex).

Kevlin Henney pointed out that, "The abs for complex is in terms of
complex<T> rather than simply just T, and so although you would be
permitted to specialise abs for complex< rational<T> > this does not give
you general licence to specialise for rational<T>."

    -- Darin

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