]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/doc/xml/manual/backwards_compatibility.xml
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / doc / xml / manual / backwards_compatibility.xml
1 <sect1 id="manual.appendix.porting.backwards" xreflabel="backwards">
2 <?dbhtml filename="backwards.html"?>
3  
4 <sect1info>
5   <keywordset>
6     <keyword>
7       ISO C++
8     </keyword>
9     <keyword>
10       backwards
11     </keyword>
12   </keywordset>
13 </sect1info>
14
15 <title>Backwards Compatibility</title>
16
17 <sect2 id="backwards.first" xreflabel="backwards.first">
18 <title>First</title>
19
20 <para>The first generation GNU C++ library was called libg++.  It was a
21 separate GNU project, although reliably paired with GCC. Rumors imply
22 that it had a working relationship with at least two kinds of
23 dinosaur.
24 </para>
25
26 <para>Some background: libg++ was designed and created when there was no
27 ISO standard to provide guidance.  Classes like linked lists are now
28 provided for by <classname>list&lt;T&gt;</classname> and do not need to be
29 created by <function>genclass</function>.  (For that matter, templates exist
30 now and are well-supported, whereas genclass (mostly) predates them.)
31 </para>
32
33 <para>There are other classes in libg++ that are not specified in the
34 ISO Standard (e.g., statistical analysis).  While there are a lot of
35 really useful things that are used by a lot of people, the Standards
36 Committee couldn't include everything, and so a lot of those
37 <quote>obvious</quote> classes didn't get included.
38 </para>
39
40 <para>Known Issues include many of the limitations of its immediate ancestor.</para> 
41
42 <para>Portability notes and known implementation limitations are as follows.</para>
43
44 <sect3>
45   <title>No <code>ios_base</code></title>
46
47 <para> At least some older implementations don't have <code>std::ios_base</code>, so you should use <code>std::ios::badbit</code>, <code>std::ios::failbit</code> and <code>std::ios::eofbit</code> and <code>std::ios::goodbit</code>.
48 </para>
49 </sect3>
50
51 <sect3>
52 <title>No <code>cout</code> in <code>ostream.h</code>, no <code>cin</code> in <code>istream.h</code></title>
53
54 <para>
55         In earlier versions of the standard,
56         <filename class="headerfile">fstream.h</filename>,
57         <filename class="headerfile">ostream.h</filename>
58         and <filename class="headerfile">istream.h</filename>
59         used to define
60         <code>cout</code>, <code>cin</code> and so on. ISO C++ specifies that one needs to include
61         <filename class="headerfile">iostream</filename>
62         explicitly to get the required definitions.
63  </para>
64 <para> Some include adjustment may be required.</para>
65
66 <para>This project is no longer maintained or supported, and the sources
67 archived. For the desperate,
68 the <ulink url="http://gcc.gnu.org/extensions.html">GCC extensions
69 page</ulink> describes where to find the last libg++ source. The code is
70 considered replaced and rewritten.
71 </para>
72 </sect3>
73 </sect2>
74
75 <sect2 id="backwards.second" xreflabel="backwards.second">
76 <title>Second</title>
77
78 <para> 
79   The second generation GNU C++ library was called libstdc++, or
80   libstdc++-v2. It spans the time between libg++ and pre-ISO C++
81   standardization and is usually associated with the following GCC
82   releases: egcs 1.x, gcc 2.95, and gcc 2.96.
83 </para>
84
85 <para> 
86   The STL portions of this library are based on SGI/HP STL release 3.11.
87 </para>
88
89 <para>
90   This project is no longer maintained or supported, and the sources
91   archived.  The code is considered replaced and rewritten.
92 </para>
93
94 <para>
95   Portability notes and known implementation limitations are as follows.
96 </para>
97
98 <sect3>
99   <title>Namespace <code>std::</code> not supported</title>
100
101   <para>
102     Some care is required to support C++ compiler and or library
103     implementation that do not have the standard library in
104     <code>namespace std</code>.
105   </para>
106
107   <para>
108     The following sections list some possible solutions to support compilers
109     that cannot ignore <code>std::</code>-qualified names.
110   </para>
111   
112   <para> 
113     First, see if the compiler has a flag for this. Namespace
114     back-portability-issues are generally not a problem for g++
115     compilers that do not have libstdc++ in <code>std::</code>, as the
116     compilers use <code>-fno-honor-std</code> (ignore
117     <code>std::</code>, <code>:: = std::</code>) by default. That is,
118     the responsibility for enabling or disabling <code>std::</code> is
119     on the user; the maintainer does not have to care about it. This
120     probably applies to some other compilers as well.
121   </para>
122
123   <para>
124     Second, experiment with a variety of pre-processor tricks.
125   </para>
126
127   <para> 
128     By defining <code>std</code> as a macro, fully-qualified namespace
129     calls become global. Volia.
130   </para>
131               
132 <programlisting>
133 #ifdef WICKEDLY_OLD_COMPILER
134 # define std
135 #endif
136 </programlisting>
137
138   <para>
139     Thanks to Juergen Heinzl who posted this solution on gnu.gcc.help.
140   </para>
141
142   <para>
143     Another pre-processor based approach is to define a macro
144     <code>NAMESPACE_STD</code>, which is defined to either
145     <quote> </quote> or <quote>std</quote> based on a compile-type
146     test. On GNU systems, this can be done with autotools by means of
147     an autoconf test (see below) for <code>HAVE_NAMESPACE_STD</code>,
148     then using that to set a value for the <code>NAMESPACE_STD</code>
149     macro.  At that point, one is able to use
150     <code>NAMESPACE_STD::string</code>, which will evaluate to
151     <code>std::string</code> or <code>::string</code> (i.e., in the
152     global namespace on systems that do not put <code>string</code> in
153     <code>std::</code>).
154   </para>
155
156 <programlisting>
157 dnl @synopsis AC_CXX_NAMESPACE_STD
158 dnl
159 dnl If the compiler supports namespace std, define
160 dnl HAVE_NAMESPACE_STD.
161 dnl
162 dnl @category Cxx
163 dnl @author Todd Veldhuizen
164 dnl @author Luc Maisonobe &lt;luc@spaceroots.org&gt;
165 dnl @version 2004-02-04
166 dnl @license AllPermissive
167 AC_DEFUN([AC_CXX_NAMESPACE_STD], [
168   AC_CACHE_CHECK(if g++ supports namespace std,
169   ac_cv_cxx_have_std_namespace,
170   [AC_LANG_SAVE
171   AC_LANG_CPLUSPLUS
172   AC_TRY_COMPILE([#include &lt;iostream&gt; 
173                   std::istream&amp; is = std::cin;],,
174   ac_cv_cxx_have_std_namespace=yes, ac_cv_cxx_have_std_namespace=no)
175   AC_LANG_RESTORE
176   ])
177   if test "$ac_cv_cxx_have_std_namespace" = yes; then
178     AC_DEFINE(HAVE_NAMESPACE_STD,,[Define if g++ supports namespace std. ])
179   fi
180 ])
181 </programlisting>
182 </sect3>
183
184 <sect3>
185 <title>Illegal iterator usage</title>
186 <para>
187   The following illustrate implementation-allowed illegal iterator
188   use, and then correct use.
189 </para>
190
191 <itemizedlist> 
192   <listitem>
193     <para>
194       you cannot do <code>ostream::operator&lt;&lt;(iterator)</code>
195       to print the address of the iterator =&gt; use
196       <code>operator&lt;&lt; &amp;*iterator</code> instead
197     </para>
198   </listitem>
199   <listitem>
200     <para>
201       you cannot clear an iterator's reference (<code>iterator =
202       0</code>) =&gt; use <code>iterator = iterator_type();</code>
203     </para>
204   </listitem>
205   <listitem>
206     <para>
207       <code>if (iterator)</code> won't work any more =&gt; use
208       <code>if (iterator != iterator_type())</code> 
209     </para>
210   </listitem>
211 </itemizedlist>
212 </sect3>
213
214 <sect3>
215   <title><code>isspace</code> from <filename class="headerfile">cctype</filename> is a macro
216   </title>
217
218   <para> 
219     Glibc 2.0.x and 2.1.x define <filename
220     class="headerfile">ctype.h</filename> functionality as macros
221     (isspace, isalpha etc.).
222   </para>
223
224   <para>
225     This implementations of libstdc++, however, keep these functions
226     as macros, and so it is not back-portable to use fully qualified
227     names. For example:
228   </para>
229
230 <programlisting> 
231 #include &lt;cctype&gt; 
232 int main() { std::isspace('X'); } 
233 </programlisting>
234
235 <para>
236   Results in something like this:
237 </para>
238
239 <programlisting> 
240 std:: (__ctype_b[(int) ( ( 'X' ) )] &amp; (unsigned short int) _ISspace ) ; 
241 </programlisting>
242
243 <para> 
244   A solution is to modify a header-file so that the compiler tells
245   <filename class="headerfile">ctype.h</filename> to define functions
246   instead of macros:
247 </para>
248
249 <programlisting>
250 // This keeps isalnum, et al from being propagated as macros. 
251 #if __linux__
252 # define __NO_CTYPE 1
253 #endif
254 </programlisting>
255
256 <para>
257   Then, include <filename class="headerfile">ctype.h</filename>
258 </para>
259
260 <para>
261   Another problem arises if you put a <code>using namespace
262   std;</code> declaration at the top, and include <filename
263   class="headerfile">ctype.h</filename>. This will result in
264   ambiguities between the definitions in the global namespace
265   (<filename class="headerfile">ctype.h</filename>) and the
266   definitions in namespace <code>std::</code>
267   (<code>&lt;cctype&gt;</code>).
268 </para>
269 </sect3>
270
271 <sect3>
272 <title>No <code>vector::at</code>, <code>deque::at</code>, <code>string::at</code></title>
273
274 <para>
275   One solution is to add an autoconf-test for this:
276 </para>
277
278 <programlisting>
279 AC_MSG_CHECKING(for container::at)
280 AC_TRY_COMPILE(
281 [
282 #include &lt;vector&gt;
283 #include &lt;deque&gt;
284 #include &lt;string&gt;
285         
286 using namespace std;
287 ],
288 [
289 deque&lt;int&gt; test_deque(3);
290 test_deque.at(2);
291 vector&lt;int&gt; test_vector(2);
292 test_vector.at(1);
293 string test_string(<quote>test_string</quote>);
294 test_string.at(3);
295 ],
296 [AC_MSG_RESULT(yes)
297 AC_DEFINE(HAVE_CONTAINER_AT)],
298 [AC_MSG_RESULT(no)])
299 </programlisting>
300
301 <para>
302   If you are using other (non-GNU) compilers it might be a good idea
303   to check for <code>string::at</code> separately.
304 </para>
305
306 </sect3>
307
308 <sect3>
309 <title>No <code>std::char_traits&lt;char&gt;::eof</code></title>
310
311 <para>
312   Use some kind of autoconf test, plus this:
313 </para>      
314
315 <programlisting>
316 #ifdef HAVE_CHAR_TRAITS
317 #define CPP_EOF std::char_traits&lt;char&gt;::eof()
318 #else
319 #define CPP_EOF EOF
320 #endif
321 </programlisting>
322
323 </sect3>
324
325 <sect3>
326 <title>No <code>string::clear</code></title>
327
328 <para>
329   There are two functions for deleting the contents of a string:
330   <code>clear</code> and <code>erase</code> (the latter returns the
331   string).
332 </para>
333       
334 <programlisting>
335 void 
336 clear() { _M_mutate(0, this-&gt;size(), 0); }
337 </programlisting>
338
339 <programlisting>
340 basic_string&amp; 
341 erase(size_type __pos = 0, size_type __n = npos)
342
343   return this-&gt;replace(_M_check(__pos), _M_fold(__pos, __n),
344                           _M_data(), _M_data()); 
345 }
346 </programlisting>
347
348 <para>
349   Unfortunately, <code>clear</code> is not implemented in this
350   version, so you should use <code>erase</code> (which is probably
351   faster than <code>operator=(charT*)</code>).
352 </para>
353 </sect3>
354
355 <sect3>
356 <title>
357   Removal of <code>ostream::form</code> and <code>istream::scan</code>
358   extensions
359 </title>
360
361 <para> 
362   These are no longer supported. Please use stringstreams instead.
363 </para>
364 </sect3>
365
366 <sect3>
367 <title>No <code>basic_stringbuf</code>, <code>basic_stringstream</code></title>
368
369 <para>
370   Although the ISO standard <code>i/ostringstream</code>-classes are
371   provided, (<filename class="headerfile">sstream</filename>), for
372   compatibility with older implementations the pre-ISO
373   <code>i/ostrstream</code> (<filename
374   class="headerfile">strstream</filename>) interface is also provided,
375   with these caveats:
376 </para>
377
378 <itemizedlist>
379   <listitem>
380     <para> 
381       <code>strstream</code> is considered to be deprecated
382     </para>
383   </listitem>
384   <listitem>
385     <para> 
386       <code>strstream</code> is limited to <code>char</code>
387     </para>
388   </listitem>
389   <listitem>
390     <para> 
391       with <code>ostringstream</code> you don't have to take care of
392       terminating the string or freeing its memory 
393     </para>
394   </listitem>
395   <listitem>
396     <para> 
397       <code>istringstream</code> can be re-filled (clear();
398       str(input);) 
399     </para>
400   </listitem>
401 </itemizedlist>
402
403 <para>
404   You can then use output-stringstreams like this:
405 </para>
406        
407 <programlisting>
408 #ifdef HAVE_SSTREAM
409 # include &lt;sstream&gt;
410 #else
411 # include &lt;strstream&gt;
412 #endif
413
414 #ifdef HAVE_SSTREAM
415   std::ostringstream oss;
416 #else
417   std::ostrstream oss;
418 #endif
419
420 oss &lt;&lt; <quote>Name=</quote> &lt;&lt; m_name &lt;&lt; <quote>, number=</quote> &lt;&lt; m_number &lt;&lt; std::endl;
421 ...
422 #ifndef HAVE_SSTREAM
423   oss &lt;&lt; std::ends; // terminate the char*-string
424 #endif
425
426 // str() returns char* for ostrstream and a string for ostringstream
427 // this also causes ostrstream to think that the buffer's memory
428 // is yours
429 m_label.set_text(oss.str());
430 #ifndef HAVE_SSTREAM
431   // let the ostrstream take care of freeing the memory
432   oss.freeze(false);
433 #endif
434 </programlisting>
435
436 <para>
437       Input-stringstreams can be used similarly:
438 </para>
439       
440 <programlisting>
441 std::string input;
442 ...
443 #ifdef HAVE_SSTREAM
444 std::istringstream iss(input);
445 #else
446 std::istrstream iss(input.c_str());
447 #endif
448
449 int i;
450 iss &gt;&gt; i; 
451 </programlisting>
452
453 <para> One (the only?) restriction is that an istrstream cannot be re-filled:
454 </para>
455       
456 <programlisting>
457 std::istringstream iss(numerator);
458 iss &gt;&gt; m_num;
459 // this is not possible with istrstream
460 iss.clear();
461 iss.str(denominator);
462 iss &gt;&gt; m_den;
463 </programlisting>
464  
465 <para>
466 If you don't care about speed, you can put these conversions in
467       a template-function:
468 </para>      
469 <programlisting>
470 template &lt;class X&gt;
471 void fromString(const string&amp; input, X&amp; any)
472 {
473 #ifdef HAVE_SSTREAM
474 std::istringstream iss(input);
475 #else
476 std::istrstream iss(input.c_str());
477 #endif
478 X temp;
479 iss &gt;&gt; temp;
480 if (iss.fail())
481 throw runtime_error(..)
482 any = temp;
483 }
484 </programlisting>
485
486 <para> 
487   Another example of using stringstreams is in <link
488   linkend="strings.string.shrink">this howto</link>.
489 </para>
490
491 <para> There is additional information in the libstdc++-v2 info files, in
492 particular <quote>info iostream</quote>.
493 </para>
494 </sect3>
495
496 <sect3>
497   <title>Little or no wide character support</title>
498   <para>
499     Classes <classname>wstring</classname> and
500     <classname>char_traits&lt;wchar_t&gt;</classname> are
501     not supported.
502   </para>
503 </sect3>
504
505 <sect3>
506   <title>No templatized iostreams</title>
507   <para>
508     Classes <classname>wfilebuf</classname> and
509     <classname>wstringstream</classname> are not supported.
510   </para>
511 </sect3>
512
513 <sect3>
514 <title>Thread safety issues</title>
515
516   <para>
517     Earlier GCC releases had a somewhat different approach to
518     threading configuration and proper compilation.  Before GCC 3.0,
519     configuration of the threading model was dictated by compiler
520     command-line options and macros (both of which were somewhat
521     thread-implementation and port-specific).  There were no
522     guarantees related to being able to link code compiled with one
523     set of options and macro setting with another set.
524   </para>
525
526   <para>
527     For GCC 3.0, configuration of the threading model used with
528     libraries and user-code is performed when GCC is configured and
529     built using the --enable-threads and --disable-threads options.
530     The ABI is stable for symbol name-mangling and limited functional
531     compatibility exists between code compiled under different
532     threading models.
533   </para>
534
535    <para>
536      The libstdc++ library has been designed so that it can be used in
537      multithreaded applications (with libstdc++-v2 this was only true
538      of the STL parts.)  The first problem is finding a
539      <emphasis>fast</emphasis> method of implementation portable to
540      all platforms.  Due to historical reasons, some of the library is
541      written against per-CPU-architecture spinlocks and other parts
542      against the gthr.h abstraction layer which is provided by gcc.  A
543      minor problem that pops up every so often is different
544      interpretations of what &quot;thread-safe&quot; means for a
545      library (not a general program).  We currently use the <ulink
546      url="http://www.sgi.com/tech/stl/thread_safety.html">same
547      definition that SGI</ulink> uses for their STL subset.  However,
548      the exception for read-only containers only applies to the STL
549      components. This definition is widely-used and something similar
550      will be used in the next version of the C++ standard library.
551    </para>
552
553    <para>
554      Here is a small link farm to threads (no pun) in the mail
555      archives that discuss the threading problem.  Each link is to the
556      first relevant message in the thread; from there you can use
557      &quot;Thread Next&quot; to move down the thread.  This farm is in
558      latest-to-oldest order.
559    </para>
560
561       <itemizedlist>
562         <listitem>
563           <para>
564             Our threading expert Loren gives a breakdown of <ulink
565             url="http://gcc.gnu.org/ml/libstdc++/2001-10/msg00024.html">the
566             six situations involving threads</ulink> for the 3.0
567             release series.
568           </para>
569       </listitem>
570         <listitem>
571           <para>
572             <ulink url="http://gcc.gnu.org/ml/libstdc++/2001-05/msg00384.html">
573         This message</ulink> inspired a recent updating of issues with
574         threading and the SGI STL library.  It also contains some
575         example POSIX-multithreaded STL code.
576           </para>
577         </listitem>
578       </itemizedlist>
579
580    <para> 
581      (A large selection of links to older messages has been removed;
582      many of the messages from 1999 were lost in a disk crash, and the
583      few people with access to the backup tapes have been too swamped
584      with work to restore them.  Many of the points have been
585      superseded anyhow.)
586    </para>
587 </sect3>
588
589 </sect2>
590
591 <sect2 id="backwards.third" xreflabel="backwards.third">
592 <title>Third</title>
593
594 <para> The third generation GNU C++ library is called libstdc++, or
595 libstdc++-v3.
596 </para>
597
598       <para>The subset commonly known as the Standard Template Library
599          (chapters 23 through 25, mostly) is adapted from the final release
600          of the SGI STL (version 3.3), with extensive changes.
601       </para>
602
603       <para>A more formal description of the V3 goals can be found in the
604          official <ulink url="../17_intro/DESIGN">design document</ulink>.
605       </para>
606
607 <para>Portability notes and known implementation limitations are as follows.</para>
608
609 <sect3>
610 <title>Pre-ISO headers moved to backwards or removed</title>
611
612 <para> The pre-ISO C++ headers
613       (<code>iostream.h</code>, <code>defalloc.h</code> etc.) are
614       available, unlike previous libstdc++ versions, but inclusion
615       generates a warning that you are using deprecated headers.
616 </para>
617
618     <para>This compatibility layer is constructed by including the
619     standard C++ headers, and injecting any items in
620     <code>std::</code> into the global namespace.
621    </para>
622    <para>For those of you new to ISO C++ (welcome, time travelers!), no,
623       that isn't a typo. Yes, the headers really have new names.
624       Marshall Cline's C++ FAQ Lite has a good explanation in <ulink url="http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4">item
625       [27.4]</ulink>.
626    </para>
627
628 <para> Some include adjustment may be required. What follows is an
629 autoconf test that defines <code>PRE_STDCXX_HEADERS</code> when they
630 exist.</para>
631
632 <programlisting>
633 # AC_HEADER_PRE_STDCXX
634 AC_DEFUN([AC_HEADER_PRE_STDCXX], [
635   AC_CACHE_CHECK(for pre-ISO C++ include files,
636   ac_cv_cxx_pre_stdcxx,
637   [AC_LANG_SAVE
638   AC_LANG_CPLUSPLUS
639   ac_save_CXXFLAGS="$CXXFLAGS"
640   CXXFLAGS="$CXXFLAGS -Wno-deprecated"  
641
642   # Omit defalloc.h, as compilation with newer compilers is problematic.
643   AC_TRY_COMPILE([
644   #include &lt;new.h&gt;
645   #include &lt;iterator.h&gt;
646   #include &lt;alloc.h&gt;
647   #include &lt;set.h&gt;
648   #include &lt;hashtable.h&gt;
649   #include &lt;hash_set.h&gt;
650   #include &lt;fstream.h&gt;
651   #include &lt;tempbuf.h&gt;
652   #include &lt;istream.h&gt;
653   #include &lt;bvector.h&gt;
654   #include &lt;stack.h&gt;
655   #include &lt;rope.h&gt;
656   #include &lt;complex.h&gt;
657   #include &lt;ostream.h&gt;
658   #include &lt;heap.h&gt;
659   #include &lt;iostream.h&gt;
660   #include &lt;function.h&gt;
661   #include &lt;multimap.h&gt;
662   #include &lt;pair.h&gt;
663   #include &lt;stream.h&gt;
664   #include &lt;iomanip.h&gt;
665   #include &lt;slist.h&gt;
666   #include &lt;tree.h&gt;
667   #include &lt;vector.h&gt;
668   #include &lt;deque.h&gt;
669   #include &lt;multiset.h&gt;
670   #include &lt;list.h&gt;
671   #include &lt;map.h&gt;
672   #include &lt;algobase.h&gt;
673   #include &lt;hash_map.h&gt;
674   #include &lt;algo.h&gt;
675   #include &lt;queue.h&gt;
676   #include &lt;streambuf.h&gt;
677   ],,
678   ac_cv_cxx_pre_stdcxx=yes, ac_cv_cxx_pre_stdcxx=no)
679   CXXFLAGS="$ac_save_CXXFLAGS"
680   AC_LANG_RESTORE
681   ])
682   if test "$ac_cv_cxx_pre_stdcxx" = yes; then
683     AC_DEFINE(PRE_STDCXX_HEADERS,,[Define if pre-ISO C++ header files are present. ])
684   fi
685 ])
686 </programlisting>
687
688 <para>Porting between pre-ISO headers and ISO headers is simple: headers
689 like <filename class="headerfile">vector.h</filename> can be replaced with <filename class="headerfile">vector</filename> and a using
690 directive <code>using namespace std;</code> can be put at the global
691 scope. This should be enough to get this code compiling, assuming the
692 other usage is correct.
693 </para>
694 </sect3>
695
696 <sect3>
697 <title>Extension headers hash_map, hash_set moved to ext or backwards</title>
698
699       <para>At this time most of the features of the SGI STL extension have been
700          replaced by standardized libraries.
701          In particular, the unordered_map and unordered_set containers of TR1
702          are suitable replacement for the non-standard hash_map and hash_set
703          containers in the SGI STL. 
704       </para>
705 <para> Header files <filename class="headerfile">hash_map</filename> and <filename class="headerfile">hash_set</filename> moved
706 to <filename class="headerfile">ext/hash_map</filename> and  <filename class="headerfile">ext/hash_set</filename>,
707 respectively. At the same time, all types in these files are enclosed
708 in <code>namespace __gnu_cxx</code>. Later versions move deprecate
709 these files, and suggest using TR1's  <filename class="headerfile">unordered_map</filename>
710 and  <filename class="headerfile">unordered_set</filename> instead.
711 </para>
712
713       <para>The extensions are no longer in the global or <code>std</code>
714          namespaces, instead they are declared in the <code>__gnu_cxx</code>
715          namespace. For maximum portability, consider defining a namespace
716          alias to use to talk about extensions, e.g.:
717       </para>
718       <programlisting>
719       #ifdef __GNUC__
720       #if __GNUC__ &lt; 3
721         #include &lt;hash_map.h&gt;
722         namespace extension { using ::hash_map; }; // inherit globals
723       #else
724         #include &lt;backward/hash_map&gt;
725         #if __GNUC__ == 3 &amp;&amp; __GNUC_MINOR__ == 0
726           namespace extension = std;               // GCC 3.0
727         #else
728           namespace extension = ::__gnu_cxx;       // GCC 3.1 and later
729         #endif
730       #endif
731       #else      // ...  there are other compilers, right?
732         namespace extension = std;
733       #endif
734
735       extension::hash_map&lt;int,int&gt; my_map; 
736       </programlisting>
737       <para>This is a bit cleaner than defining typedefs for all the
738          instantiations you might need.
739       </para>
740  
741
742 <para>The following autoconf tests check for working HP/SGI hash containers.
743 </para>
744
745 <programlisting>
746 # AC_HEADER_EXT_HASH_MAP
747 AC_DEFUN([AC_HEADER_EXT_HASH_MAP], [
748   AC_CACHE_CHECK(for ext/hash_map,
749   ac_cv_cxx_ext_hash_map,
750   [AC_LANG_SAVE
751   AC_LANG_CPLUSPLUS
752   ac_save_CXXFLAGS="$CXXFLAGS"
753   CXXFLAGS="$CXXFLAGS -Werror"  
754   AC_TRY_COMPILE([#include &lt;ext/hash_map&gt;], [using __gnu_cxx::hash_map;],
755   ac_cv_cxx_ext_hash_map=yes, ac_cv_cxx_ext_hash_map=no)
756   CXXFLAGS="$ac_save_CXXFLAGS"
757   AC_LANG_RESTORE
758   ])
759   if test "$ac_cv_cxx_ext_hash_map" = yes; then
760     AC_DEFINE(HAVE_EXT_HASH_MAP,,[Define if ext/hash_map is present. ])
761   fi
762 ])
763 </programlisting>
764
765 <programlisting>
766 # AC_HEADER_EXT_HASH_SET
767 AC_DEFUN([AC_HEADER_EXT_HASH_SET], [
768   AC_CACHE_CHECK(for ext/hash_set,
769   ac_cv_cxx_ext_hash_set,
770   [AC_LANG_SAVE
771   AC_LANG_CPLUSPLUS
772   ac_save_CXXFLAGS="$CXXFLAGS"
773   CXXFLAGS="$CXXFLAGS -Werror"  
774   AC_TRY_COMPILE([#include &lt;ext/hash_set&gt;], [using __gnu_cxx::hash_set;],
775   ac_cv_cxx_ext_hash_set=yes, ac_cv_cxx_ext_hash_set=no)
776   CXXFLAGS="$ac_save_CXXFLAGS"
777   AC_LANG_RESTORE
778   ])
779   if test "$ac_cv_cxx_ext_hash_set" = yes; then
780     AC_DEFINE(HAVE_EXT_HASH_SET,,[Define if ext/hash_set is present. ])
781   fi
782 ])
783 </programlisting>
784 </sect3>
785
786 <sect3>
787 <title>No <code>ios::nocreate/ios::noreplace</code>.
788 </title>
789
790 <para> The existence of <code>ios::nocreate</code> being used for
791 input-streams has been confirmed, most probably because the author
792 thought it would be more correct to specify nocreate explicitly.  So
793 it can be left out for input-streams.
794 </para>
795
796 <para>For output streams, <quote>nocreate</quote> is probably the default,
797 unless you specify <code>std::ios::trunc</code> ? To be safe, you can
798 open the file for reading, check if it has been opened, and then
799 decide whether you want to create/replace or not. To my knowledge,
800 even older implementations support <code>app</code>, <code>ate</code>
801 and <code>trunc</code> (except for <code>app</code> ?).
802 </para>
803 </sect3>
804
805 <sect3>
806 <title>
807 No <code>stream::attach(int fd)</code>
808 </title>
809
810 <para>
811       Phil Edwards writes: It was considered and rejected for the ISO
812       standard.  Not all environments use file descriptors.  Of those
813       that do, not all of them use integers to represent them.
814     </para>  
815
816 <para>
817       For a portable solution (among systems which use
818       file descriptors), you need to implement a subclass of
819       <code>std::streambuf</code> (or
820       <code>std::basic_streambuf&lt;..&gt;</code>) which opens a file
821       given a descriptor, and then pass an instance of this to the
822       stream-constructor. 
823     </para>
824
825 <para>
826       An extension is available that implements this.
827       <filename class="headerfile">ext/stdio_filebuf.h</filename> contains a derived class called
828       <ulink url="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/class____gnu__cxx_1_1stdio__filebuf.html"><code>__gnu_cxx::stdio_filebuf</code></ulink>.
829       This class can be constructed from a C <code>FILE*</code> or a file
830       descriptor, and provides the <code>fd()</code> function.
831     </para>
832
833 <para>
834  For another example of this, refer to
835       <ulink url="http://www.josuttis.com/cppcode/fdstream.html">fdstream example</ulink> 
836       by Nicolai Josuttis.
837 </para>
838 </sect3>
839
840 <sect3>
841 <title>
842 Support for C++98 dialect.
843 </title>
844
845 <para>Check for complete library coverage of the C++1998/2003 standard.
846 </para>
847
848 <programlisting>
849 # AC_HEADER_STDCXX_98
850 AC_DEFUN([AC_HEADER_STDCXX_98], [
851   AC_CACHE_CHECK(for ISO C++ 98 include files,
852   ac_cv_cxx_stdcxx_98,
853   [AC_LANG_SAVE
854   AC_LANG_CPLUSPLUS
855   AC_TRY_COMPILE([
856     #include &lt;cassert&gt;
857     #include &lt;cctype&gt;
858     #include &lt;cerrno&gt;
859     #include &lt;cfloat&gt;
860     #include &lt;ciso646&gt;
861     #include &lt;climits&gt;
862     #include &lt;clocale&gt;
863     #include &lt;cmath&gt;
864     #include &lt;csetjmp&gt;
865     #include &lt;csignal&gt;
866     #include &lt;cstdarg&gt;
867     #include &lt;cstddef&gt;
868     #include &lt;cstdio&gt;
869     #include &lt;cstdlib&gt;
870     #include &lt;cstring&gt;
871     #include &lt;ctime&gt;
872
873     #include &lt;algorithm&gt;
874     #include &lt;bitset&gt;
875     #include &lt;complex&gt;
876     #include &lt;deque&gt;
877     #include &lt;exception&gt;
878     #include &lt;fstream&gt;
879     #include &lt;functional&gt;
880     #include &lt;iomanip&gt;
881     #include &lt;ios&gt;
882     #include &lt;iosfwd&gt;
883     #include &lt;iostream&gt;
884     #include &lt;istream&gt;
885     #include &lt;iterator&gt;
886     #include &lt;limits&gt;
887     #include &lt;list&gt;
888     #include &lt;locale&gt;
889     #include &lt;map&gt;
890     #include &lt;memory&gt;
891     #include &lt;new&gt;
892     #include &lt;numeric&gt;
893     #include &lt;ostream&gt;
894     #include &lt;queue&gt;
895     #include &lt;set&gt;
896     #include &lt;sstream&gt;
897     #include &lt;stack&gt;
898     #include &lt;stdexcept&gt;
899     #include &lt;streambuf&gt;
900     #include &lt;string&gt;
901     #include &lt;typeinfo&gt;
902     #include &lt;utility&gt;
903     #include &lt;valarray&gt;
904     #include &lt;vector&gt;
905   ],,
906   ac_cv_cxx_stdcxx_98=yes, ac_cv_cxx_stdcxx_98=no)
907   AC_LANG_RESTORE
908   ])
909   if test "$ac_cv_cxx_stdcxx_98" = yes; then
910     AC_DEFINE(STDCXX_98_HEADERS,,[Define if ISO C++ 1998 header files are present. ])
911   fi
912 ])
913 </programlisting>
914 </sect3>
915
916 <sect3>
917 <title>
918 Support for C++TR1 dialect.
919 </title>
920
921 <para>Check for library coverage of the TR1 standard.
922 </para>
923
924 <programlisting>
925 # AC_HEADER_STDCXX_TR1
926 AC_DEFUN([AC_HEADER_STDCXX_TR1], [
927   AC_CACHE_CHECK(for ISO C++ TR1 include files,
928   ac_cv_cxx_stdcxx_tr1,
929   [AC_LANG_SAVE
930   AC_LANG_CPLUSPLUS
931   AC_TRY_COMPILE([
932   #include &lt;tr1/array&gt;
933   #include &lt;tr1/ccomplex&gt;
934   #include &lt;tr1/cctype&gt;
935   #include &lt;tr1/cfenv&gt;
936   #include &lt;tr1/cfloat&gt;
937   #include &lt;tr1/cinttypes&gt;
938   #include &lt;tr1/climits&gt;
939   #include &lt;tr1/cmath&gt;
940   #include &lt;tr1/complex&gt;
941   #include &lt;tr1/cstdarg&gt;
942   #include &lt;tr1/cstdbool&gt;
943   #include &lt;tr1/cstdint&gt;
944   #include &lt;tr1/cstdio&gt;
945   #include &lt;tr1/cstdlib&gt;
946   #include &lt;tr1/ctgmath&gt;
947   #include &lt;tr1/ctime&gt;
948   #include &lt;tr1/cwchar&gt;
949   #include &lt;tr1/cwctype&gt;
950   #include &lt;tr1/functional&gt;
951   #include &lt;tr1/memory&gt;
952   #include &lt;tr1/random&gt;
953   #include &lt;tr1/regex&gt;
954   #include &lt;tr1/tuple&gt;
955   #include &lt;tr1/type_traits&gt;
956   #include &lt;tr1/unordered_set&gt;
957   #include &lt;tr1/unordered_map&gt;
958   #include &lt;tr1/utility&gt;
959   ],,
960   ac_cv_cxx_stdcxx_tr1=yes, ac_cv_cxx_stdcxx_tr1=no)
961   AC_LANG_RESTORE
962   ])
963   if test "$ac_cv_cxx_stdcxx_tr1" = yes; then
964     AC_DEFINE(STDCXX_TR1_HEADERS,,[Define if ISO C++ TR1 header files are present. ])
965   fi
966 ])
967 </programlisting>
968
969 <para>An alternative is to check just for specific TR1 includes, such as &lt;unordered_map&gt; and &lt;unordered_set&gt;.
970 </para>
971
972 <programlisting>
973 # AC_HEADER_TR1_UNORDERED_MAP
974 AC_DEFUN([AC_HEADER_TR1_UNORDERED_MAP], [
975   AC_CACHE_CHECK(for tr1/unordered_map,
976   ac_cv_cxx_tr1_unordered_map,
977   [AC_LANG_SAVE
978   AC_LANG_CPLUSPLUS
979   AC_TRY_COMPILE([#include &lt;tr1/unordered_map&gt;], [using std::tr1::unordered_map;],
980   ac_cv_cxx_tr1_unordered_map=yes, ac_cv_cxx_tr1_unordered_map=no)
981   AC_LANG_RESTORE
982   ])
983   if test "$ac_cv_cxx_tr1_unordered_map" = yes; then
984     AC_DEFINE(HAVE_TR1_UNORDERED_MAP,,[Define if tr1/unordered_map is present. ])
985   fi
986 ])
987 </programlisting>
988
989 <programlisting>
990 # AC_HEADER_TR1_UNORDERED_SET
991 AC_DEFUN([AC_HEADER_TR1_UNORDERED_SET], [
992   AC_CACHE_CHECK(for tr1/unordered_set,
993   ac_cv_cxx_tr1_unordered_set,
994   [AC_LANG_SAVE
995   AC_LANG_CPLUSPLUS
996   AC_TRY_COMPILE([#include &lt;tr1/unordered_set&gt;], [using std::tr1::unordered_set;],
997   ac_cv_cxx_tr1_unordered_set=yes, ac_cv_cxx_tr1_unordered_set=no)
998   AC_LANG_RESTORE
999   ])
1000   if test "$ac_cv_cxx_tr1_unordered_set" = yes; then
1001     AC_DEFINE(HAVE_TR1_UNORDERED_SET,,[Define if tr1/unordered_set is present. ])
1002   fi
1003 ])
1004 </programlisting>
1005 </sect3>
1006
1007
1008 <sect3>
1009 <title>
1010 Support for C++0x dialect.
1011 </title>
1012
1013 <para>Check for baseline language coverage in the compiler for the C++0xstandard.
1014 </para>
1015
1016 <programlisting>
1017 # AC_COMPILE_STDCXX_OX
1018 AC_DEFUN([AC_COMPILE_STDCXX_0X], [
1019   AC_CACHE_CHECK(if g++ supports C++0x features without additional flags,
1020   ac_cv_cxx_compile_cxx0x_native,
1021   [AC_LANG_SAVE
1022   AC_LANG_CPLUSPLUS
1023   AC_TRY_COMPILE([
1024   template &lt;typename T&gt;
1025     struct check 
1026     {
1027       static_assert(sizeof(int) &lt;= sizeof(T), "not big enough");
1028     };
1029
1030     typedef check&lt;check&lt;bool&gt;&gt; right_angle_brackets;
1031
1032     int a;
1033     decltype(a) b;
1034
1035     typedef check&lt;int&gt; check_type;
1036     check_type c;
1037     check_type&amp;&amp; cr = c;],,
1038   ac_cv_cxx_compile_cxx0x_native=yes, ac_cv_cxx_compile_cxx0x_native=no)
1039   AC_LANG_RESTORE
1040   ])
1041
1042   AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x,
1043   ac_cv_cxx_compile_cxx0x_cxx,
1044   [AC_LANG_SAVE
1045   AC_LANG_CPLUSPLUS
1046   ac_save_CXXFLAGS="$CXXFLAGS"
1047   CXXFLAGS="$CXXFLAGS -std=c++0x"       
1048   AC_TRY_COMPILE([
1049   template &lt;typename T&gt;
1050     struct check 
1051     {
1052       static_assert(sizeof(int) &lt;= sizeof(T), "not big enough");
1053     };
1054
1055     typedef check&lt;check&lt;bool&gt;&gt; right_angle_brackets;
1056
1057     int a;
1058     decltype(a) b;
1059
1060     typedef check&lt;int&gt; check_type;
1061     check_type c;
1062     check_type&amp;&amp; cr = c;],,
1063   ac_cv_cxx_compile_cxx0x_cxx=yes, ac_cv_cxx_compile_cxx0x_cxx=no)
1064   CXXFLAGS="$ac_save_CXXFLAGS"
1065   AC_LANG_RESTORE
1066   ])
1067
1068   AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x,
1069   ac_cv_cxx_compile_cxx0x_gxx,
1070   [AC_LANG_SAVE
1071   AC_LANG_CPLUSPLUS
1072   ac_save_CXXFLAGS="$CXXFLAGS"
1073   CXXFLAGS="$CXXFLAGS -std=gnu++0x"     
1074   AC_TRY_COMPILE([
1075   template &lt;typename T&gt;
1076     struct check 
1077     {
1078       static_assert(sizeof(int) &lt;= sizeof(T), "not big enough");
1079     };
1080
1081     typedef check&lt;check&lt;bool&gt;&gt; right_angle_brackets;
1082
1083     int a;
1084     decltype(a) b;
1085
1086     typedef check&lt;int&gt; check_type;
1087     check_type c;
1088     check_type&amp;&amp; cr = c;],,
1089   ac_cv_cxx_compile_cxx0x_gxx=yes, ac_cv_cxx_compile_cxx0x_gxx=no)
1090   CXXFLAGS="$ac_save_CXXFLAGS"
1091   AC_LANG_RESTORE
1092   ])
1093
1094   if test "$ac_cv_cxx_compile_cxx0x_native" = yes || 
1095      test "$ac_cv_cxx_compile_cxx0x_cxx" = yes || 
1096      test "$ac_cv_cxx_compile_cxx0x_gxx" = yes; then
1097     AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ])
1098   fi
1099 ])
1100 </programlisting>
1101
1102
1103 <para>Check for library coverage of the C++0xstandard.
1104 </para>
1105
1106 <programlisting>
1107 # AC_HEADER_STDCXX_0X
1108 AC_DEFUN([AC_HEADER_STDCXX_0X], [
1109   AC_CACHE_CHECK(for ISO C++ 0x include files,
1110   ac_cv_cxx_stdcxx_0x,
1111   [AC_REQUIRE([AC_COMPILE_STDCXX_0X])
1112   AC_LANG_SAVE
1113   AC_LANG_CPLUSPLUS
1114   ac_save_CXXFLAGS="$CXXFLAGS"
1115   CXXFLAGS="$CXXFLAGS -std=gnu++0x"     
1116
1117   AC_TRY_COMPILE([
1118     #include &lt;cassert&gt;
1119     #include &lt;ccomplex&gt;
1120     #include &lt;cctype&gt;
1121     #include &lt;cerrno&gt;
1122     #include &lt;cfenv&gt;
1123     #include &lt;cfloat&gt;
1124     #include &lt;cinttypes&gt;
1125     #include &lt;ciso646&gt;
1126     #include &lt;climits&gt;
1127     #include &lt;clocale&gt;
1128     #include &lt;cmath&gt;
1129     #include &lt;csetjmp&gt;
1130     #include &lt;csignal&gt;
1131     #include &lt;cstdarg&gt;
1132     #include &lt;cstdbool&gt;
1133     #include &lt;cstddef&gt;
1134     #include &lt;cstdint&gt;
1135     #include &lt;cstdio&gt;
1136     #include &lt;cstdlib&gt;
1137     #include &lt;cstring&gt;
1138     #include &lt;ctgmath&gt;
1139     #include &lt;ctime&gt;
1140     #include &lt;cwchar&gt;
1141     #include &lt;cwctype&gt;
1142
1143     #include &lt;algorithm&gt;
1144     #include &lt;array&gt;
1145     #include &lt;bitset&gt;
1146     #include &lt;complex&gt;
1147     #include &lt;deque&gt;
1148     #include &lt;exception&gt;
1149     #include &lt;fstream&gt;
1150     #include &lt;functional&gt;
1151     #include &lt;iomanip&gt;
1152     #include &lt;ios&gt;
1153     #include &lt;iosfwd&gt;
1154     #include &lt;iostream&gt;
1155     #include &lt;istream&gt;
1156     #include &lt;iterator&gt;
1157     #include &lt;limits&gt;
1158     #include &lt;list&gt;
1159     #include &lt;locale&gt;
1160     #include &lt;map&gt;
1161     #include &lt;memory&gt;
1162     #include &lt;new&gt;
1163     #include &lt;numeric&gt;
1164     #include &lt;ostream&gt;
1165     #include &lt;queue&gt;
1166     #include &lt;random&gt;
1167     #include &lt;regex&gt;
1168     #include &lt;set&gt;
1169     #include &lt;sstream&gt;
1170     #include &lt;stack&gt;
1171     #include &lt;stdexcept&gt;
1172     #include &lt;streambuf&gt;
1173     #include &lt;string&gt;
1174     #include &lt;tuple&gt;
1175     #include &lt;typeinfo&gt;
1176     #include &lt;type_traits&gt;
1177     #include &lt;unordered_map&gt;
1178     #include &lt;unordered_set&gt;
1179     #include &lt;utility&gt;
1180     #include &lt;valarray&gt;
1181     #include &lt;vector&gt;
1182   ],,
1183   ac_cv_cxx_stdcxx_0x=yes, ac_cv_cxx_stdcxx_0x=no)
1184   AC_LANG_RESTORE
1185   CXXFLAGS="$ac_save_CXXFLAGS"
1186   ])
1187   if test "$ac_cv_cxx_stdcxx_0x" = yes; then
1188     AC_DEFINE(STDCXX_0X_HEADERS,,[Define if ISO C++ 0x header files are present. ])
1189   fi
1190 ])
1191 </programlisting>
1192
1193 <para>As is the case for TR1 support, these autoconf macros can be made for a finer-grained, per-header-file check. For &lt;unordered_map&gt;
1194 </para>
1195
1196 <programlisting>
1197 # AC_HEADER_UNORDERED_MAP
1198 AC_DEFUN([AC_HEADER_UNORDERED_MAP], [
1199   AC_CACHE_CHECK(for unordered_map,
1200   ac_cv_cxx_unordered_map,
1201   [AC_REQUIRE([AC_COMPILE_STDCXX_0X])
1202   AC_LANG_SAVE
1203   AC_LANG_CPLUSPLUS
1204   ac_save_CXXFLAGS="$CXXFLAGS"
1205   CXXFLAGS="$CXXFLAGS -std=gnu++0x"     
1206   AC_TRY_COMPILE([#include &lt;unordered_map&gt;], [using std::unordered_map;],
1207   ac_cv_cxx_unordered_map=yes, ac_cv_cxx_unordered_map=no)
1208   CXXFLAGS="$ac_save_CXXFLAGS"
1209   AC_LANG_RESTORE
1210   ])
1211   if test "$ac_cv_cxx_unordered_map" = yes; then
1212     AC_DEFINE(HAVE_UNORDERED_MAP,,[Define if unordered_map is present. ])
1213   fi
1214 ])
1215 </programlisting>
1216
1217 <programlisting>
1218 # AC_HEADER_UNORDERED_SET
1219 AC_DEFUN([AC_HEADER_UNORDERED_SET], [
1220   AC_CACHE_CHECK(for unordered_set,
1221   ac_cv_cxx_unordered_set,
1222   [AC_REQUIRE([AC_COMPILE_STDCXX_0X])
1223   AC_LANG_SAVE
1224   AC_LANG_CPLUSPLUS
1225   ac_save_CXXFLAGS="$CXXFLAGS"
1226   CXXFLAGS="$CXXFLAGS -std=gnu++0x"     
1227   AC_TRY_COMPILE([#include &lt;unordered_set&gt;], [using std::unordered_set;],
1228   ac_cv_cxx_unordered_set=yes, ac_cv_cxx_unordered_set=no)
1229   CXXFLAGS="$ac_save_CXXFLAGS"
1230   AC_LANG_RESTORE
1231   ])
1232   if test "$ac_cv_cxx_unordered_set" = yes; then
1233     AC_DEFINE(HAVE_UNORDERED_SET,,[Define if unordered_set is present. ])
1234   fi
1235 ])
1236 </programlisting>
1237 </sect3>
1238
1239 <sect3>
1240 <title>
1241   Container::iterator_type is not necessarily Container::value_type*
1242 </title>
1243
1244 <para>
1245   This is a change in behavior from the previous version. Now, most
1246   <type>iterator_type</type> typedefs in container classes are POD
1247   objects, not <type>value_type</type> pointers.
1248 </para>
1249 </sect3>
1250
1251 </sect2>
1252
1253 <bibliography id="backwards.biblio" xreflabel="backwards.biblio">
1254 <title>Bibliography</title>
1255
1256   <biblioentry>
1257     <abbrev>
1258       kegel41
1259     </abbrev>
1260
1261     <title>
1262       Migrating to GCC 4.1
1263     </title>
1264
1265     <author>
1266       <firstname>Dan</firstname>
1267       <surname>Kegel</surname>
1268     </author>
1269
1270     <biblioid>
1271       <ulink url="http://www.kegel.com/gcc/gcc4.html">
1272       </ulink>
1273     </biblioid>
1274   </biblioentry> 
1275
1276
1277   <biblioentry>
1278     <abbrev>
1279       kegel41
1280     </abbrev>
1281
1282     <title>
1283       Building the Whole Debian Archive with GCC 4.1: A Summary
1284     </title>
1285
1286     <author>
1287       <firstname>Martin</firstname>
1288       <surname>Michlmayr</surname>
1289     </author>
1290
1291     <biblioid>
1292       <ulink url="http://lists.debian.org/debian-gcc/2006/03/msg00405.html">
1293       </ulink>
1294     </biblioid>
1295   </biblioentry> 
1296
1297
1298   <biblioentry>
1299     <abbrev>
1300       lbl32
1301     </abbrev>
1302
1303     <title>
1304       Migration guide for GCC-3.2
1305     </title>
1306
1307     <biblioid>
1308       <ulink url="http://annwm.lbl.gov/~leggett/Atlas/gcc-3.2.html">
1309       </ulink>
1310     </biblioid>
1311   </biblioentry> 
1312
1313 </bibliography>
1314
1315 </sect1>