Topic: namespace aliases and =?iso-8859-1?Q?extension=ADnamespace=ADdefinition?=
Author: David R Tribble <dtribble@technologist.com>
Date: 1999/02/16 Raw View
dietmar.kuehl@claas-solutions.de wrote:
>
> ncm@nospam.cantrip.org (Nathan Myers) wrote:
>>
>> Piet Van Vlierberghe<pieter.vanvlierberghe@@.lms.be.notrash> wrote:
>>> Is the following code correct?
>>> namespace N { }
>>> namespace Alias = N;
>>> namespace Alias { }
>>
>> No.
>
> That's bad... I thought it would be possible to provide different
> version of the standard library and choose the one to be used with a
> namespace alias, for example like this:
>
> // file: iostream
> namespace _Std_thread_save_98 { /* lots of stuff */ }
> namespace _Std_fast_98 { /* lots of stuff */ }
> namespace _Std_memory_saving_98 { /* lots of stuff */ }
> namespace _Std_checked_98
>
> #ifdef _USE_THREADS
> namespace std = _Std_thread_save_98;
> #elif _LOW_MEMORY
> namespace std = _Std_memory_saving_98;
> #elif _CHECK
> namespace std = _Std_checked_98;
> #else
> namespace std = _Std_fast_98;
> #endif
>
> Of course, the same result can be achieved with other approaches, too,
> but this one would allow to even mix different choices in one program.
...
The above would more typically be done like this:
namespace std {
#if _USE_THREADS
// lots of stuff
#elif _LOW_MEMORY
// lots of stuff
#elif _CHECK
// lots of stuff
#else
// lots of stuff
#endif
}
This approach doesn't have the nice grouping arrangement that the
(first) namespace aliasing approach does. In particular, we can't
pick out individual items such as Std_fast_98::foobar(). OTOH, one
could argue that mixing items from different "std" namespaces might
cause runtime compatibility problems (e.g., imagine a hypothetical
Std_no_exceptions namespace that operates without exception
handling).
The second approach also allows us to reopen namespace std to add
more stuff without any problems:
namespace std {
#if _NUMERIC_EXTENSIONS
// lots of added stuff
#endif
}
-- David R. Tribble, dtribble@technologist.com --
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/02/16 Raw View
Steve Clamage wrote:
>
> dietmar.kuehl@claas-solutions.de writes:
>
> >In article <7a2i5v$k7j$1@shell7.ba.best.com>,
> > ncm@nospam.cantrip.org (Nathan Myers) wrote:
> >>
> >> Piet Van Vlierberghe<pieter.vanvlierberghe@@.lms.be.notrash> wrote:
> >> >Is the following code correct?
> >> > namespace N { }
> >> > namespace Alias = N;
> >> > namespace Alias { }
> >>
> >> No.
>
> >That's bad... I thought it would be possible to provide different version of
> >the standard library and choose the one to be used with a namespace alias, for
> >example like this:
> > // file: iostream
> > namespace _Std_thread_save_98 { /* lots of stuff */ }
> > namespace _Std_fast_98 { /* lots of stuff */ }
> > namespace _Std_memory_saving_98 { /* lots of stuff */ }
> > namespace _Std_checked_98
>
> > #ifdef _USE_THREADS
> > namespace std = _Std_thread_save_98;
> > #elif _LOW_MEMORY
> > namespace std = _Std_memory_saving_98;
> > #elif _CHECK
> > namespace std = _Std_checked_98;
> > #else
> > namespace std = _Std_fast_98;
> > #endif
>
> >Of course, the same result can be achieved with other approaches, too, but
> >this one would allow to even mix different choices in one program.
>
> If you write your own version of part of the standard library,
I rather got the impression that he was talking about something that an
implementor could do, rather than a user. With the above definition of
<iostream>, a user could #include <iostream> and get standard behavior
(except for the issue that's under discussion here, the inability to
reopen the namespace using the alias). Alternatively a user could
#define one of the relevant implemention-specific macros before
#including it, and get implementation-specific behavior.
> it is inlikely that you could get it to work with the precompiled
> standard library supplied with your implementation. (The results are
> undefined.) If you did get it to work, it wouldn't be portable.
A user is permitted to specialize a standard library template for a
user-defined class; if the specialization meets all of the requirements
specified for that template, the results are just as portable as the
coding techniques used within the specialization itself allow them to
be. The standard requires that implementors not use implementation
techniques which would interfere with such a specialization.
This provides a legitimate reason for wanting to reopen namespace std,
and therefore a motive in the case shown above for wanting to be able to
reopen it using an alias.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: sbnaran@localhost.localdomain.COM (Siemel Naran)
Date: 1999/02/14 Raw View
On 13 Feb 1999 16:47:41 GMT, Nathan Myers <ncm@nospam.cantrip.org> wrote:
> Piet Van Vlierberghe<pieter.vanvlierberghe@@.lms.be.notrash> wrote:
>>Is the following code correct?
>> namespace N { }
>> namespace Alias = N;
>> namespace Alias { }
>
>No.
What's the reason to disallow this?
--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]