Boost logo

Boost :

From: Gabriel Dos Reis (dosreis_at_[hidden])
Date: 1999-12-10 17:18:26

Darin Adler <darin_at_[hidden]> writes:

| > | 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.

Stop. You can't specialize a template function. You *overload* it. Two
differents things; althought they might be seen as having similar

| 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>."

Right. And right now there is no strong reasons to put it in
namespace std, apart from (probably) to make it look like standard :)

-- Gaby

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