TITLE: adding components to a namespace

(Newsgroups: comp.lang.c++.moderated)


PROBLEM: geert@cs.ruu.nl (Geert-Jan Giezeman)

I wonder if it is allowed (according to the DWP) to add a member to
the std namespace. I vaguely remember that this is not the case, but
can not find the definitive answer in the DWP (it is sooo big). Who
can point me to the answer?

The reason for this question is the following. The standard
introduces the templated class numeric_limits<T> in namespace std.
This class specifies all kinds of properties of numeric types, by
means of specialisaions.  (numeric_limits<int>, numeric_limits<float>
etcetera).

It would be very handy to have treat user defined number types, for
example for arbitrary precision integer arithmetic(apia), in the same
way. That would mean one should supply a specialisation
numeric_limits<apia>.


RESPONSE: clamage@taumet.Eng.Sun.COM (Steve Clamage), 27 Aug 96

You (as a C++ user) cannot add new names to namespace std, but you
can add new specializations of templates that are already there.
The wording of the draft standard previously did not make this clear,
but has been fixed.

So you cannot write
	namespace std { class MyNewClass { ... }; }

but you can write
	class apia { ... };
	namespace std { class numeric_limits<apia> { ... }; }
