sgi extensions
Jonathan Wakely
cow@compsoc.man.ac.uk
Wed Nov 27 08:06:00 GMT 2002
On Fri, Nov 22, 2002 at 08:54:09PM +0000, Nathan Myers wrote:
> > > Are there namespace tricks I need to do to get at the sgi extensions?
> > > simply using #include <ext/hash_map> doesn't seem to be doing the trick
> > > as it claims hash_map is undeclared.
> >
> > They're in the __gnu_cxx namespace.
>
> For maximum portability, consider defining a namespace alias to use
> to talk about extensions. E.g.
[snip]
> This is a bit cleaner than defining typedefs for all the instantiations
> you might need. (It's a pity you can't say "namespace Sgi = ::;".)
>
> Phil, you might suggest something like this in the docs.
This patch adds your recommendation almost verbatim (except for the
concluding "it's a pity...", want it in?) and with a little extra context
added at the beginning. I've added it to the "Extensions and Backward
Compatibility" section of the FAQ, since this is referenced at the top
of the ext/howto.html page. I'm not sure if that's the best place for
it.
Should there be separate tests for 3.0 and 3.1, IIRC the extensions were
still in the std namespace until 3.1?
jon
-------------- next part --------------
Index: docs/html/faq/index.html
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/docs/html/faq/index.html,v
retrieving revision 1.47
diff -u -r1.47 index.html
--- docs/html/faq/index.html 21 Nov 2002 07:16:01 -0000 1.47
+++ docs/html/faq/index.html 27 Nov 2002 11:46:51 -0000
@@ -877,6 +877,31 @@
that of other headers whose directories are not searched directly,
e.g., <code><sys/stat.h></code>, <code><X11/Xlib.h></code>.
</p>
+
+ <p>The extensions are no longer in the global or <code>std</code>
+ namespaces, instead they are declared in the <code>__gnu_cxx</code>
+ namespace. For maximum portability, consider defining a namespace
+ alias to use to talk about extensions, e.g.:
+ </p>
+ <pre>
+ #ifdef __GNUC__
+ #if __GNUC__ < 3
+ #include <hash_map.h>
+ namespace Sgi { using ::hash_map; }; // inherit globals
+ #else
+ #include <ext/hash_map>
+ namespace Sgi = ::__gnu_cxx;
+ #endif
+ #else // ... there are other compilers, right?
+ namespace Sgi = std;
+ #endif
+
+ Sgi::hash_map<int,int> my_map; </pre>
+ <p>This is a bit cleaner than defining typedefs for all the
+ instantiations you might need.
+ </p>
+
+
<p>Extensions to the library have
<a href="../ext/howto.html">their own page</a>.
</p>
More information about the Libstdc++
mailing list