xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/doc/xml/manual/using.xml (revision cb0339e943798efefc7358cd1ebad87bda2ecd6e)
1<chapter xmlns="http://docbook.org/ns/docbook" version="5.0"
2	 xml:id="manual.intro.using" xreflabel="Using">
3  <info><title>Using</title></info>
4  <?dbhtml filename="using.html"?>
5
6  <section xml:id="manual.intro.using.flags" xreflabel="Flags"><info><title>Command Options</title></info>
7
8    <para>
9      The set of features available in the GNU C++ library is shaped by
10      several <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Invoking-GCC.html">GCC
11      Command Options</link>. Options that impact libstdc++ are
12      enumerated and detailed in the table below.
13    </para>
14
15    <para>
16      The standard library conforms to the dialect of C++ specified by the
17      <option>-std</option> option passed to the compiler.
18      By default, <command>g++</command> is equivalent to
19      <command>g++ -std=gnu++14</command> since GCC 6, and
20      <command>g++ -std=gnu++98</command> for older releases.
21    </para>
22
23 <table frame="all" xml:id="table.cmd_options">
24<title>C++ Command Options</title>
25
26<tgroup cols="2" align="left" colsep="1" rowsep="1">
27<colspec colname="c1"/>
28<colspec colname="c2"/>
29
30  <thead>
31    <row>
32      <entry>Option Flags</entry>
33      <entry>Description</entry>
34    </row>
35  </thead>
36
37  <tbody>
38    <row>
39      <entry><literal>-std=c++98</literal> or <literal>-std=c++03</literal>
40      </entry>
41      <entry>Use the 1998 ISO C++ standard plus amendments.</entry>
42    </row>
43
44    <row>
45      <entry><literal>-std=gnu++98</literal> or <literal>-std=gnu++03</literal>
46      </entry>
47      <entry>As directly above, with GNU extensions.</entry>
48    </row>
49
50    <row>
51      <entry><literal>-std=c++11</literal></entry>
52      <entry>Use the 2011 ISO C++ standard.</entry>
53    </row>
54
55    <row>
56      <entry><literal>-std=gnu++11</literal></entry>
57      <entry>As directly above, with GNU extensions.</entry>
58    </row>
59
60    <row>
61      <entry><literal>-std=c++14</literal></entry>
62      <entry>Use the 2014 ISO C++ standard.</entry>
63    </row>
64
65    <row>
66      <entry><literal>-std=gnu++14</literal></entry>
67      <entry>As directly above, with GNU extensions.</entry>
68    </row>
69
70    <row>
71      <entry><literal>-fexceptions</literal></entry>
72      <entry>See <link linkend="intro.using.exception.no">exception-free dialect</link></entry>
73    </row>
74
75    <row>
76      <entry><literal>-frtti</literal></entry>
77      <entry>As above, but RTTI-free dialect.</entry>
78    </row>
79
80    <row>
81      <entry><literal>-pthread</literal> or <literal>-pthreads</literal></entry>
82      <entry>For ISO C++11
83        <filename class="headerfile">&lt;thread&gt;</filename>,
84        <filename class="headerfile">&lt;future&gt;</filename>,
85        <filename class="headerfile">&lt;mutex&gt;</filename>,
86        or <filename class="headerfile">&lt;condition_variable&gt;</filename>.
87      </entry>
88    </row>
89
90    <row>
91      <entry><literal>-latomic</literal></entry>
92      <entry>Linking to <filename class="libraryfile">libatomic</filename>
93        is required for some uses of ISO C++11
94        <filename class="headerfile">&lt;atomic&gt;</filename>.
95      </entry>
96    </row>
97
98    <row>
99      <entry><literal>-lstdc++fs</literal></entry>
100      <entry>Linking to <filename class="libraryfile">libstdc++fs</filename>
101        is required for use of the Filesystem library extensions in
102        <filename class="headerfile">&lt;experimental/filesystem&gt;</filename>.
103      </entry>
104    </row>
105
106    <row>
107      <entry><literal>-fopenmp</literal></entry>
108      <entry>For <link linkend="manual.ext.parallel_mode">parallel</link> mode.</entry>
109    </row>
110  </tbody>
111
112</tgroup>
113</table>
114
115  </section>
116
117  <section xml:id="manual.intro.using.headers" xreflabel="Headers"><info><title>Headers</title></info>
118    <?dbhtml filename="using_headers.html"?>
119
120
121    <section xml:id="manual.intro.using.headers.all" xreflabel="Header Files"><info><title>Header Files</title></info>
122
123
124   <para>
125     The C++ standard specifies the entire set of header files that
126     must be available to all hosted implementations.  Actually, the
127     word "files" is a misnomer, since the contents of the
128     headers don't necessarily have to be in any kind of external
129     file.  The only rule is that when one <code>#include</code>s a
130     header, the contents of that header become available, no matter
131     how.
132   </para>
133
134   <para>
135   That said, in practice files are used.
136   </para>
137
138   <para>
139     There are two main types of include files: header files related
140     to a specific version of the ISO C++ standard (called Standard
141     Headers), and all others (TS, TR1, C++ ABI, and Extensions).
142   </para>
143
144   <para>
145     Multiple dialects of standard headers are supported, corresponding to
146     the 1998 standard as updated for 2003, the 2011 standard, the 2014
147     standard, and so on.
148   </para>
149
150   <para>
151     <xref linkend="table.cxx98_headers"/> and
152     <xref linkend="table.cxx98_cheaders"/> and
153     <xref linkend="table.cxx98_deprheaders"/>
154     show the C++98/03 include files.
155     These are available in the C++98 compilation mode,
156     i.e. <code>-std=c++98</code> or <code>-std=gnu++98</code>.
157     Unless specified otherwise below, they are also available in later modes
158     (C++11, C++14 etc).
159   </para>
160
161<table frame="all" xml:id="table.cxx98_headers">
162<title>C++ 1998 Library Headers</title>
163
164<tgroup cols="5" align="left" colsep="1" rowsep="1">
165<colspec colname="c1"/>
166<colspec colname="c2"/>
167<colspec colname="c3"/>
168<colspec colname="c4"/>
169<colspec colname="c5"/>
170<tbody>
171<row>
172<entry><filename class="headerfile">algorithm</filename></entry>
173<entry><filename class="headerfile">bitset</filename></entry>
174<entry><filename class="headerfile">complex</filename></entry>
175<entry><filename class="headerfile">deque</filename></entry>
176<entry><filename class="headerfile">exception</filename></entry>
177</row>
178<row>
179<entry><filename class="headerfile">fstream</filename></entry>
180<entry><filename class="headerfile">functional</filename></entry>
181<entry><filename class="headerfile">iomanip</filename></entry>
182<entry><filename class="headerfile">ios</filename></entry>
183<entry><filename class="headerfile">iosfwd</filename></entry>
184</row>
185<row>
186<entry><filename class="headerfile">iostream</filename></entry>
187<entry><filename class="headerfile">istream</filename></entry>
188<entry><filename class="headerfile">iterator</filename></entry>
189<entry><filename class="headerfile">limits</filename></entry>
190<entry><filename class="headerfile">list</filename></entry>
191</row>
192<row>
193<entry><filename class="headerfile">locale</filename></entry>
194<entry><filename class="headerfile">map</filename></entry>
195<entry><filename class="headerfile">memory</filename></entry>
196<entry><filename class="headerfile">new</filename></entry>
197<entry><filename class="headerfile">numeric</filename></entry>
198</row>
199<row>
200<entry><filename class="headerfile">ostream</filename></entry>
201<entry><filename class="headerfile">queue</filename></entry>
202<entry><filename class="headerfile">set</filename></entry>
203<entry><filename class="headerfile">sstream</filename></entry>
204<entry><filename class="headerfile">stack</filename></entry>
205</row>
206<row>
207<entry><filename class="headerfile">stdexcept</filename></entry>
208<entry><filename class="headerfile">streambuf</filename></entry>
209<entry><filename class="headerfile">string</filename></entry>
210<entry><filename class="headerfile">utility</filename></entry>
211<entry><filename class="headerfile">typeinfo</filename></entry>
212</row>
213<row>
214<entry><filename class="headerfile">valarray</filename></entry>
215<entry><filename class="headerfile">vector</filename></entry>
216<entry namest="c3" nameend="c5"/>
217</row>
218</tbody>
219</tgroup>
220</table>
221
222<para/>
223<table frame="all" xml:id="table.cxx98_cheaders">
224<title>C++ 1998 Library Headers for C Library Facilities</title>
225
226<tgroup cols="5" align="left" colsep="1" rowsep="1">
227<colspec colname="c1"/>
228<colspec colname="c2"/>
229<colspec colname="c3"/>
230<colspec colname="c4"/>
231<colspec colname="c5"/>
232<tbody>
233<row>
234<entry><filename class="headerfile">cassert</filename></entry>
235<entry><filename class="headerfile">cerrno</filename></entry>
236<entry><filename class="headerfile">cctype</filename></entry>
237<entry><filename class="headerfile">cfloat</filename></entry>
238<entry><filename class="headerfile">ciso646</filename></entry>
239</row>
240<row>
241<entry><filename class="headerfile">climits</filename></entry>
242<entry><filename class="headerfile">clocale</filename></entry>
243<entry><filename class="headerfile">cmath</filename></entry>
244<entry><filename class="headerfile">csetjmp</filename></entry>
245<entry><filename class="headerfile">csignal</filename></entry>
246</row>
247<row>
248<entry><filename class="headerfile">cstdarg</filename></entry>
249<entry><filename class="headerfile">cstddef</filename></entry>
250<entry><filename class="headerfile">cstdio</filename></entry>
251<entry><filename class="headerfile">cstdlib</filename></entry>
252<entry><filename class="headerfile">cstring</filename></entry>
253</row>
254<row>
255<entry><filename class="headerfile">ctime</filename></entry>
256<entry><filename class="headerfile">cwchar</filename></entry>
257<entry><filename class="headerfile">cwctype</filename></entry>
258<entry namest="c4" nameend="c5"/>
259</row>
260</tbody>
261</tgroup>
262</table>
263
264<para>
265  The following header is deprecated
266  and might be removed from a future C++ standard.
267</para>
268
269<table frame="all" xml:id="table.cxx98_deprheaders">
270<title>C++ 1998 Deprecated Library Header</title>
271
272<tgroup cols="1" align="left" colsep="1" rowsep="1">
273<colspec colname="c1"/>
274<tbody>
275<row>
276<entry><filename class="headerfile">strstream</filename></entry>
277</row>
278</tbody>
279</tgroup>
280</table>
281
282<para>
283<xref linkend="table.cxx11_headers"/> and
284<xref linkend="table.cxx11_cheaders"/> show the C++11 include files.
285These are available in C++11 compilation
286mode, i.e. <literal>-std=c++11</literal> or <literal>-std=gnu++11</literal>.
287Including these headers in C++98/03 mode may result in compilation errors.
288Unless specified otherwise below, they are also available in later modes
289(C++14 etc).
290</para>
291
292<para/>
293<table frame="all" xml:id="table.cxx11_headers">
294<title>C++ 2011 Library Headers</title>
295
296<tgroup cols="5" align="left" colsep="1" rowsep="1">
297<colspec colname="c1"/>
298<colspec colname="c2"/>
299<colspec colname="c3"/>
300<colspec colname="c4"/>
301<colspec colname="c5"/>
302<tbody>
303
304<row>
305<entry><filename class="headerfile">array</filename></entry>
306<entry><filename class="headerfile">atomic</filename></entry>
307<entry><filename class="headerfile">chrono</filename></entry>
308<entry><filename class="headerfile">codecvt</filename></entry>
309<entry><filename class="headerfile">condition_variable</filename></entry>
310</row>
311<row>
312<entry><filename class="headerfile">forward_list</filename></entry>
313<entry><filename class="headerfile">future</filename></entry>
314<entry><filename class="headerfile">initalizer_list</filename></entry>
315<entry><filename class="headerfile">mutex</filename></entry>
316<entry><filename class="headerfile">random</filename></entry>
317</row>
318<row>
319<entry><filename class="headerfile">ratio</filename></entry>
320<entry><filename class="headerfile">regex</filename></entry>
321<entry><filename class="headerfile">scoped_allocator</filename></entry>
322<entry><filename class="headerfile">system_error</filename></entry>
323<entry><filename class="headerfile">thread</filename></entry>
324</row>
325<row>
326<entry><filename class="headerfile">tuple</filename></entry>
327<entry><filename class="headerfile">typeindex</filename></entry>
328<entry><filename class="headerfile">type_traits</filename></entry>
329<entry><filename class="headerfile">unordered_map</filename></entry>
330<entry><filename class="headerfile">unordered_set</filename></entry>
331</row>
332
333</tbody>
334</tgroup>
335</table>
336
337<para/>
338
339<table frame="all" xml:id="table.cxx11_cheaders">
340<title>C++ 2011 Library Headers for C Library Facilities</title>
341
342<tgroup cols="5" align="left" colsep="1" rowsep="1">
343<colspec colname="c1"/>
344<colspec colname="c2"/>
345<colspec colname="c3"/>
346<colspec colname="c4"/>
347<colspec colname="c5"/>
348<tbody>
349<row>
350<entry><filename class="headerfile">ccomplex</filename></entry>
351<entry><filename class="headerfile">cfenv</filename></entry>
352<entry><filename class="headerfile">cinttypes</filename></entry>
353<entry><filename class="headerfile">cstdalign</filename></entry>
354<entry><filename class="headerfile">cstdbool</filename></entry>
355</row>
356<row>
357<entry><filename class="headerfile">cstdint</filename></entry>
358<entry><filename class="headerfile">ctgmath</filename></entry>
359<entry><filename class="headerfile">cuchar</filename></entry>
360<entry namest="c4" nameend="c5"/>
361</row>
362</tbody>
363</tgroup>
364</table>
365
366<para>
367<xref linkend="table.cxx14_headers"/> shows the C++14 include file.
368This is available in C++14 compilation
369mode, i.e. <literal>-std=c++14</literal> or <literal>-std=gnu++14</literal>.
370Including this header in C++98/03 mode or C++11 will not result in
371compilation errors, but will not define anything.
372Unless specified otherwise below, it is also available in later modes
373(C++17 etc).
374</para>
375
376<para/>
377<table frame="all" xml:id="table.cxx14_headers">
378<title>C++ 2014 Library Header</title>
379
380<tgroup cols="1" align="left" colsep="1" rowsep="1">
381<colspec colname="c1"/>
382<tbody>
383<row>
384<entry><filename class="headerfile">shared_mutex</filename></entry>
385</row>
386</tbody>
387</tgroup>
388</table>
389
390<para>
391<xref linkend="table.filesystemts_headers"/>,
392shows the additional include file define by the
393File System Technical Specification, ISO/IEC TS 18822.
394This is available in C++11 and later compilation modes.
395Including this header in earlier modes will not result in
396compilation errors, but will not define anything.
397</para>
398
399<para/>
400<table frame="all" xml:id="table.filesystemts_headers">
401<title>File System TS Header</title>
402
403<tgroup cols="1" align="left" colsep="1" rowsep="1">
404<colspec colname="c1"/>
405<tbody>
406<row>
407<entry><filename class="headerfile">experimental/filesystem</filename></entry>
408</row>
409</tbody>
410</tgroup>
411</table>
412
413
414<para>
415<xref linkend="table.libfundts_headers"/>,
416shows the additional include files define by the C++ Extensions for
417Library Fundamentals Technical Specification, ISO/IEC TS 19568.
418These are available in C++14 and later compilation modes.
419Including these headers in earlier modes will not result in
420compilation errors, but will not define anything.
421</para>
422
423<para/>
424<table frame="all" xml:id="table.libfundts_headers">
425<title>Library Fundamentals TS Headers</title>
426
427<tgroup cols="5" align="left" colsep="1" rowsep="1">
428<colspec colname="c1"/>
429<colspec colname="c2"/>
430<colspec colname="c3"/>
431<colspec colname="c4"/>
432<colspec colname="c5"/>
433<tbody>
434<row>
435<entry><filename class="headerfile">experimental/algorithm</filename></entry>
436<entry><filename class="headerfile">experimental/any</filename></entry>
437<entry><filename class="headerfile">experimental/array</filename></entry>
438<entry><filename class="headerfile">experimental/chrono</filename></entry>
439<entry><filename class="headerfile">experimental/deque</filename></entry>
440</row>
441<row>
442<entry><filename class="headerfile">experimental/forward_list</filename></entry>
443<entry><filename class="headerfile">experimental/functional</filename></entry>
444<entry><filename class="headerfile">experimental/iterator</filename></entry>
445<entry><filename class="headerfile">experimental/list</filename></entry>
446<entry><filename class="headerfile">experimental/map</filename></entry>
447</row>
448<row>
449<entry><filename class="headerfile">experimental/memory</filename></entry>
450<entry><filename class="headerfile">experimental/memory_resource</filename></entry>
451<entry><filename class="headerfile">experimental/numeric</filename></entry>
452<entry><filename class="headerfile">experimental/optional</filename></entry>
453<entry><filename class="headerfile">experimental/propagate_const</filename></entry>
454</row>
455<row>
456<entry><filename class="headerfile">experimental/random</filename></entry>
457<entry><filename class="headerfile">experimental/ratio</filename></entry>
458<entry><filename class="headerfile">experimental/regex</filename></entry>
459<entry><filename class="headerfile">experimental/set</filename></entry>
460<entry><filename class="headerfile">experimental/string</filename></entry>
461</row>
462<row>
463<entry><filename class="headerfile">experimental/string_view</filename></entry>
464<entry><filename class="headerfile">experimental/system_error</filename></entry>
465<entry><filename class="headerfile">experimental/tuple</filename></entry>
466<entry><filename class="headerfile">experimental/type_traits</filename></entry>
467<entry><filename class="headerfile">experimental/unordered_map</filename></entry>
468</row>
469<row>
470<entry><filename class="headerfile">experimental/unordered_set</filename></entry>
471<entry><filename class="headerfile">experimental/utility</filename></entry>
472<entry><filename class="headerfile">experimental/vector</filename></entry>
473<entry namest="c4" nameend="c5"/>
474</row>
475</tbody>
476</tgroup>
477</table>
478
479
480<para>
481  In addition, TR1 includes as:
482</para>
483
484<table frame="all" xml:id="table.tr1_headers">
485<title>C++ TR 1 Library Headers</title>
486
487<tgroup cols="5" align="left" colsep="1" rowsep="1">
488<colspec colname="c1"/>
489<colspec colname="c2"/>
490<colspec colname="c3"/>
491<colspec colname="c4"/>
492<colspec colname="c5"/>
493<tbody>
494
495<row>
496<entry><filename class="headerfile">tr1/array</filename></entry>
497<entry><filename class="headerfile">tr1/complex</filename></entry>
498<entry><filename class="headerfile">tr1/memory</filename></entry>
499<entry><filename class="headerfile">tr1/functional</filename></entry>
500<entry><filename class="headerfile">tr1/random</filename></entry>
501</row>
502<row>
503<entry><filename class="headerfile">tr1/regex</filename></entry>
504<entry><filename class="headerfile">tr1/tuple</filename></entry>
505<entry><filename class="headerfile">tr1/type_traits</filename></entry>
506<entry><filename class="headerfile">tr1/unordered_map</filename></entry>
507<entry><filename class="headerfile">tr1/unordered_set</filename></entry>
508</row>
509<row>
510<entry><filename class="headerfile">tr1/utility</filename></entry>
511<entry namest="c2" nameend="c5"/>
512</row>
513
514</tbody>
515</tgroup>
516</table>
517
518<para/>
519
520
521<table frame="all" xml:id="table.tr1_cheaders">
522<title>C++ TR 1 Library Headers for C Library Facilities</title>
523
524<tgroup cols="5" align="left" colsep="1" rowsep="1">
525<colspec colname="c1"/>
526<colspec colname="c2"/>
527<colspec colname="c3"/>
528<colspec colname="c4"/>
529<colspec colname="c5"/>
530<tbody>
531
532<row>
533<entry><filename class="headerfile">tr1/ccomplex</filename></entry>
534<entry><filename class="headerfile">tr1/cfenv</filename></entry>
535<entry><filename class="headerfile">tr1/cfloat</filename></entry>
536<entry><filename class="headerfile">tr1/cmath</filename></entry>
537<entry><filename class="headerfile">tr1/cinttypes</filename></entry>
538</row>
539<row>
540<entry><filename class="headerfile">tr1/climits</filename></entry>
541<entry><filename class="headerfile">tr1/cstdarg</filename></entry>
542<entry><filename class="headerfile">tr1/cstdbool</filename></entry>
543<entry><filename class="headerfile">tr1/cstdint</filename></entry>
544<entry><filename class="headerfile">tr1/cstdio</filename></entry>
545</row>
546<row>
547<entry><filename class="headerfile">tr1/cstdlib</filename></entry>
548<entry><filename class="headerfile">tr1/ctgmath</filename></entry>
549<entry><filename class="headerfile">tr1/ctime</filename></entry>
550<entry><filename class="headerfile">tr1/cwchar</filename></entry>
551<entry><filename class="headerfile">tr1/cwctype</filename></entry>
552</row>
553
554</tbody>
555</tgroup>
556</table>
557
558
559<para>Decimal floating-point arithmetic is available if the C++
560compiler supports scalar decimal floating-point types defined via
561<code>__attribute__((mode(SD|DD|LD)))</code>.
562</para>
563
564<table frame="all" xml:id="table.decfp_headers">
565<title>C++ TR 24733 Decimal Floating-Point Header</title>
566
567<tgroup cols="1" align="left" colsep="1" rowsep="1">
568<colspec colname="c1"/>
569<tbody>
570<row>
571<entry><filename class="headerfile">decimal/decimal</filename></entry>
572</row>
573</tbody>
574</tgroup>
575</table>
576
577<para>
578  Also included are files for the C++ ABI interface:
579</para>
580
581<table frame="all" xml:id="table.abi_headers">
582<title>C++ ABI Headers</title>
583
584<tgroup cols="2" align="left" colsep="1" rowsep="1">
585<colspec colname="c1"/>
586<colspec colname="c2"/>
587<tbody>
588<row><entry><filename class="headerfile">cxxabi.h</filename></entry><entry><filename class="headerfile">cxxabi_forced.h</filename></entry></row>
589</tbody>
590</tgroup>
591</table>
592
593<para>
594  And a large variety of extensions.
595</para>
596
597<table frame="all" xml:id="table.ext_headers">
598<title>Extension Headers</title>
599
600<tgroup cols="5" align="left" colsep="1" rowsep="1">
601<colspec colname="c1"/>
602<colspec colname="c2"/>
603<colspec colname="c3"/>
604<colspec colname="c4"/>
605<colspec colname="c5"/>
606<tbody>
607
608<row>
609<entry><filename class="headerfile">ext/algorithm</filename></entry>
610<entry><filename class="headerfile">ext/atomicity.h</filename></entry>
611<entry><filename class="headerfile">ext/array_allocator.h</filename></entry>
612<entry><filename class="headerfile">ext/bitmap_allocator.h</filename></entry>
613<entry><filename class="headerfile">ext/cast.h</filename></entry>
614</row>
615<row>
616<entry><filename class="headerfile">ext/codecvt_specializations.h</filename></entry>
617<entry><filename class="headerfile">ext/concurrence.h</filename></entry>
618<entry><filename class="headerfile">ext/debug_allocator.h</filename></entry>
619<entry><filename class="headerfile">ext/enc_filebuf.h</filename></entry>
620<entry><filename class="headerfile">ext/extptr_allocator.h</filename></entry>
621</row>
622<row>
623<entry><filename class="headerfile">ext/functional</filename></entry>
624<entry><filename class="headerfile">ext/iterator</filename></entry>
625<entry><filename class="headerfile">ext/malloc_allocator.h</filename></entry>
626<entry><filename class="headerfile">ext/memory</filename></entry>
627<entry><filename class="headerfile">ext/mt_allocator.h</filename></entry>
628</row>
629<row>
630<entry><filename class="headerfile">ext/new_allocator.h</filename></entry>
631<entry><filename class="headerfile">ext/numeric</filename></entry>
632<entry><filename class="headerfile">ext/numeric_traits.h</filename></entry>
633<entry><filename class="headerfile">ext/pb_ds/assoc_container.h</filename></entry>
634<entry><filename class="headerfile">ext/pb_ds/priority_queue.h</filename></entry>
635</row>
636<row>
637<entry><filename class="headerfile">ext/pod_char_traits.h</filename></entry>
638<entry><filename class="headerfile">ext/pool_allocator.h</filename></entry>
639<entry><filename class="headerfile">ext/rb_tree</filename></entry>
640<entry><filename class="headerfile">ext/rope</filename></entry>
641<entry><filename class="headerfile">ext/slist</filename></entry>
642</row>
643<row>
644<entry><filename class="headerfile">ext/stdio_filebuf.h</filename></entry>
645<entry><filename class="headerfile">ext/stdio_sync_filebuf.h</filename></entry>
646<entry><filename class="headerfile">ext/throw_allocator.h</filename></entry>
647<entry><filename class="headerfile">ext/typelist.h</filename></entry>
648<entry><filename class="headerfile">ext/type_traits.h</filename></entry>
649</row>
650<row>
651<entry><filename class="headerfile">ext/vstring.h</filename></entry>
652<entry namest="c2" nameend="c5"/>
653</row>
654
655</tbody>
656</tgroup>
657</table>
658
659<para/>
660
661<table frame="all" xml:id="table.debug_headers">
662<title>Extension Debug Headers</title>
663
664<tgroup cols="5" align="left" colsep="1" rowsep="1">
665<colspec colname="c1"/>
666<colspec colname="c2"/>
667<colspec colname="c3"/>
668<colspec colname="c4"/>
669<colspec colname="c5"/>
670<tbody>
671
672<row>
673<entry><filename class="headerfile">debug/array</filename></entry>
674<entry><filename class="headerfile">debug/bitset</filename></entry>
675<entry><filename class="headerfile">debug/deque</filename></entry>
676<entry><filename class="headerfile">debug/forward_list</filename></entry>
677<entry><filename class="headerfile">debug/list</filename></entry>
678</row>
679<row>
680<entry><filename class="headerfile">debug/map</filename></entry>
681<entry><filename class="headerfile">debug/set</filename></entry>
682<entry><filename class="headerfile">debug/string</filename></entry>
683<entry><filename class="headerfile">debug/unordered_map</filename></entry>
684<entry><filename class="headerfile">debug/unordered_set</filename></entry>
685</row>
686<row>
687<entry><filename class="headerfile">debug/vector</filename></entry>
688<entry namest="c2" nameend="c5"/>
689</row>
690
691</tbody>
692</tgroup>
693</table>
694
695<para/>
696
697<table frame="all" xml:id="table.profile_headers">
698<title>Extension Profile Headers</title>
699
700<tgroup cols="4" align="left" colsep="1" rowsep="1">
701<colspec colname="c1"/>
702<colspec colname="c2"/>
703<colspec colname="c3"/>
704<colspec colname="c4"/>
705<tbody>
706
707<row>
708<entry><filename class="headerfile">profile/bitset</filename></entry>
709<entry><filename class="headerfile">profile/deque</filename></entry>
710<entry><filename class="headerfile">profile/list</filename></entry>
711<entry><filename class="headerfile">profile/map</filename></entry>
712</row>
713
714<row>
715<entry><filename class="headerfile">profile/set</filename></entry>
716<entry><filename class="headerfile">profile/unordered_map</filename></entry>
717<entry><filename class="headerfile">profile/unordered_set</filename></entry>
718<entry><filename class="headerfile">profile/vector</filename></entry>
719</row>
720
721</tbody>
722</tgroup>
723</table>
724
725<para/>
726
727<table frame="all" xml:id="table.parallel_headers">
728<title>Extension Parallel Headers</title>
729
730<tgroup cols="2" align="left" colsep="1" rowsep="1">
731<colspec colname="c1"/>
732<colspec colname="c2"/>
733<tbody>
734<row>
735<entry><filename class="headerfile">parallel/algorithm</filename></entry>
736<entry><filename class="headerfile">parallel/numeric</filename></entry>
737</row>
738</tbody>
739</tgroup>
740</table>
741
742    </section>
743
744    <section xml:id="manual.intro.using.headers.mixing" xreflabel="Mixing Headers"><info><title>Mixing Headers</title></info>
745
746
747<para> A few simple rules.
748</para>
749
750<para>First, mixing different dialects of the standard headers is not
751possible. It's an all-or-nothing affair. Thus, code like
752</para>
753
754<programlisting>
755#include &lt;array&gt;
756#include &lt;functional&gt;
757</programlisting>
758
759<para>Implies C++11 mode. To use the entities in &lt;array&gt;, the C++11
760compilation mode must be used, which implies the C++11 functionality
761(and deprecations) in &lt;functional&gt; will be present.
762</para>
763
764<para>Second, the other headers can be included with either dialect of
765the standard headers, although features and types specific to C++11
766are still only enabled when in C++11 compilation mode. So, to use
767rvalue references with <code>__gnu_cxx::vstring</code>, or to use the
768debug-mode versions of <code>std::unordered_map</code>, one must use
769the <code>std=gnu++11</code> compiler flag. (Or <code>std=c++11</code>, of course.)
770</para>
771
772<para>A special case of the second rule is the mixing of TR1 and C++11
773facilities. It is possible (although not especially prudent) to
774include both the TR1 version and the C++11 version of header in the
775same translation unit:
776</para>
777
778<programlisting>
779#include &lt;tr1/type_traits&gt;
780#include &lt;type_traits&gt;
781</programlisting>
782
783<para> Several parts of C++11 diverge quite substantially from TR1 predecessors.
784</para>
785    </section>
786
787    <section xml:id="manual.intro.using.headers.cheaders" xreflabel="C Headers and"><info><title>The C Headers and <code>namespace std</code></title></info>
788
789
790<para>
791	The standard specifies that if one includes the C-style header
792	(&lt;math.h&gt; in this case), the symbols will be available
793	in the global namespace and perhaps in
794	namespace <code>std::</code> (but this is no longer a firm
795	requirement.) On the other hand, including the C++-style
796	header (&lt;cmath&gt;) guarantees that the entities will be
797	found in namespace std and perhaps in the global namespace.
798      </para>
799
800<para>
801Usage of C++-style headers is recommended, as then
802C-linkage names can be disambiguated by explicit qualification, such
803as by <code>std::abort</code>. In addition, the C++-style headers can
804use function overloading to provide a simpler interface to certain
805families of C-functions. For instance in &lt;cmath&gt;, the
806function <code>std::sin</code> has overloads for all the builtin
807floating-point types. This means that <code>std::sin</code> can be
808used uniformly, instead of a combination
809of <code>std::sinf</code>, <code>std::sin</code>,
810and <code>std::sinl</code>.
811</para>
812    </section>
813
814    <section xml:id="manual.intro.using.headers.pre" xreflabel="Precompiled Headers"><info><title>Precompiled Headers</title></info>
815
816
817
818<para>There are three base header files that are provided. They can be
819used to precompile the standard headers and extensions into binary
820files that may then be used to speed up compilations that use these headers.
821</para>
822
823
824<itemizedlist>
825<listitem>
826  <para>stdc++.h</para>
827<para>Includes all standard headers. Actual content varies depending on
828<link linkend="manual.intro.using.flags">language dialect</link>.
829</para>
830</listitem>
831
832<listitem>
833  <para>stdtr1c++.h</para>
834<para>Includes all of &lt;stdc++.h&gt;, and adds all the TR1 headers.
835</para>
836</listitem>
837
838<listitem><para>extc++.h</para>
839<para>Includes all of &lt;stdc++.h&gt;, and adds all the Extension headers
840(and in C++98 mode also adds all the TR1 headers by including all of
841&lt;stdtr1c++.h&gt;).
842</para></listitem>
843</itemizedlist>
844
845<para>To construct a .gch file from one of these base header files,
846first find the include directory for the compiler. One way to do
847this is:</para>
848
849<programlisting>
850g++ -v hello.cc
851
852#include &lt;...&gt; search starts here:
853 /mnt/share/bld/H-x86-gcc.20071201/include/c++/4.3.0
854...
855End of search list.
856</programlisting>
857
858
859<para>Then, create a precompiled header file with the same flags that
860will be used to compile other projects.</para>
861
862<programlisting>
863g++ -Winvalid-pch -x c++-header -g -O2 -o ./stdc++.h.gch /mnt/share/bld/H-x86-gcc.20071201/include/c++/4.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h
864</programlisting>
865
866<para>The resulting file will be quite large: the current size is around
867thirty megabytes. </para>
868
869<para>How to use the resulting file.</para>
870
871<programlisting>
872g++ -I. -include stdc++.h  -H -g -O2 hello.cc
873</programlisting>
874
875<para>Verification that the PCH file is being used is easy:</para>
876
877<programlisting>
878g++ -Winvalid-pch -I. -include stdc++.h -H -g -O2 hello.cc -o test.exe
879! ./stdc++.h.gch
880. /mnt/share/bld/H-x86-gcc.20071201/include/c++/4.3.0/iostream
881. /mnt/share/bld/H-x86-gcc.20071201include/c++/4.3.0/string
882</programlisting>
883
884<para>The exclamation point to the left of the <code>stdc++.h.gch</code> listing means that the generated PCH file was used.</para>
885<para/>
886
887<para> Detailed information about creating precompiled header files can be found in the GCC <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html">documentation</link>.
888</para>
889
890    </section>
891  </section>
892
893
894  <section xml:id="manual.intro.using.macros" xreflabel="Macros"><info><title>Macros</title></info>
895    <?dbhtml filename="using_macros.html"?>
896
897
898   <para>
899     All library macros begin with <code>_GLIBCXX_</code>.
900   </para>
901
902   <para>
903     Furthermore, all pre-processor macros, switches, and
904      configuration options are gathered in the
905      file <filename class="headerfile">c++config.h</filename>, which
906      is generated during the libstdc++ configuration and build
907      process. This file is then included when needed by files part of
908      the public libstdc++ API, like
909      <filename class="headerfile">&lt;ios&gt;</filename>. Most of these
910      macros should not be used by consumers of libstdc++, and are reserved
911      for internal implementation use. <emphasis>These macros cannot
912      be redefined</emphasis>.
913   </para>
914
915   <para>
916     A select handful of macros control libstdc++ extensions and extra
917      features, or provide versioning information for the API.  Only
918      those macros listed below are offered for consideration by the
919      general public.
920   </para>
921
922   <para>Below is the macro which users may check for library version
923      information. </para>
924
925    <variablelist>
926    <varlistentry>
927      <term><code>__GLIBCXX__</code></term>
928      <listitem>
929	<para>The current version of
930    libstdc++ in compressed ISO date format, as an unsigned
931    long. For details on the value of this particular macro for a
932    particular release, please consult the <link linkend="appendix.porting.abi">
933    ABI Policy and Guidelines</link> appendix.
934    </para>
935    </listitem>
936    </varlistentry>
937    </variablelist>
938
939   <para>Below are the macros which users may change with #define/#undef or
940      with -D/-U compiler flags.  The default state of the symbol is
941      listed.</para>
942
943   <para><quote>Configurable</quote> (or <quote>Not configurable</quote>) means
944      that the symbol is initially chosen (or not) based on
945      --enable/--disable options at library build and configure time
946      (documented in
947      <link linkend="manual.intro.setup.configure">Configure</link>),
948      with the various --enable/--disable choices being translated to
949      #define/#undef).
950   </para>
951
952   <para> <acronym>ABI</acronym> means that changing from the default value may
953  mean changing the <acronym>ABI</acronym> of compiled code. In other words,
954  these choices control code which has already been compiled (i.e., in a
955  binary such as libstdc++.a/.so).  If you explicitly #define or
956  #undef these macros, the <emphasis>headers</emphasis> may see different code
957  paths, but the <emphasis>libraries</emphasis> which you link against will not.
958  Experimenting with different values with the expectation of
959  consistent linkage requires changing the config headers before
960  building/installing the library.
961   </para>
962
963    <variablelist>
964    <varlistentry><term><code>_GLIBCXX_USE_DEPRECATED</code></term>
965    <listitem>
966      <para>
967	Defined by default. Not configurable. ABI-changing. Turning this off
968	removes older ARM-style iostreams code, and other anachronisms
969	from the API.  This macro is dependent on the version of the
970	standard being tracked, and as a result may give different results for
971	<code>-std=c++98</code> and <code>-std=c++11</code>. This may
972	be useful in updating old C++ code which no longer meet the
973	requirements of the language, or for checking current code
974	against new language standards.
975    </para>
976    </listitem></varlistentry>
977
978    <varlistentry><term><code>_GLIBCXX_USE_CXX11_ABI</code></term>
979    <listitem>
980      <para>
981        Defined to the value <literal>1</literal> by default.
982        Configurable via  <code>--disable-libstdcxx-dual-abi</code>
983        and/or <code>--with-default-libstdcxx-abi</code>.
984        ABI-changing.
985        When defined to a non-zero value the library headers will use the
986        new C++11-conforming ABI introduced in GCC 5, rather than the older
987        ABI introduced in GCC 3.4. This changes the definition of several
988        class templates, including <classname>std:string</classname>,
989        <classname>std::list</classname> and some locale facets.
990        For more details see <xref linkend="manual.intro.using.abi"/>.
991    </para>
992    </listitem></varlistentry>
993
994    <varlistentry><term><code>_GLIBCXX_CONCEPT_CHECKS</code></term>
995    <listitem>
996      <para>
997	Undefined by default.  Configurable via
998	<code>--enable-concept-checks</code>.  When defined, performs
999	compile-time checking on certain template instantiations to
1000	detect violations of the requirements of the standard.  This
1001	macro has no effect for freestanding implementations.
1002	This is described in more detail in
1003	<link linkend="manual.ext.compile_checks">Compile Time Checks</link>.
1004      </para>
1005    </listitem></varlistentry>
1006
1007    <varlistentry><term><code>_GLIBCXX_ASSERTIONS</code></term>
1008    <listitem>
1009      <para>
1010	Undefined by default. When defined, enables extra error checking in
1011        the form of precondition assertions, such as bounds checking in
1012        strings and null pointer checks when dereferencing smart pointers.
1013      </para>
1014    </listitem></varlistentry>
1015    <varlistentry><term><code>_GLIBCXX_DEBUG</code></term>
1016    <listitem>
1017      <para>
1018	Undefined by default. When defined, compiles user code using
1019	the <link linkend="manual.ext.debug_mode">debug mode</link>.
1020        When defined, <code>_GLIBCXX_ASSERTIONS</code> is defined
1021        automatically, so all the assertions enabled by that macro are also
1022        enabled in debug mode.
1023      </para>
1024    </listitem></varlistentry>
1025    <varlistentry><term><code>_GLIBCXX_DEBUG_PEDANTIC</code></term>
1026    <listitem>
1027      <para>
1028	Undefined by default. When defined while compiling with
1029	the <link linkend="manual.ext.debug_mode">debug mode</link>, makes
1030	the debug mode extremely picky by making the use of libstdc++
1031	extensions and libstdc++-specific behavior into errors.
1032      </para>
1033    </listitem></varlistentry>
1034    <varlistentry><term><code>_GLIBCXX_PARALLEL</code></term>
1035    <listitem>
1036      <para>Undefined by default. When defined, compiles user code
1037	using the <link linkend="manual.ext.parallel_mode">parallel
1038	mode</link>.
1039      </para>
1040    </listitem></varlistentry>
1041    <varlistentry><term><code>_GLIBCXX_PARALLEL_ASSERTIONS</code></term>
1042    <listitem>
1043      <para>Undefined by default, but when any parallel mode header is included
1044      this macro will be defined to a non-zero value if
1045      <code>_GLIBCXX_ASSERTIONS</code> has a non-zero value, otherwise to zero.
1046      When defined to a non-zero value, it enables extra error checking and
1047      assertions in the parallel mode.
1048      </para>
1049    </listitem></varlistentry>
1050
1051    <varlistentry><term><code>_GLIBCXX_PROFILE</code></term>
1052    <listitem>
1053      <para>Undefined by default. When defined, compiles user code
1054	using the <link linkend="manual.ext.profile_mode">profile
1055	mode</link>.
1056      </para>
1057    </listitem></varlistentry>
1058
1059    <varlistentry><term><code>__STDCPP_WANT_MATH_SPEC_FUNCS__</code></term>
1060    <listitem>
1061      <para>Undefined by default. When defined to a non-zero integer constant,
1062	enables support for ISO/IEC 29124 Special Math Functions.
1063      </para>
1064    </listitem></varlistentry>
1065    </variablelist>
1066
1067  </section>
1068
1069<section xml:id="manual.intro.using.abi" xreflabel="Dual ABI">
1070  <info><title>Dual ABI</title></info>
1071  <?dbhtml filename="using_dual_abi.html"?>
1072
1073<para> In the GCC 5.1 release libstdc++ introduced a new library ABI that
1074  includes new implementations of <classname>std::string</classname> and
1075  <classname>std::list</classname>. These changes were necessary to conform
1076  to the 2011 C++ standard which forbids Copy-On-Write strings and requires
1077  lists to keep track of their size.
1078</para>
1079
1080<para> In order to maintain backwards compatibility for existing code linked
1081  to libstdc++ the library's soname has not changed and the old
1082  implementations are still supported in parallel with the new ones.
1083  This is achieved by defining the new implementations in an inline namespace
1084  so they have different names for linkage purposes, e.g. the new version of
1085  <classname>std::list&lt;int&gt;</classname> is actually defined as
1086  <classname>std::__cxx11::list&lt;int&gt;</classname>. Because the symbols
1087  for the new implementations have different names the definitions for both
1088  versions can be present in the same library.
1089</para>
1090
1091<para> The <symbol>_GLIBCXX_USE_CXX11_ABI</symbol> macro (see
1092  <xref linkend="manual.intro.using.macros"/>) controls whether
1093  the declarations in the library headers use the old or new ABI.
1094  So the decision of which ABI to use can be made separately for each
1095  source file being compiled.
1096  Using the default configuration options for GCC the default value
1097  of the macro is <literal>1</literal> which causes the new ABI to be active,
1098  so to use the old ABI you must explicitly define the macro to
1099  <literal>0</literal> before including any library headers.
1100  (Be aware that some GNU/Linux distributions configure GCC 5 differently so
1101  that the default value of the macro is <literal>0</literal> and users must
1102  define it to <literal>1</literal> to enable the new ABI.)
1103</para>
1104
1105<para> Although the changes were made for C++11 conformance, the choice of ABI
1106  to use is independent of the <option>-std</option> option used to compile
1107  your code, i.e. for a given GCC build the default value of the
1108  <symbol>_GLIBCXX_USE_CXX11_ABI</symbol> macro is the same for all dialects.
1109  This ensures that the <option>-std</option> does not change the ABI, so
1110  that it is straightforward to link C++03 and C++11 code together.
1111</para>
1112
1113<para> Because <classname>std::string</classname> is used extensively
1114  throughout the library a number of other types are also defined twice,
1115  including the stringstream classes and several facets used by
1116  <classname>std::locale</classname>. The standard facets which are always
1117  installed in a locale may be present twice, with both ABIs, to ensure that
1118  code like
1119  <code>std::use_facet&lt;std::time_get&lt;char&gt;&gt;(locale);</code>
1120  will work correctly for both <classname>std::time_get</classname> and
1121  <classname>std::__cxx11::time_get</classname> (even if a user-defined
1122  facet that derives from one or other version of
1123  <classname>time_get</classname> is installed in the locale).
1124</para>
1125
1126<para> Although the standard exception types defined in
1127  <filename class="headerfile">&lt;stdexcept&gt;</filename> use strings, most
1128  are not defined twice, so that a <classname>std::out_of_range</classname>
1129  exception thrown in one file can always be caught by a suitable handler in
1130  another file, even if the two files are compiled with different ABIs.
1131</para>
1132
1133<para> One exception type does change when using the new ABI, namely
1134  <classname>std::ios_base::failure</classname>.
1135  This is necessary because the 2011 standard changed its base class from
1136  <classname>std::exception</classname> to
1137  <classname>std::system_error</classname>, which causes its layout to change.
1138  Exceptions due to iostream errors are thrown by a function inside
1139  <filename class="libraryfile">libstdc++.so</filename>, so whether the thrown
1140  exception uses the old <classname>std::ios_base::failure</classname> type
1141  or the new one depends on the ABI that was active when
1142  <filename class="libraryfile">libstdc++.so</filename> was built,
1143  <emphasis>not</emphasis> the ABI active in the user code that is using
1144  iostreams.
1145  This means that for a given build of GCC the type thrown is fixed.
1146  In current releases the library throws a special type that can be caught
1147  by handlers for either the old or new type,
1148  but for GCC 7.1, 7.2 and 7.3 the library throws the new
1149  <classname>std::ios_base::failure</classname> type,
1150  and for GCC 5.x and 6.x the library throws the old type.
1151  Catch handlers of type <classname>std::ios_base::failure</classname>
1152  will only catch the exceptions if using a newer release,
1153  or if the handler is compiled with the same ABI as the type thrown by
1154  the library.
1155  Handlers for <classname>std::exception</classname> will always catch
1156  iostreams exceptions, because the old and new type both inherit from
1157  <classname>std::exception</classname>.
1158</para>
1159
1160<section xml:id="manual.intro.using.abi.trouble" xreflabel="Dual ABI Troubleshooting"><info><title>Troubleshooting</title></info>
1161
1162<para> If you get linker errors about undefined references to symbols
1163  that involve types in the <code>std::__cxx11</code> namespace or the tag
1164  <code>[abi:cxx11]</code> then it probably indicates that you are trying to
1165  link together object files that were compiled with different values for the
1166  <symbol>_GLIBCXX_USE_CXX11_ABI</symbol> macro. This commonly happens when
1167  linking to a third-party library that was compiled with an older version
1168  of GCC. If the third-party library cannot be rebuilt with the new ABI then
1169  you will need to recompile your code with the old ABI.
1170</para>
1171
1172<para> Not all uses of the new ABI will cause changes in symbol names, for
1173  example a class with a <classname>std::string</classname> member variable
1174  will have the same mangled name whether compiled with the old or new ABI.
1175  In order to detect such problems the new types and functions are
1176  annotated with the <property>abi_tag</property> attribute, allowing the
1177  compiler to warn about potential ABI incompatibilities in code using them.
1178  Those warnings can be enabled with the <option>-Wabi-tag</option> option.
1179</para>
1180
1181</section>
1182</section>
1183
1184  <section xml:id="manual.intro.using.namespaces" xreflabel="Namespaces"><info><title>Namespaces</title></info>
1185    <?dbhtml filename="using_namespaces.html"?>
1186
1187
1188    <section xml:id="manual.intro.using.namespaces.all" xreflabel="Available Namespaces"><info><title>Available Namespaces</title></info>
1189
1190
1191
1192
1193<para> There are three main namespaces.
1194</para>
1195
1196<itemizedlist>
1197  <listitem><para>std</para>
1198<para>The ISO C++ standards specify that "all library entities are defined
1199within namespace std." This includes namespaces nested
1200within namespace <code>std</code>, such as namespace
1201<code>std::chrono</code>.
1202</para>
1203</listitem>
1204<listitem><para>abi</para>
1205<para>Specified by the C++ ABI. This ABI specifies a number of type and
1206function APIs supplemental to those required by the ISO C++ Standard,
1207but necessary for interoperability.
1208</para>
1209</listitem>
1210
1211<listitem><para>__gnu_</para>
1212<para>Indicating one of several GNU extensions. Choices
1213include <code>__gnu_cxx</code>, <code>__gnu_debug</code>, <code>__gnu_parallel</code>,
1214and <code>__gnu_pbds</code>.
1215</para></listitem>
1216</itemizedlist>
1217
1218<para> The library uses a number of inline namespaces as implementation
1219details that are not intended for users to refer to directly, these include
1220<code>std::__detail</code>, <code>std::__cxx11</code> and <code>std::_V2</code>.
1221</para>
1222
1223<para> A complete list of implementation namespaces (including namespace contents) is available in the generated source <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/namespaces.html">documentation</link>.
1224</para>
1225
1226
1227    </section>
1228
1229    <section xml:id="manual.intro.using.namespaces.std" xreflabel="namespace std"><info><title>namespace std</title></info>
1230
1231
1232
1233<para>
1234      One standard requirement is that the library components are defined
1235      in <code>namespace std::</code>. Thus, in order to use these types or
1236      functions, one must do one of two things:
1237</para>
1238
1239<itemizedlist>
1240  <listitem><para>put a kind of <emphasis>using-declaration</emphasis> in your source
1241(either <code>using namespace std;</code> or i.e. <code>using
1242std::string;</code>) This approach works well for individual source files, but
1243should not be used in a global context, like header files.
1244	  </para></listitem> <listitem><para>use a <emphasis>fully
1245qualified name</emphasis> for each library symbol
1246(i.e. <code>std::string</code>, <code>std::cout</code>) Always can be
1247used, and usually enhanced, by strategic use of typedefs. (In the
1248cases where the qualified verbiage becomes unwieldy.)
1249	  </para>
1250	</listitem>
1251</itemizedlist>
1252
1253    </section>
1254
1255    <section xml:id="manual.intro.using.namespaces.comp" xreflabel="Using Namespace Composition"><info><title>Using Namespace Composition</title></info>
1256
1257
1258<para>
1259Best practice in programming suggests sequestering new data or
1260functionality in a sanely-named, unique namespace whenever
1261possible. This is considered an advantage over dumping everything in
1262the global namespace, as then name look-up can be explicitly enabled or
1263disabled as above, symbols are consistently mangled without repetitive
1264naming prefixes or macros, etc.
1265</para>
1266
1267<para>For instance, consider a project that defines most of its classes in <code>namespace gtk</code>. It is possible to
1268	adapt <code>namespace gtk</code> to <code>namespace std</code> by using a C++-feature called
1269	<emphasis>namespace composition</emphasis>. This is what happens if
1270	a <emphasis>using</emphasis>-declaration is put into a
1271	namespace-definition: the imported symbol(s) gets imported into the
1272	currently active namespace(s). For example:
1273</para>
1274<programlisting>
1275namespace gtk
1276{
1277  using std::string;
1278  using std::tr1::array;
1279
1280  class Window { ... };
1281}
1282</programlisting>
1283<para>
1284	In this example, <code>std::string</code> gets imported into
1285	<code>namespace gtk</code>.  The result is that use of
1286	<code>std::string</code> inside namespace gtk can just use <code>string</code>, without the explicit qualification.
1287	As an added bonus,
1288	<code>std::string</code> does not get imported into
1289	the global namespace.  Additionally, a more elaborate arrangement can be made for backwards compatibility and portability, whereby the
1290	<code>using</code>-declarations can wrapped in macros that
1291	are set based on autoconf-tests to either "" or i.e. <code>using
1292	  std::string;</code> (depending on whether the system has
1293	libstdc++ in <code>std::</code> or not).  (ideas from
1294	Llewelly and Karl Nelson)
1295</para>
1296
1297
1298    </section>
1299  </section>
1300
1301  <section xml:id="manual.intro.using.linkage" xreflabel="Linkage"><info><title>Linking</title></info>
1302    <?dbhtml filename="using_dynamic_or_shared.html"?>
1303
1304
1305    <section xml:id="manual.intro.using.linkage.freestanding" xreflabel="Freestanding"><info><title>Almost Nothing</title></info>
1306
1307      <para>
1308	Or as close as it gets: freestanding. This is a minimal
1309	configuration, with only partial support for the standard
1310	library. Assume only the following header files can be used:
1311      </para>
1312
1313      <itemizedlist>
1314	<listitem>
1315	  <para>
1316	    <filename class="headerfile">cstdarg</filename>
1317	  </para>
1318	</listitem>
1319
1320	<listitem>
1321	  <para>
1322	  <filename class="headerfile">cstddef</filename>
1323	  </para>
1324	</listitem>
1325
1326	<listitem>
1327	  <para>
1328	  <filename class="headerfile">cstdlib</filename>
1329	  </para>
1330	</listitem>
1331
1332	<listitem>
1333	  <para>
1334	  <filename class="headerfile">exception</filename>
1335	  </para>
1336	</listitem>
1337
1338	<listitem>
1339	  <para>
1340	  <filename class="headerfile">limits</filename>
1341	  </para>
1342	</listitem>
1343
1344	<listitem>
1345	  <para>
1346	  <filename class="headerfile">new</filename>
1347	  </para>
1348	</listitem>
1349
1350	<listitem>
1351	  <para>
1352	  <filename class="headerfile">exception</filename>
1353	  </para>
1354	</listitem>
1355
1356	<listitem>
1357	  <para>
1358	  <filename class="headerfile">typeinfo</filename>
1359	  </para>
1360	</listitem>
1361      </itemizedlist>
1362
1363      <para>
1364	In addition, throw in
1365      </para>
1366
1367      <itemizedlist>
1368	<listitem>
1369	  <para>
1370	  <filename class="headerfile">cxxabi.h</filename>.
1371	  </para>
1372	</listitem>
1373      </itemizedlist>
1374
1375      <para>
1376	In the
1377	C++11 <link linkend="manual.intro.using.flags">dialect</link> add
1378      </para>
1379
1380      <itemizedlist>
1381	<listitem>
1382	  <para>
1383	  <filename class="headerfile">initializer_list</filename>
1384	  </para>
1385	</listitem>
1386	<listitem>
1387	  <para>
1388	  <filename class="headerfile">type_traits</filename>
1389	  </para>
1390	</listitem>
1391      </itemizedlist>
1392
1393      <para> There exists a library that offers runtime support for
1394	just these headers, and it is called
1395	<filename class="libraryfile">libsupc++.a</filename>. To use it, compile with <command>gcc</command> instead of <command>g++</command>, like so:
1396      </para>
1397
1398      <para>
1399	<command>gcc foo.cc -lsupc++</command>
1400      </para>
1401
1402      <para>
1403	No attempt is made to verify that only the minimal subset
1404	identified above is actually used at compile time. Violations
1405	are diagnosed as undefined symbols at link time.
1406      </para>
1407    </section>
1408
1409    <section xml:id="manual.intro.using.linkage.dynamic" xreflabel="Dynamic and Shared"><info><title>Finding Dynamic or Shared Libraries</title></info>
1410
1411
1412    <para>
1413      If the only library built is the static library
1414      (<filename class="libraryfile">libstdc++.a</filename>), or if
1415      specifying static linking, this section is can be skipped.  But
1416      if building or using a shared library
1417      (<filename class="libraryfile">libstdc++.so</filename>), then
1418      additional location information will need to be provided.
1419    </para>
1420    <para>
1421      But how?
1422    </para>
1423    <para>
1424A quick read of the relevant part of the GCC
1425      manual, <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/onlinedocs/gcc/Invoking-G_002b_002b.html#Invoking-G_002b_002b">Compiling
1426      C++ Programs</link>, specifies linking against a C++
1427      library. More details from the
1428      GCC <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/faq.html#rpath">FAQ</link>,
1429      which states <emphasis>GCC does not, by default, specify a
1430      location so that the dynamic linker can find dynamic libraries at
1431      runtime.</emphasis>
1432    </para>
1433    <para>
1434      Users will have to provide this information.
1435    </para>
1436    <para>
1437      Methods vary for different platforms and different styles, and
1438      are printed to the screen during installation. To summarize:
1439    </para>
1440    <itemizedlist>
1441      <listitem>
1442	<para>
1443	  At runtime set <literal>LD_LIBRARY_PATH</literal> in your
1444	  environment correctly, so that the shared library for
1445	  libstdc++ can be found and loaded.  Be certain that you
1446	  understand all of the other implications and behavior
1447	  of <literal>LD_LIBRARY_PATH</literal> first.
1448	</para>
1449
1450      </listitem>
1451      <listitem>
1452	<para>
1453	  Compile the path to find the library at runtime into the
1454	  program.  This can be done by passing certain options to
1455	  <command>g++</command>, which will in turn pass them on to
1456	  the linker.  The exact format of the options is dependent on
1457	  which linker you use:
1458	</para>
1459	<itemizedlist>
1460	  <listitem>
1461	    <para>
1462	      GNU ld (default on GNU/Linux):
1463              <literal>-Wl,-rpath,</literal><filename class="directory">destdir/lib</filename>
1464	    </para>
1465	  </listitem>
1466	  <listitem>
1467	  <para>
1468	    Solaris ld:
1469            <literal>-Wl,-R</literal><filename class="directory">destdir/lib</filename>
1470	  </para>
1471	  </listitem>
1472	</itemizedlist>
1473      </listitem>
1474      <listitem>
1475	<para>
1476	  Some linkers allow you to specify the path to the library by
1477	  setting <literal>LD_RUN_PATH</literal> in your environment
1478	  when linking.
1479	</para>
1480      </listitem>
1481      <listitem>
1482	<para>
1483	  On some platforms the system administrator can configure the
1484	  dynamic linker to always look for libraries in
1485	  <filename class="directory">destdir/lib</filename>, for example
1486	  by using the <command>ldconfig</command> utility on GNU/Linux
1487	  or the <command>crle</command> utility on Solaris. This is a
1488	  system-wide change which can make the system unusable so if you
1489	  are unsure then use one of the other methods described above.
1490	</para>
1491      </listitem>
1492    </itemizedlist>
1493    <para>
1494      Use the <command>ldd</command> utility on the linked executable
1495      to show
1496      which <filename class="libraryfile">libstdc++.so</filename>
1497      library the system will get at runtime.
1498    </para>
1499    <para>
1500      A <filename class="libraryfile">libstdc++.la</filename> file is
1501      also installed, for use with Libtool.  If you use Libtool to
1502      create your executables, these details are taken care of for
1503      you.
1504    </para>
1505    </section>
1506
1507    <section xml:id="manual.intro.using.linkage.experimental" xreflabel="Library Extensions"><info><title>Experimental Library Extensions</title></info>
1508
1509    <para>
1510      GCC 5.3 includes an implementation of the Filesystem library defined
1511      by the technical specification ISO/IEC TS 18822:2015. Because this is
1512      an experimental library extension, not part of the C++ standard, it
1513      is implemented in a separate library,
1514      <filename class="libraryfile">libstdc++fs.a</filename>, and there is
1515      no shared library for it. To use the library you should include
1516      <filename class="headerfile">&lt;experimental/filesystem&gt;</filename>
1517      and link with <option>-lstdc++fs</option>. The library implementation
1518      is incomplete on non-POSIX platforms, specifically Windows support is
1519      rudimentary.
1520    </para>
1521
1522    <para>
1523      Due to the experimental nature of the Filesystem library the usual
1524      guarantees about ABI stability and backwards compatibility do not apply
1525      to it. There is no guarantee that the components in any
1526      <filename class="headerfile">&lt;experimental/xxx&gt;</filename>
1527      header will remain compatible between different GCC releases.
1528    </para>
1529    </section>
1530  </section>
1531
1532  <section xml:id="manual.intro.using.concurrency" xreflabel="Concurrency"><info><title>Concurrency</title></info>
1533    <?dbhtml filename="using_concurrency.html"?>
1534
1535
1536   <para>This section discusses issues surrounding the proper compilation
1537      of multithreaded applications which use the Standard C++
1538      library.  This information is GCC-specific since the C++
1539      standard does not address matters of multithreaded applications.
1540   </para>
1541
1542    <section xml:id="manual.intro.using.concurrency.prereq" xreflabel="Thread Prereq"><info><title>Prerequisites</title></info>
1543
1544
1545   <para>All normal disclaimers aside, multithreaded C++ application are
1546      only supported when libstdc++ and all user code was built with
1547      compilers which report (via <code> gcc/g++ -v </code>) the same thread
1548      model and that model is not <emphasis>single</emphasis>.  As long as your
1549      final application is actually single-threaded, then it should be
1550      safe to mix user code built with a thread model of
1551      <emphasis>single</emphasis> with a libstdc++ and other C++ libraries built
1552      with another thread model useful on the platform.  Other mixes
1553      may or may not work but are not considered supported.  (Thus, if
1554      you distribute a shared C++ library in binary form only, it may
1555      be best to compile it with a GCC configured with
1556      --enable-threads for maximal interchangeability and usefulness
1557      with a user population that may have built GCC with either
1558      --enable-threads or --disable-threads.)
1559   </para>
1560   <para>When you link a multithreaded application, you will probably
1561      need to add a library or flag to g++.  This is a very
1562      non-standardized area of GCC across ports.  Some ports support a
1563      special flag (the spelling isn't even standardized yet) to add
1564      all required macros to a compilation (if any such flags are
1565      required then you must provide the flag for all compilations not
1566      just linking) and link-library additions and/or replacements at
1567      link time.  The documentation is weak.  On several targets (including
1568      GNU/Linux, Solaris and various BSDs) -pthread is honored.
1569      Some other ports use other switches.
1570      This is not well documented anywhere other than
1571      in "gcc -dumpspecs" (look at the 'lib' and 'cpp' entries).
1572   </para>
1573
1574   <para>
1575     Some uses of <classname>std::atomic</classname> also require linking
1576     to <filename class="libraryfile">libatomic</filename>.
1577   </para>
1578
1579    </section>
1580
1581    <section xml:id="manual.intro.using.concurrency.thread_safety" xreflabel="Thread Safety"><info><title>Thread Safety</title></info>
1582
1583
1584<para>
1585In the terms of the 2011 C++ standard a thread-safe program is one which
1586does not perform any conflicting non-atomic operations on memory locations
1587and so does not contain any data races.
1588The standard places requirements on the library to ensure that no data
1589races are caused by the library itself or by programs which use the
1590library correctly (as described below).
1591The C++11 memory model and library requirements are a more formal version
1592of the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.sgi.com/tech/stl/thread_safety.html">SGI STL</link> definition of thread safety, which the library used
1593prior to the 2011 standard.
1594</para>
1595
1596
1597      <para>The library strives to be thread-safe when all of the following
1598	 conditions are met:
1599      </para>
1600      <itemizedlist>
1601       <listitem>
1602       <para>The system's libc is itself thread-safe,
1603       </para>
1604       </listitem>
1605       <listitem>
1606	 <para>
1607	   The compiler in use reports a thread model other than
1608	   'single'. This can be tested via output from <code>gcc
1609	   -v</code>. Multi-thread capable versions of gcc output
1610	   something like this:
1611	 </para>
1612<programlisting>
1613%gcc -v
1614Using built-in specs.
1615...
1616Thread model: posix
1617gcc version 4.1.2 20070925 (Red Hat 4.1.2-33)
1618</programlisting>
1619
1620<para>Look for "Thread model" lines that aren't equal to "single."</para>
1621       </listitem>
1622       <listitem>
1623       <para>
1624	 Requisite command-line flags are used for atomic operations
1625	 and threading. Examples of this include <code>-pthread</code>
1626	 and <code>-march=native</code>, although specifics vary
1627	 depending on the host environment. See
1628	 <link linkend="manual.intro.using.flags">Command Options</link> and
1629	 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html">Machine
1630	 Dependent Options</link>.
1631       </para>
1632       </listitem>
1633       <listitem>
1634	 <para>
1635	   An implementation of the
1636	   <filename class="headerfile">atomicity.h</filename> functions
1637	   exists for the architecture in question. See the
1638	   <link linkend="internals.thread_safety">internals
1639	   documentation</link> for more details.
1640       </para>
1641       </listitem>
1642
1643      </itemizedlist>
1644
1645      <para>The user code must guard against concurrent function calls which
1646         access any particular library object's state when one or more of
1647         those accesses modifies the state. An object will be modified by
1648         invoking a non-const member function on it or passing it as a
1649         non-const argument to a library function. An object will not be
1650         modified by invoking a const member function on it or passing it to
1651         a function as a pointer- or reference-to-const.
1652         Typically, the application
1653         programmer may infer what object locks must be held based on the
1654         objects referenced in a function call and whether the objects are
1655         accessed as const or non-const.  Without getting
1656	 into great detail, here is an example which requires user-level
1657	 locks:
1658      </para>
1659      <programlisting>
1660     library_class_a shared_object_a;
1661
1662     void thread_main () {
1663       library_class_b *object_b = new library_class_b;
1664       shared_object_a.add_b (object_b);   // must hold lock for shared_object_a
1665       shared_object_a.mutate ();          // must hold lock for shared_object_a
1666     }
1667
1668     // Multiple copies of thread_main() are started in independent threads.</programlisting>
1669      <para>Under the assumption that object_a and object_b are never exposed to
1670	 another thread, here is an example that does not require any
1671	 user-level locks:
1672      </para>
1673      <programlisting>
1674     void thread_main () {
1675       library_class_a object_a;
1676       library_class_b *object_b = new library_class_b;
1677       object_a.add_b (object_b);
1678       object_a.mutate ();
1679     } </programlisting>
1680
1681      <para>All library types are safe to use in a multithreaded program
1682         if objects are not shared between threads or as
1683	 long each thread carefully locks out access by any other
1684	 thread while it modifies any object visible to another thread.
1685	 Unless otherwise documented, the only exceptions to these rules
1686         are atomic operations on the types in
1687         <filename class="headerfile">&lt;atomic&gt;</filename>
1688         and lock/unlock operations on the standard mutex types in
1689         <filename class="headerfile">&lt;mutex&gt;</filename>. These
1690         atomic operations allow concurrent accesses to the same object
1691         without introducing data races.
1692      </para>
1693
1694      <para>The following member functions of standard containers can be
1695         considered to be const for the purposes of avoiding data races:
1696         <code>begin</code>, <code>end</code>, <code>rbegin</code>, <code>rend</code>,
1697         <code>front</code>, <code>back</code>, <code>data</code>,
1698         <code>find</code>, <code>lower_bound</code>, <code>upper_bound</code>,
1699         <code>equal_range</code>, <code>at</code>
1700         and, except in associative or unordered associative containers,
1701         <code>operator[]</code>. In other words, although they are non-const
1702         so that they can return mutable iterators, those member functions
1703         will not modify the container.
1704         Accessing an iterator might cause a non-modifying access to
1705         the container the iterator refers to (for example incrementing a
1706         list iterator must access the pointers between nodes, which are part
1707         of the container and so conflict with other accesses to the container).
1708      </para>
1709
1710      <para>Programs which follow the rules above will not encounter data
1711         races in library code, even when using library types which share
1712         state between distinct objects.  In the example below the
1713         <code>shared_ptr</code> objects share a reference count, but
1714         because the code does not perform any non-const operations on the
1715         globally-visible object, the library ensures that the reference
1716         count updates are atomic and do not introduce data races:
1717      </para>
1718      <programlisting>
1719    std::shared_ptr&lt;int&gt; global_sp;
1720
1721    void thread_main() {
1722      auto local_sp = global_sp;  // OK, copy constructor's parameter is reference-to-const
1723
1724      int i = *global_sp;         // OK, operator* is const
1725      int j = *local_sp;          // OK, does not operate on global_sp
1726
1727      // *global_sp = 2;          // NOT OK, modifies int visible to other threads
1728      // *local_sp = 2;           // NOT OK, modifies int visible to other threads
1729
1730      // global_sp.reset();       // NOT OK, reset is non-const
1731      local_sp.reset();           // OK, does not operate on global_sp
1732    }
1733
1734    int main() {
1735      global_sp.reset(new int(1));
1736      std::thread t1(thread_main);
1737      std::thread t2(thread_main);
1738      t1.join();
1739      t2.join();
1740    }
1741      </programlisting>
1742
1743      <para>For further details of the C++11 memory model see Hans-J. Boehm's
1744      <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.hpl.hp.com/personal/Hans_Boehm/c++mm/user-faq.html">Threads
1745      and memory model for C++</link> pages, particularly the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.hpl.hp.com/personal/Hans_Boehm/c++mm/threadsintro.html">introduction</link>
1746      and <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.hpl.hp.com/personal/Hans_Boehm/c++mm/user-faq.html">FAQ</link>.
1747      </para>
1748
1749  </section>
1750  <section xml:id="manual.intro.using.concurrency.atomics" xreflabel="Atomics"><info><title>Atomics</title></info>
1751
1752    <para>
1753    </para>
1754  </section>
1755
1756    <section xml:id="manual.intro.using.concurrency.io" xreflabel="IO"><info><title>IO</title></info>
1757
1758     <para>This gets a bit tricky.  Please read carefully, and bear with me.
1759   </para>
1760
1761    <section xml:id="concurrency.io.structure" xreflabel="Structure"><info><title>Structure</title></info>
1762
1763   <para>A wrapper
1764      type called <code>__basic_file</code> provides our abstraction layer
1765      for the <code>std::filebuf</code> classes.  Nearly all decisions dealing
1766      with actual input and output must be made in <code>__basic_file</code>.
1767   </para>
1768   <para>A generic locking mechanism is somewhat in place at the filebuf layer,
1769      but is not used in the current code.  Providing locking at any higher
1770      level is akin to providing locking within containers, and is not done
1771      for the same reasons (see the links above).
1772   </para>
1773    </section>
1774
1775    <section xml:id="concurrency.io.defaults" xreflabel="Defaults"><info><title>Defaults</title></info>
1776
1777   <para>The __basic_file type is simply a collection of small wrappers around
1778      the C stdio layer (again, see the link under Structure).  We do no
1779      locking ourselves, but simply pass through to calls to <code>fopen</code>,
1780      <code>fwrite</code>, and so forth.
1781   </para>
1782   <para>So, for 3.0, the question of "is multithreading safe for I/O"
1783      must be answered with, "is your platform's C library threadsafe
1784      for I/O?"  Some are by default, some are not; many offer multiple
1785      implementations of the C library with varying tradeoffs of threadsafety
1786      and efficiency.  You, the programmer, are always required to take care
1787      with multiple threads.
1788   </para>
1789   <para>(As an example, the POSIX standard requires that C stdio FILE*
1790       operations are atomic.  POSIX-conforming C libraries (e.g, on Solaris
1791       and GNU/Linux) have an internal mutex to serialize operations on
1792       FILE*s.  However, you still need to not do stupid things like calling
1793       <code>fclose(fs)</code> in one thread followed by an access of
1794       <code>fs</code> in another.)
1795   </para>
1796   <para>So, if your platform's C library is threadsafe, then your
1797      <code>fstream</code> I/O operations will be threadsafe at the lowest
1798      level.  For higher-level operations, such as manipulating the data
1799      contained in the stream formatting classes (e.g., setting up callbacks
1800      inside an <code>std::ofstream</code>), you need to guard such accesses
1801      like any other critical shared resource.
1802   </para>
1803    </section>
1804
1805    <section xml:id="concurrency.io.future" xreflabel="Future"><info><title>Future</title></info>
1806
1807   <para> A
1808      second choice may be available for I/O implementations:  libio.  This is
1809      disabled by default, and in fact will not currently work due to other
1810      issues.  It will be revisited, however.
1811   </para>
1812   <para>The libio code is a subset of the guts of the GNU libc (glibc) I/O
1813      implementation.  When libio is in use, the <code>__basic_file</code>
1814      type is basically derived from FILE.  (The real situation is more
1815      complex than that... it's derived from an internal type used to
1816      implement FILE.  See libio/libioP.h to see scary things done with
1817      vtbls.)  The result is that there is no "layer" of C stdio
1818      to go through; the filebuf makes calls directly into the same
1819      functions used to implement <code>fread</code>, <code>fwrite</code>,
1820      and so forth, using internal data structures.  (And when I say
1821      "makes calls directly," I mean the function is literally
1822      replaced by a jump into an internal function.  Fast but frightening.
1823      *grin*)
1824   </para>
1825   <para>Also, the libio internal locks are used.  This requires pulling in
1826      large chunks of glibc, such as a pthreads implementation, and is one
1827      of the issues preventing widespread use of libio as the libstdc++
1828      cstdio implementation.
1829   </para>
1830   <para>But we plan to make this work, at least as an option if not a future
1831      default.  Platforms running a copy of glibc with a recent-enough
1832      version will see calls from libstdc++ directly into the glibc already
1833      installed.  For other platforms, a copy of the libio subsection will
1834      be built and included in libstdc++.
1835   </para>
1836    </section>
1837
1838    <section xml:id="concurrency.io.alt" xreflabel="Alt"><info><title>Alternatives</title></info>
1839
1840   <para>Don't forget that other cstdio implementations are possible.  You could
1841      easily write one to perform your own forms of locking, to solve your
1842      "interesting" problems.
1843   </para>
1844    </section>
1845
1846    </section>
1847
1848    <section xml:id="manual.intro.using.concurrency.containers" xreflabel="Containers"><info><title>Containers</title></info>
1849
1850
1851   <para>This section discusses issues surrounding the design of
1852      multithreaded applications which use Standard C++ containers.
1853      All information in this section is current as of the gcc 3.0
1854      release and all later point releases.  Although earlier gcc
1855      releases had a different approach to threading configuration and
1856      proper compilation, the basic code design rules presented here
1857      were similar.  For information on all other aspects of
1858      multithreading as it relates to libstdc++, including details on
1859      the proper compilation of threaded code (and compatibility between
1860      threaded and non-threaded code), see Chapter 17.
1861   </para>
1862   <para>Two excellent pages to read when working with the Standard C++
1863      containers and threads are
1864      <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.sgi.com/tech/stl/thread_safety.html">SGI's
1865      http://www.sgi.com/tech/stl/thread_safety.html</link> and
1866      <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.sgi.com/tech/stl/Allocators.html">SGI's
1867      http://www.sgi.com/tech/stl/Allocators.html</link>.
1868   </para>
1869   <para><emphasis>However, please ignore all discussions about the user-level
1870      configuration of the lock implementation inside the STL
1871      container-memory allocator on those pages.  For the sake of this
1872      discussion, libstdc++ configures the SGI STL implementation,
1873      not you.  This is quite different from how gcc pre-3.0 worked.
1874      In particular, past advice was for people using g++ to
1875      explicitly define _PTHREADS or other macros or port-specific
1876      compilation options on the command line to get a thread-safe
1877      STL.  This is no longer required for any port and should no
1878      longer be done unless you really know what you are doing and
1879      assume all responsibility.</emphasis>
1880   </para>
1881   <para>Since the container implementation of libstdc++ uses the SGI
1882      code, we use the same definition of thread safety as SGI when
1883      discussing design.  A key point that beginners may miss is the
1884      fourth major paragraph of the first page mentioned above
1885      (<emphasis>For most clients...</emphasis>), which points out that
1886      locking must nearly always be done outside the container, by
1887      client code (that'd be you, not us).  There is a notable
1888      exceptions to this rule.  Allocators called while a container or
1889      element is constructed uses an internal lock obtained and
1890      released solely within libstdc++ code (in fact, this is the
1891      reason STL requires any knowledge of the thread configuration).
1892   </para>
1893   <para>For implementing a container which does its own locking, it is
1894      trivial to provide a wrapper class which obtains the lock (as
1895      SGI suggests), performs the container operation, and then
1896      releases the lock.  This could be templatized <emphasis>to a certain
1897      extent</emphasis>, on the underlying container and/or a locking
1898      mechanism.  Trying to provide a catch-all general template
1899      solution would probably be more trouble than it's worth.
1900   </para>
1901   <para>The library implementation may be configured to use the
1902      high-speed caching memory allocator, which complicates thread
1903      safety issues. For all details about how to globally override
1904      this at application run-time
1905      see <link linkend="manual.intro.using.macros">here</link>. Also
1906      useful are details
1907      on <link linkend="std.util.memory.allocator">allocator</link>
1908      options and capabilities.
1909   </para>
1910
1911    </section>
1912</section>
1913
1914<!-- Section 0x : Exception policies, expectations, topics -->
1915<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml" href="using_exceptions.xml">
1916</xi:include>
1917
1918<!-- Section 0x : Debug -->
1919<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml" href="debug.xml">
1920</xi:include>
1921
1922</chapter>
1923