Topic: namespace aliases and extensionnamespacedefinition


Author: AllanW@my-dejanews.com
Date: 1999/02/17
Raw View
In article <7a77v8$rsp$1@nnrp1.dejanews.com>,
  dietmar.kuehl@claas-solutions.de wrote:
> 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.

    namespace std {
      #ifdef _USE_THREADS
        using namespace _Std_thread_save_98;
      #elif _LOW_MEMORY
        using namespace _Std_memory_saving_98;
      #elif _CHECK
        using namespace _Std_checked_98;
      #else
        using namespace _Std_fast_98;
      #endif
    };

----
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own


[ 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: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1999/02/17
Raw View
David R Tribble wrote:
>
> 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
>
>     }

Is the folloing allowed?

namespace A
{
  namespace B
  {
    template<class T> class C { ... };
  }
  using B::C;
}

// now specialize for C<int>
namespace A
{
  template<> class C<int> { ... };
}

If so, the solution could be:

namespace std
{
  namespace _fast
  {
    ...
  }
  namspace _small
  {
    ...
  }
  namespace _default
  {
    ...
  }

#if defined(_FAST)
  using _fast::vector;
  ...
#elif defined(_SMALL)
  using _small::vector;
#else
  using _default::vector
#endif

}


However, I guess the best approach (esp. for compile time) is:

// Header: vector

#ifndef _VECTOR
#define _VECTOR

#if defined(_FAST)
#include <fast/vector>
#elif defined(_SMALL)
#include <small/vector>
#else
#include <default/vector>
#endif

#endif // _VECTOR


[ 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: Valentin Bonnard <bonnard@clipper.ens.fr>
Date: 1999/02/15
Raw View
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.

So we can't make std an alias for the namespace std_1998 !

For future evolution, we could introduce std2... but it's
less pretty than std.

--

Valentin Bonnard
---
[ 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: Gabriel Dos_Reis <gdosreis@sophia.inria.fr>
Date: 1999/02/16
Raw View
Valentin Bonnard <bonnard@clipper.ens.fr> writes:

=B7-----------------
| Nathan Myers wrote:
| >=20
| >  Piet Van Vlierberghe<pieter.vanvlierberghe@@.lms.be.notrash> wrote:
| > >Is the following code correct?
| > > namespace N { }
| > > namespace Alias =3D N;
| > > namespace Alias { }
| >=20
| > No.
|=20
| So we can't make std an alias for the namespace std_1998 !
|=20
| For future evolution, we could introduce std2... but it's=20
| less pretty than std.
=B7-----------------

for future evolution, you are not supposed to break C++98 (yes, that
looks like utopia). As a good engineer you're expected to extend the
current library whitout requiring a new (reserved) namespace :-)

--=20
Gabriel Dos Reis, dosreis@cmla.ens-cachan.fr
---
[ 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: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1999/02/16
Raw View
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,
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.

If you are the implementer of the standard library, you probably have
other means of getting the effect of mixing different implementations
of the "same" classes. The implementation is usually not written
entirely in portable code anyway, and whatever you did would amount
to just one more implementation trick.

--
Steve Clamage, stephen.clamage@sun.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: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1999/02/13
Raw View
 Piet Van Vlierberghe<pieter.vanvlierberghe@@.lms.be.notrash> wrote:
>Is the following code correct?
> namespace N { }
> namespace Alias = N;
> namespace Alias { }

No.

--
Nathan Myers
ncm@nospam.cantrip.org  http://www.cantrip.org/



[ 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: dietmar.kuehl@claas-solutions.de
Date: 1999/02/15
Raw View
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. It cannot
be done because certain things can/must be defined in the namespace std, for
example:

  class myclass { /*...*/ };
  namespace std { template <> struct numeric_limits<myclass> { /*...*/ }; }

If 'std' is just an alias for a namespace, this seems to be impossible :-(
--
<mailto:dietmar.kuehl@claas-solutions.de>
homepage: <http://www.informatik.uni-konstanz.de/~kuehl>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
---
[ 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: "Piet Van Vlierberghe" <pieter.vanvlierberghe@lms.be>
Date: 1999/02/10
Raw View
Is the following code correct:

namespace N {
}

namespace Alias = N;

namespace Alias {
}

In other words, can I, according to the standard, use a namespace alias to
extend a namespace definition? I admit that I have access to CD2 only. CD2
suggests that it is invalid only in its syntax definition, which is not
exactly the most unambigous part of C++. Any relevant quotes?

Thanks in advance,

Piet Van Vlierberghe




[ 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              ]