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