Boost logo

Boost :

From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 2000-01-23 16:46:17

Dave Abrahams wrote:
> In generic programs, there are two ways to allow users to customize
> behaviors of called functions for their own types:
> 1. We can use overloading and rely on Koenig lookup to help select specific
> implementations.
> 2. We can supply a function template and rely on the user to specialize it
> for her own types.

3. For namespaces different from std, use overloading in only one
     for things that can be overloaded (functions), and do not rely on
     lookup but, on the contrary, use qualified names; user code adds
     directly in the library namespace
   use specialisations for things which can't (classes)

   In any cases, when adding something to a namespace, follow the
   requirements of the name of the thing being added.

This works w/o reserving function names in every namespace,
and allows complete parametrisation by library users.

> (e.g., how would you write an abs that works for unsigned?)

Seems to me that

namespace boost {
  unsigned abs (unsigned x) { return x; }
  unsigned long abs (unsigned long x) { return x; }

does the job.

Valentin Bonnard

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