1<section xmlns="http://docbook.org/ns/docbook" version="5.0"
2	 xml:id="manual.appendix.porting.backwards" xreflabel="backwards">
3<?dbhtml filename="backwards.html"?>
4
5<info><title>Backwards Compatibility</title>
6  <keywordset>
7    <keyword>ISO C++</keyword>
8    <keyword>backwards</keyword>
9  </keywordset>
10</info>
11
12
13
14<section xml:id="backwards.first"><info><title>First</title></info>
15
16
17<para>The first generation GNU C++ library was called libg++.  It was a
18separate GNU project, although reliably paired with GCC. Rumors imply
19that it had a working relationship with at least two kinds of
20dinosaur.
21</para>
22
23<para>Some background: libg++ was designed and created when there was no
24ISO standard to provide guidance.  Classes like linked lists are now
25provided for by <classname>std::list&lt;T&gt;</classname> and do not need to be
26created by <function>genclass</function>.  (For that matter, templates exist
27now and are well-supported, whereas genclass (mostly) predates them.)
28</para>
29
30<para>There are other classes in libg++ that are not specified in the
31ISO Standard (e.g., statistical analysis).  While there are a lot of
32really useful things that are used by a lot of people, the Standards
33Committee couldn't include everything, and so a lot of those
34<quote>obvious</quote> classes didn't get included.
35</para>
36
37<para>That project is no longer maintained or supported, and the sources
38archived. For the desperate, the
39<link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://ftp.gnu.org/old-gnu/libg++/">ftp.gnu.org</link>
40server still has the libg++ source.
41</para>
42</section>
43
44<section xml:id="backwards.second"><info><title>Second</title></info>
45
46
47<para>
48  The second generation GNU C++ library was called libstdc++, or
49  libstdc++-v2. It spans the time between libg++ and pre-ISO C++
50  standardization and is usually associated with the following GCC
51  releases: egcs 1.x, gcc 2.95, and gcc 2.96.
52</para>
53
54<para>
55  The STL portions of that library are based on SGI/HP STL release 3.11.
56</para>
57
58<para>
59  That project is no longer maintained or supported, and the sources
60  archived.  The code was replaced and rewritten for libstdc++-v3.
61</para>
62
63</section>
64
65<section xml:id="backwards.third"><info><title>Third</title></info>
66
67
68<para> The third generation GNU C++ library is called libstdc++, or
69libstdc++-v3.
70</para>
71
72      <para>The subset commonly known as the Standard Template Library
73	 (clauses 23 through 25 in C++98, mostly) is adapted from the final release
74	 of the SGI STL (version 3.3), with extensive changes.
75      </para>
76
77      <para>A more formal description of the V3 goals can be found in the
78	 official <link linkend="contrib.design_notes">design document</link>.
79      </para>
80
81<para>Portability notes and known implementation limitations are as follows.</para>
82
83<section xml:id="backwards.third.headers"><info><title>Pre-ISO headers removed</title></info>
84
85
86<para> The pre-ISO C++ headers
87      (<filename class="headerfile">&lt;iostream.h&gt;</filename>,
88      <filename class="headerfile">&lt;defalloc.h&gt;</filename> etc.) are
89      not supported.
90</para>
91
92   <para>For those of you new to ISO C++ (welcome, time travelers!), the
93      ancient pre-ISO headers have new names.
94      The C++ FAQ has a good explanation in <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://isocpp.org/wiki/faq/coding-standards#std-headers">What's
95      the difference between &lt;xxx&gt; and &lt;xxx.h&gt; headers?</link>.
96   </para>
97
98<para>Porting between pre-ISO headers and ISO headers is simple: headers
99like <filename class="headerfile">&lt;vector.h&gt;</filename> can be replaced with <filename class="headerfile">&lt;vector&gt;</filename> and a using
100directive <code>using namespace std;</code> can be put at the global
101scope. This should be enough to get this code compiling, assuming the
102other usage is correct.
103</para>
104</section>
105
106<section xml:id="backwards.third.hash"><info><title>Extension headers hash_map, hash_set moved to ext or backwards</title></info>
107
108
109      <para>At this time most of the features of the SGI STL extension have been
110	 replaced by standardized libraries.
111	 In particular, the <classname>unordered_map</classname> and
112	 <classname>unordered_set</classname> containers of TR1 and C++ 2011
113	 are suitable replacements for the non-standard
114	 <classname>hash_map</classname> and <classname>hash_set</classname>
115	 containers in the SGI STL.
116      </para>
117<para> Header files <filename class="headerfile">&lt;hash_map&gt;</filename> and <filename class="headerfile">&lt;hash_set&gt;</filename> moved
118to <filename class="headerfile">&lt;ext/hash_map&gt;</filename> and  <filename class="headerfile">&lt;ext/hash_set&gt;</filename>,
119respectively. At the same time, all types in these files are enclosed
120in <code>namespace __gnu_cxx</code>. Later versions deprecate
121these files, and suggest using TR1's  <filename class="headerfile">&lt;unordered_map&gt;</filename>
122and  <filename class="headerfile">&lt;unordered_set&gt;</filename> instead.
123</para>
124
125      <para>The extensions are no longer in the global or <code>std</code>
126	 namespaces, instead they are declared in the <code>__gnu_cxx</code>
127	 namespace. For maximum portability, consider defining a namespace
128	 alias to use to talk about extensions, e.g.:
129      </para>
130      <programlisting>
131      #ifdef __GNUC__
132      #if __GNUC__ &lt; 3
133	#include &lt;hash_map.h&gt;
134	namespace extension { using ::hash_map; }; // inherit globals
135      #else
136	#include &lt;backward/hash_map&gt;
137	#if __GNUC__ == 3 &amp;&amp; __GNUC_MINOR__ == 0
138	  namespace extension = std;               // GCC 3.0
139	#else
140	  namespace extension = ::__gnu_cxx;       // GCC 3.1 and later
141	#endif
142      #endif
143      #else      // ...  there are other compilers, right?
144	namespace extension = std;
145      #endif
146
147      extension::hash_map&lt;int,int&gt; my_map;
148      </programlisting>
149      <para>This is a bit cleaner than defining typedefs for all the
150	 instantiations you might need.
151      </para>
152
153
154<para>The following autoconf tests check for working HP/SGI hash containers.
155</para>
156
157<programlisting>
158# AC_HEADER_EXT_HASH_MAP
159AC_DEFUN([AC_HEADER_EXT_HASH_MAP], [
160  AC_CACHE_CHECK(for ext/hash_map,
161  ac_cv_cxx_ext_hash_map,
162  [AC_LANG_SAVE
163  AC_LANG_CPLUSPLUS
164  ac_save_CXXFLAGS="$CXXFLAGS"
165  CXXFLAGS="$CXXFLAGS -Werror"
166  AC_TRY_COMPILE([#include &lt;ext/hash_map&gt;], [using __gnu_cxx::hash_map;],
167  ac_cv_cxx_ext_hash_map=yes, ac_cv_cxx_ext_hash_map=no)
168  CXXFLAGS="$ac_save_CXXFLAGS"
169  AC_LANG_RESTORE
170  ])
171  if test "$ac_cv_cxx_ext_hash_map" = yes; then
172    AC_DEFINE(HAVE_EXT_HASH_MAP,,[Define if ext/hash_map is present. ])
173  fi
174])
175</programlisting>
176
177<programlisting>
178# AC_HEADER_EXT_HASH_SET
179AC_DEFUN([AC_HEADER_EXT_HASH_SET], [
180  AC_CACHE_CHECK(for ext/hash_set,
181  ac_cv_cxx_ext_hash_set,
182  [AC_LANG_SAVE
183  AC_LANG_CPLUSPLUS
184  ac_save_CXXFLAGS="$CXXFLAGS"
185  CXXFLAGS="$CXXFLAGS -Werror"
186  AC_TRY_COMPILE([#include &lt;ext/hash_set&gt;], [using __gnu_cxx::hash_set;],
187  ac_cv_cxx_ext_hash_set=yes, ac_cv_cxx_ext_hash_set=no)
188  CXXFLAGS="$ac_save_CXXFLAGS"
189  AC_LANG_RESTORE
190  ])
191  if test "$ac_cv_cxx_ext_hash_set" = yes; then
192    AC_DEFINE(HAVE_EXT_HASH_SET,,[Define if ext/hash_set is present. ])
193  fi
194])
195</programlisting>
196</section>
197
198<section xml:id="backwards.third.nocreate_noreplace"><info><title>No <code>ios::nocreate/ios::noreplace</code>.
199</title></info>
200
201
202<para>Historically these flags were used with iostreams to control whether
203new files are created or not when opening a file stream, similar to the
204<code>O_CREAT</code> and <code>O_EXCL</code> flags for the
205<function>open(2)</function> system call. Because iostream modes correspond
206to <function>fopen(3)</function> modes these flags are not supported.
207For input streams a new file will not be created anyway, so
208<code>ios::nocreate</code> is not needed.
209For output streams, a new file will be created if it does not exist, which is
210consistent with the behaviour of <function>fopen</function>.
211</para>
212
213<para>When one of these flags is needed a possible alternative is to attempt
214to open the file using <type>std::ifstream</type> first to determine whether
215the file already exists or not. This may not be reliable however, because
216whether the file exists or not could change between opening the
217<type>std::istream</type> and re-opening with an output stream. If you need
218to check for existence and open a file as a single operation then you will
219need to use OS-specific facilities outside the C++ standard library, such
220as <function>open(2)</function>.
221</para>
222</section>
223
224<section xml:id="backwards.third.streamattach"><info><title>
225No <code>stream::attach(int fd)</code>
226</title></info>
227
228
229<para>
230      Phil Edwards writes: It was considered and rejected for the ISO
231      standard.  Not all environments use file descriptors.  Of those
232      that do, not all of them use integers to represent them.
233    </para>
234
235<para>
236      For a portable solution (among systems which use
237      file descriptors), you need to implement a subclass of
238      <code>std::streambuf</code> (or
239      <code>std::basic_streambuf&lt;..&gt;</code>) which opens a file
240      given a descriptor, and then pass an instance of this to the
241      stream-constructor.
242    </para>
243
244<para>
245      An extension is available that implements this.
246      <filename class="headerfile">&lt;ext/stdio_filebuf.h&gt;</filename>
247      contains a derived class called
248      <classname>__gnu_cxx::stdio_filebuf</classname>.
249      This class can be constructed from a C <code>FILE*</code> or a file
250      descriptor, and provides the <code>fd()</code> function.
251    </para>
252
253<para>
254 For another example of this, refer to
255      <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.josuttis.com/cppcode/fdstream.html">fdstream example</link>
256      by Nicolai Josuttis.
257</para>
258</section>
259
260<section xml:id="backwards.third.support_cxx98"><info><title>
261Support for C++98 dialect.
262</title></info>
263
264
265<para>Check for complete library coverage of the C++1998/2003 standard.
266</para>
267
268<programlisting>
269# AC_HEADER_STDCXX_98
270AC_DEFUN([AC_HEADER_STDCXX_98], [
271  AC_CACHE_CHECK(for ISO C++ 98 include files,
272  ac_cv_cxx_stdcxx_98,
273  [AC_LANG_SAVE
274  AC_LANG_CPLUSPLUS
275  AC_TRY_COMPILE([
276    #include &lt;cassert&gt;
277    #include &lt;cctype&gt;
278    #include &lt;cerrno&gt;
279    #include &lt;cfloat&gt;
280    #include &lt;ciso646&gt;
281    #include &lt;climits&gt;
282    #include &lt;clocale&gt;
283    #include &lt;cmath&gt;
284    #include &lt;csetjmp&gt;
285    #include &lt;csignal&gt;
286    #include &lt;cstdarg&gt;
287    #include &lt;cstddef&gt;
288    #include &lt;cstdio&gt;
289    #include &lt;cstdlib&gt;
290    #include &lt;cstring&gt;
291    #include &lt;ctime&gt;
292
293    #include &lt;algorithm&gt;
294    #include &lt;bitset&gt;
295    #include &lt;complex&gt;
296    #include &lt;deque&gt;
297    #include &lt;exception&gt;
298    #include &lt;fstream&gt;
299    #include &lt;functional&gt;
300    #include &lt;iomanip&gt;
301    #include &lt;ios&gt;
302    #include &lt;iosfwd&gt;
303    #include &lt;iostream&gt;
304    #include &lt;istream&gt;
305    #include &lt;iterator&gt;
306    #include &lt;limits&gt;
307    #include &lt;list&gt;
308    #include &lt;locale&gt;
309    #include &lt;map&gt;
310    #include &lt;memory&gt;
311    #include &lt;new&gt;
312    #include &lt;numeric&gt;
313    #include &lt;ostream&gt;
314    #include &lt;queue&gt;
315    #include &lt;set&gt;
316    #include &lt;sstream&gt;
317    #include &lt;stack&gt;
318    #include &lt;stdexcept&gt;
319    #include &lt;streambuf&gt;
320    #include &lt;string&gt;
321    #include &lt;typeinfo&gt;
322    #include &lt;utility&gt;
323    #include &lt;valarray&gt;
324    #include &lt;vector&gt;
325  ],,
326  ac_cv_cxx_stdcxx_98=yes, ac_cv_cxx_stdcxx_98=no)
327  AC_LANG_RESTORE
328  ])
329  if test "$ac_cv_cxx_stdcxx_98" = yes; then
330    AC_DEFINE(STDCXX_98_HEADERS,,[Define if ISO C++ 1998 header files are present. ])
331  fi
332])
333</programlisting>
334</section>
335
336<section xml:id="backwards.third.support_tr1"><info><title>
337Support for C++TR1 dialect.
338</title></info>
339
340
341<para>Check for library coverage of the TR1 standard.
342</para>
343
344<programlisting>
345# AC_HEADER_STDCXX_TR1
346AC_DEFUN([AC_HEADER_STDCXX_TR1], [
347  AC_CACHE_CHECK(for ISO C++ TR1 include files,
348  ac_cv_cxx_stdcxx_tr1,
349  [AC_LANG_SAVE
350  AC_LANG_CPLUSPLUS
351  AC_TRY_COMPILE([
352  #include &lt;tr1/array&gt;
353  #include &lt;tr1/ccomplex&gt;
354  #include &lt;tr1/cctype&gt;
355  #include &lt;tr1/cfenv&gt;
356  #include &lt;tr1/cfloat&gt;
357  #include &lt;tr1/cinttypes&gt;
358  #include &lt;tr1/climits&gt;
359  #include &lt;tr1/cmath&gt;
360  #include &lt;tr1/complex&gt;
361  #include &lt;tr1/cstdarg&gt;
362  #include &lt;tr1/cstdbool&gt;
363  #include &lt;tr1/cstdint&gt;
364  #include &lt;tr1/cstdio&gt;
365  #include &lt;tr1/cstdlib&gt;
366  #include &lt;tr1/ctgmath&gt;
367  #include &lt;tr1/ctime&gt;
368  #include &lt;tr1/cwchar&gt;
369  #include &lt;tr1/cwctype&gt;
370  #include &lt;tr1/functional&gt;
371  #include &lt;tr1/memory&gt;
372  #include &lt;tr1/random&gt;
373  #include &lt;tr1/regex&gt;
374  #include &lt;tr1/tuple&gt;
375  #include &lt;tr1/type_traits&gt;
376  #include &lt;tr1/unordered_set&gt;
377  #include &lt;tr1/unordered_map&gt;
378  #include &lt;tr1/utility&gt;
379  ],,
380  ac_cv_cxx_stdcxx_tr1=yes, ac_cv_cxx_stdcxx_tr1=no)
381  AC_LANG_RESTORE
382  ])
383  if test "$ac_cv_cxx_stdcxx_tr1" = yes; then
384    AC_DEFINE(STDCXX_TR1_HEADERS,,[Define if ISO C++ TR1 header files are present. ])
385  fi
386])
387</programlisting>
388
389<para>An alternative is to check just for specific TR1 includes, such as &lt;unordered_map&gt; and &lt;unordered_set&gt;.
390</para>
391
392<programlisting>
393# AC_HEADER_TR1_UNORDERED_MAP
394AC_DEFUN([AC_HEADER_TR1_UNORDERED_MAP], [
395  AC_CACHE_CHECK(for tr1/unordered_map,
396  ac_cv_cxx_tr1_unordered_map,
397  [AC_LANG_SAVE
398  AC_LANG_CPLUSPLUS
399  AC_TRY_COMPILE([#include &lt;tr1/unordered_map&gt;], [using std::tr1::unordered_map;],
400  ac_cv_cxx_tr1_unordered_map=yes, ac_cv_cxx_tr1_unordered_map=no)
401  AC_LANG_RESTORE
402  ])
403  if test "$ac_cv_cxx_tr1_unordered_map" = yes; then
404    AC_DEFINE(HAVE_TR1_UNORDERED_MAP,,[Define if tr1/unordered_map is present. ])
405  fi
406])
407</programlisting>
408
409<programlisting>
410# AC_HEADER_TR1_UNORDERED_SET
411AC_DEFUN([AC_HEADER_TR1_UNORDERED_SET], [
412  AC_CACHE_CHECK(for tr1/unordered_set,
413  ac_cv_cxx_tr1_unordered_set,
414  [AC_LANG_SAVE
415  AC_LANG_CPLUSPLUS
416  AC_TRY_COMPILE([#include &lt;tr1/unordered_set&gt;], [using std::tr1::unordered_set;],
417  ac_cv_cxx_tr1_unordered_set=yes, ac_cv_cxx_tr1_unordered_set=no)
418  AC_LANG_RESTORE
419  ])
420  if test "$ac_cv_cxx_tr1_unordered_set" = yes; then
421    AC_DEFINE(HAVE_TR1_UNORDERED_SET,,[Define if tr1/unordered_set is present. ])
422  fi
423])
424</programlisting>
425</section>
426
427
428<section xml:id="backwards.third.support_cxx11"><info><title>
429Support for C++11 dialect.
430</title></info>
431
432
433<para>Check for baseline language coverage in the compiler for the C++11 standard.
434</para>
435
436<programlisting>
437# AC_COMPILE_STDCXX_11
438AC_DEFUN([AC_COMPILE_STDCXX_11], [
439  AC_CACHE_CHECK(if g++ supports C++11 features without additional flags,
440  ac_cv_cxx_compile_cxx11_native,
441  [AC_LANG_SAVE
442  AC_LANG_CPLUSPLUS
443  AC_TRY_COMPILE([
444  template &lt;typename T&gt;
445    struct check final
446    {
447      static constexpr T value{ __cplusplus };
448    };
449
450    typedef check&lt;check&lt;bool&gt;&gt; right_angle_brackets;
451
452    int a;
453    decltype(a) b;
454
455    typedef check&lt;int&gt; check_type;
456    check_type c{};
457    check_type&amp;&amp; cr = static_cast&lt;check_type&amp;&amp;&gt;(c);
458
459    static_assert(check_type::value == 201103L, "C++11 compiler");],,
460  ac_cv_cxx_compile_cxx11_native=yes, ac_cv_cxx_compile_cxx11_native=no)
461  AC_LANG_RESTORE
462  ])
463
464  AC_CACHE_CHECK(if g++ supports C++11 features with -std=c++11,
465  ac_cv_cxx_compile_cxx11_cxx,
466  [AC_LANG_SAVE
467  AC_LANG_CPLUSPLUS
468  ac_save_CXXFLAGS="$CXXFLAGS"
469  CXXFLAGS="$CXXFLAGS -std=c++11"
470  AC_TRY_COMPILE([
471  template &lt;typename T&gt;
472    struct check final
473    {
474      static constexpr T value{ __cplusplus };
475    };
476
477    typedef check&lt;check&lt;bool&gt;&gt; right_angle_brackets;
478
479    int a;
480    decltype(a) b;
481
482    typedef check&lt;int&gt; check_type;
483    check_type c{};
484    check_type&amp;&amp; cr = static_cast&lt;check_type&amp;&amp;&gt;(c);
485
486    static_assert(check_type::value == 201103L, "C++11 compiler");],,
487  ac_cv_cxx_compile_cxx11_cxx=yes, ac_cv_cxx_compile_cxx11_cxx=no)
488  CXXFLAGS="$ac_save_CXXFLAGS"
489  AC_LANG_RESTORE
490  ])
491
492  AC_CACHE_CHECK(if g++ supports C++11 features with -std=gnu++11,
493  ac_cv_cxx_compile_cxx11_gxx,
494  [AC_LANG_SAVE
495  AC_LANG_CPLUSPLUS
496  ac_save_CXXFLAGS="$CXXFLAGS"
497  CXXFLAGS="$CXXFLAGS -std=gnu++11"
498  AC_TRY_COMPILE([
499  template &lt;typename T&gt;
500    struct check final
501    {
502      static constexpr T value{ __cplusplus };
503    };
504
505    typedef check&lt;check&lt;bool&gt;&gt; right_angle_brackets;
506
507    int a;
508    decltype(a) b;
509
510    typedef check&lt;int&gt; check_type;
511    check_type c{};
512    check_type&amp;&amp; cr = static_cast&lt;check_type&amp;&amp;&gt;(c);
513
514    static_assert(check_type::value == 201103L, "C++11 compiler");],,
515  ac_cv_cxx_compile_cxx11_gxx=yes, ac_cv_cxx_compile_cxx11_gxx=no)
516  CXXFLAGS="$ac_save_CXXFLAGS"
517  AC_LANG_RESTORE
518  ])
519
520  if test "$ac_cv_cxx_compile_cxx11_native" = yes ||
521     test "$ac_cv_cxx_compile_cxx11_cxx" = yes ||
522     test "$ac_cv_cxx_compile_cxx11_gxx" = yes; then
523    AC_DEFINE(HAVE_STDCXX_11,,[Define if g++ supports C++11 features. ])
524  fi
525])
526</programlisting>
527
528
529<para>Check for library coverage of the C++2011 standard.
530  (Some library headers are commented out in this check, they are
531  not currently provided by libstdc++).
532</para>
533
534<programlisting>
535# AC_HEADER_STDCXX_11
536AC_DEFUN([AC_HEADER_STDCXX_11], [
537  AC_CACHE_CHECK(for ISO C++11 include files,
538  ac_cv_cxx_stdcxx_11,
539  [AC_REQUIRE([AC_COMPILE_STDCXX_11])
540  AC_LANG_SAVE
541  AC_LANG_CPLUSPLUS
542  ac_save_CXXFLAGS="$CXXFLAGS"
543  CXXFLAGS="$CXXFLAGS -std=gnu++11"
544
545  AC_TRY_COMPILE([
546    #include &lt;cassert&gt;
547    #include &lt;ccomplex&gt;
548    #include &lt;cctype&gt;
549    #include &lt;cerrno&gt;
550    #include &lt;cfenv&gt;
551    #include &lt;cfloat&gt;
552    #include &lt;cinttypes&gt;
553    #include &lt;ciso646&gt;
554    #include &lt;climits&gt;
555    #include &lt;clocale&gt;
556    #include &lt;cmath&gt;
557    #include &lt;csetjmp&gt;
558    #include &lt;csignal&gt;
559    #include &lt;cstdalign&gt;
560    #include &lt;cstdarg&gt;
561    #include &lt;cstdbool&gt;
562    #include &lt;cstddef&gt;
563    #include &lt;cstdint&gt;
564    #include &lt;cstdio&gt;
565    #include &lt;cstdlib&gt;
566    #include &lt;cstring&gt;
567    #include &lt;ctgmath&gt;
568    #include &lt;ctime&gt;
569    // #include &lt;cuchar&gt;
570    #include &lt;cwchar&gt;
571    #include &lt;cwctype&gt;
572
573    #include &lt;algorithm&gt;
574    #include &lt;array&gt;
575    #include &lt;atomic&gt;
576    #include &lt;bitset&gt;
577    #include &lt;chrono&gt;
578    // #include &lt;codecvt&gt;
579    #include &lt;complex&gt;
580    #include &lt;condition_variable&gt;
581    #include &lt;deque&gt;
582    #include &lt;exception&gt;
583    #include &lt;forward_list&gt;
584    #include &lt;fstream&gt;
585    #include &lt;functional&gt;
586    #include &lt;future&gt;
587    #include &lt;initializer_list&gt;
588    #include &lt;iomanip&gt;
589    #include &lt;ios&gt;
590    #include &lt;iosfwd&gt;
591    #include &lt;iostream&gt;
592    #include &lt;istream&gt;
593    #include &lt;iterator&gt;
594    #include &lt;limits&gt;
595    #include &lt;list&gt;
596    #include &lt;locale&gt;
597    #include &lt;map&gt;
598    #include &lt;memory&gt;
599    #include &lt;mutex&gt;
600    #include &lt;new&gt;
601    #include &lt;numeric&gt;
602    #include &lt;ostream&gt;
603    #include &lt;queue&gt;
604    #include &lt;random&gt;
605    #include &lt;ratio&gt;
606    #include &lt;regex&gt;
607    #include &lt;scoped_allocator&gt;
608    #include &lt;set&gt;
609    #include &lt;sstream&gt;
610    #include &lt;stack&gt;
611    #include &lt;stdexcept&gt;
612    #include &lt;streambuf&gt;
613    #include &lt;string&gt;
614    #include &lt;system_error&gt;
615    #include &lt;thread&gt;
616    #include &lt;tuple&gt;
617    #include &lt;typeindex&gt;
618    #include &lt;typeinfo&gt;
619    #include &lt;type_traits&gt;
620    #include &lt;unordered_map&gt;
621    #include &lt;unordered_set&gt;
622    #include &lt;utility&gt;
623    #include &lt;valarray&gt;
624    #include &lt;vector&gt;
625  ],,
626  ac_cv_cxx_stdcxx_11=yes, ac_cv_cxx_stdcxx_11=no)
627  AC_LANG_RESTORE
628  CXXFLAGS="$ac_save_CXXFLAGS"
629  ])
630  if test "$ac_cv_cxx_stdcxx_11" = yes; then
631    AC_DEFINE(STDCXX_11_HEADERS,,[Define if ISO C++11 header files are present. ])
632  fi
633])
634</programlisting>
635
636<para>As is the case for TR1 support, these autoconf macros can be made for a finer-grained, per-header-file check. For
637<filename class="headerfile">&lt;unordered_map&gt;</filename>
638</para>
639
640<programlisting>
641# AC_HEADER_UNORDERED_MAP
642AC_DEFUN([AC_HEADER_UNORDERED_MAP], [
643  AC_CACHE_CHECK(for unordered_map,
644  ac_cv_cxx_unordered_map,
645  [AC_REQUIRE([AC_COMPILE_STDCXX_11])
646  AC_LANG_SAVE
647  AC_LANG_CPLUSPLUS
648  ac_save_CXXFLAGS="$CXXFLAGS"
649  CXXFLAGS="$CXXFLAGS -std=gnu++11"
650  AC_TRY_COMPILE([#include &lt;unordered_map&gt;], [using std::unordered_map;],
651  ac_cv_cxx_unordered_map=yes, ac_cv_cxx_unordered_map=no)
652  CXXFLAGS="$ac_save_CXXFLAGS"
653  AC_LANG_RESTORE
654  ])
655  if test "$ac_cv_cxx_unordered_map" = yes; then
656    AC_DEFINE(HAVE_UNORDERED_MAP,,[Define if unordered_map is present. ])
657  fi
658])
659</programlisting>
660
661<programlisting>
662# AC_HEADER_UNORDERED_SET
663AC_DEFUN([AC_HEADER_UNORDERED_SET], [
664  AC_CACHE_CHECK(for unordered_set,
665  ac_cv_cxx_unordered_set,
666  [AC_REQUIRE([AC_COMPILE_STDCXX_11])
667  AC_LANG_SAVE
668  AC_LANG_CPLUSPLUS
669  ac_save_CXXFLAGS="$CXXFLAGS"
670  CXXFLAGS="$CXXFLAGS -std=gnu++11"
671  AC_TRY_COMPILE([#include &lt;unordered_set&gt;], [using std::unordered_set;],
672  ac_cv_cxx_unordered_set=yes, ac_cv_cxx_unordered_set=no)
673  CXXFLAGS="$ac_save_CXXFLAGS"
674  AC_LANG_RESTORE
675  ])
676  if test "$ac_cv_cxx_unordered_set" = yes; then
677    AC_DEFINE(HAVE_UNORDERED_SET,,[Define if unordered_set is present. ])
678  fi
679])
680</programlisting>
681
682<para>
683  Some C++11 features first appeared in GCC 4.3 and could be enabled by
684  <option>-std=c++0x</option> and <option>-std=gnu++0x</option> for GCC
685  releases which pre-date the 2011 standard. Those C++11 features and GCC's
686  support for them were still changing until the 2011 standard was finished,
687  but the autoconf checks above could be extended to test for incomplete
688  C++11 support with <option>-std=c++0x</option> and
689  <option>-std=gnu++0x</option>.
690</para>
691
692</section>
693
694<section xml:id="backwards.third.iterator_type"><info><title>
695  <code>Container::iterator_type</code> is not necessarily <code>Container::value_type*</code>
696</title></info>
697
698
699<para>
700  This is a change in behavior from older versions. Now, most
701  <type>iterator_type</type> typedefs in container classes are POD
702  objects, not <type>value_type</type> pointers.
703</para>
704</section>
705
706</section>
707
708</section>
709