Add missing <experimental/numeric> header to docs
[official-gcc.git] / libstdc++-v3 / doc / xml / faq.xml
blobedc07f16acb32e4079c21bc80206e7b112ab50a2
1 <book xmlns="http://docbook.org/ns/docbook" version="5.0">
3 <article xml:id="faq" xreflabel="Frequently Asked Questions">
4 <?dbhtml filename="faq.html"?>
5  
6 <info><title>Frequently Asked Questions</title>
7   
8   <copyright>
9     <year>
10       2008-2018
11     </year>
12     <holder>
13       <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://www.fsf.org">FSF</link>
14     </holder>
15   </copyright>
16 </info>
18 <!-- FAQ starts here -->
19 <qandaset xml:id="faq.faq">
21 <!-- General Information -->
22 <qandadiv xml:id="faq.info" xreflabel="General Information">
24 <qandaentry xml:id="faq.what">
25   <question xml:id="faq.what.q">
26     <para>
27       What is libstdc++?
28     </para>
29   </question>
30   <answer xml:id="faq.what.a">
31     <para>
32      The GNU Standard C++ Library v3 is an ongoing project to
33      implement the ISO 14882 C++ Standard Library as described in
34      clauses 20 through 33 and annex D (prior to the 2017 standard
35      the library clauses started with 17).  For those who want to see
36      exactly how far the project has come, or just want the latest
37      bleeding-edge code, the up-to-date source is available over
38      anonymous SVN, and can be browsed over the
39      <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/svn.html">web</link>.
40     </para> 
42     <para>
43     N.B. The library is called libstdc++ <emphasis>not</emphasis> stdlibc++.
44     </para>
45   </answer>
46 </qandaentry>
48 <qandaentry xml:id="faq.why">
49   <question xml:id="q-why">
50     <para>
51       Why should I use libstdc++?
52     </para>
53   </question>
54   <answer xml:id="a-why">
55     <para>
56     The completion of the initial ISO C++ standardization effort gave the C++
57     community a powerful set of reuseable tools in the form of the C++
58     Standard Library.  However, for several years C++ implementations were
59     (as the Draft Standard used to say) <quote>incomplet and
60     incorrekt</quote>, and many suffered from limitations of the compilers
61     that used them.
62     </para> 
63     <para>
64     The GNU compiler collection
65     (<command>gcc</command>, <command>g++</command>, etc) is widely
66     considered to be one of the leading compilers in the world.  Its
67     development is overseen by the
68     <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/">GCC team</link>.  All of
69     the rapid development and near-legendary
70     <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/buildstat.html">portability</link>
71     that are the hallmarks of an open-source project are applied to libstdc++.
72     </para> 
73     <para>
74     All of the standard classes and functions from C++98/C++03, C++11 and C++14
75     (such as <classname>string</classname>,
76     <classname>vector&lt;&gt;</classname>, iostreams, algorithms etc.)
77     are freely available and attempt to be fully compliant.
78     Work is ongoing to complete support for the current revision of the
79     ISO C++ Standard.
80     </para>
81   </answer>
82 </qandaentry>
84 <qandaentry xml:id="faq.who">
85   <question xml:id="q-who">
86     <para>
87       Who's in charge of it?
88     </para>
89   </question>
90   <answer xml:id="a-who">
91     <para>
92      The libstdc++ project is contributed to by several developers
93      all over the world, in the same way as GCC or the Linux kernel.
94      The current maintainers are listed in the
95      <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/viewcvs/gcc/trunk/MAINTAINERS?view=co"><filename>MAINTAINERS</filename></link>
96      file (look for "c++ runtime libs").
97     </para>
98     <para>
99     Development and discussion is held on the libstdc++ mailing
100     list.  Subscribing to the list, or searching the list
101     archives, is open to everyone.  You can read instructions for
102     doing so on the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/lists.html">GCC mailing lists</link> page.
103     If you have questions, ideas, code, or are just curious, sign up!
104     </para> 
105   </answer>
106 </qandaentry>
108 <qandaentry xml:id="faq.when">
109   <question xml:id="q-when">
110     <para>
111       When is libstdc++ going to be finished?
112     </para>
113   </question>
114   <answer xml:id="a-when">
115     <para>
116     Nathan Myers gave the best of all possible answers, responding to
117     a Usenet article asking this question: <emphasis>Sooner, if you
118     help.</emphasis>
119     </para> 
120   </answer>
121 </qandaentry>
123 <qandaentry xml:id="faq.how">
124   <question xml:id="q-how">
125     <para>
126       How do I contribute to the effort?
127     </para>
128   </question>
129   <answer xml:id="a-how">
130     <para>
131     See the <link linkend="appendix.contrib">Contributing</link> section in
132     the manual. Subscribing to the mailing list (see above, or
133     the homepage) is a very good idea if you have something to
134     contribute, or if you have spare time and want to
135     help. Contributions don't have to be in the form of source code;
136     anybody who is willing to help write documentation, for example,
137     or has found a bug in code that we all thought was working and is
138     willing to provide details, is more than welcome!
139     </para> 
140   </answer>
141 </qandaentry>
143 <qandaentry xml:id="faq.whereis_old">
144   <question xml:id="q-whereis_old">
145     <para>
146       What happened to the older libg++? I need that!
147     </para>
148   </question>
149   <answer xml:id="a-whereis_old">
150     <para>
151     The last libg++ README states
152     <quote>This package is considered obsolete and is no longer
153     being developed.</quote>
154     It should not be used for new projects, and won't even compile with
155     recent releases of GCC (or most other C++ compilers).
156     </para> 
157     <para>
158     More information can be found in the
159     <link linkend="manual.appendix.porting.backwards">Backwards
160     Compatibility</link> section of the libstdc++ manual.
161     </para>
162   </answer>
163 </qandaentry>
165 <qandaentry xml:id="faq.more_questions">
166   <question xml:id="q-more_questions">
167     <para>
168       What if I have more questions?
169     </para>
170   </question>
171   <answer xml:id="a-more_questions">
172     <para>
173     If you have read the documentation, and your question remains
174     unanswered, then just ask the mailing list. At present, you do not
175     need to be subscribed to the list to send a message to it.  More
176     information is available on the homepage (including how to browse
177     the list archives); to send a message to the list,
178     use <email>libstdc++@gcc.gnu.org</email>.
179     </para> 
181     <para> 
182     If you have a question that you think should be included
183     here, or if you have a question <emphasis>about</emphasis> a question/answer
184     here, please send email to the libstdc++ mailing list, as above.
185     </para> 
186   </answer>
187 </qandaentry>
189 </qandadiv>
191 <!-- License -->
192 <qandadiv xml:id="faq.license" xreflabel="License QA">
195 <qandaentry xml:id="faq.license.what">
196   <question xml:id="q-license.what">
197     <para>
198       What are the license terms for libstdc++?
199     </para>
200   </question>
201   <answer xml:id="a-license.what">
202     <para>
203     See <link linkend="manual.intro.status.license">our license description</link>
204     for these and related questions.
205     </para> 
206   </answer>
207 </qandaentry>
209 <qandaentry xml:id="faq.license.any_program">
210   <question xml:id="q-license.any_program">
211     <para>
212       So any program which uses libstdc++ falls under the GPL?
213     </para>
214   </question>
215   <answer xml:id="a-license.any_program">
216     <para>
217      No. The special exception permits use of the library in
218      proprietary applications.
219     </para> 
220   </answer>
221 </qandaentry>
224 <qandaentry xml:id="faq.license.lgpl">
225   <question xml:id="q-license.lgpl">
226     <para>
227       How is that different from the GNU {Lesser,Library} GPL?
228     </para>
229   </question>
230   <answer xml:id="a-license.lgpl">
231     <para>
232       The LGPL requires that users be able to replace the LGPL code with a
233      modified version; this is trivial if the library in question is a C
234      shared library.  But there's no way to make that work with C++, where
235      much of the library consists of inline functions and templates, which
236      are expanded inside the code that uses the library.  So to allow people
237      to replace the library code, someone using the library would have to
238      distribute their own source, rendering the LGPL equivalent to the GPL.
239     </para> 
240   </answer>
241 </qandaentry>
243 <qandaentry xml:id="faq.license.what_restrictions">
244   <question xml:id="q-license.what_restrictions">
245     <para>
246       I see. So, what restrictions are there on programs that use the library?
247     </para>
248   </question>
249   <answer xml:id="a-license.what_restrictions">
250     <para>
251       None.  We encourage such programs to be released as free software,
252      but we won't punish you or sue you if you choose otherwise.
253     </para> 
254   </answer>
255 </qandaentry>
257 </qandadiv>
259 <!-- Installation -->
260 <qandadiv xml:id="faq.installation" xreflabel="Installation">
263 <qandaentry xml:id="faq.how_to_install">
264   <question xml:id="q-how_to_install">
265     <para>How do I install libstdc++?
266     </para>
267   </question>
268   <answer xml:id="a-how_to_install">
269     <para>
270     Often libstdc++ comes pre-installed as an integral part of many
271     existing GNU/Linux and Unix systems, as well as many embedded
272     development tools. It may be necessary to install extra
273     development packages to get the headers, or the documentation, or
274     the source: please consult your vendor for details.
275     </para> 
276     <para> 
277     To build and install from the GNU GCC sources, please consult the 
278     <link linkend="manual.intro.setup">setup
279     documentation</link> for detailed
280     instructions. You may wish to browse those files ahead
281     of time to get a feel for what's required.
282     </para> 
283   </answer>
284 </qandaentry>
286 <qandaentry xml:id="faq.how_to_get_sources">
287   <question xml:id="q-how_to_get_sources">
288     <para>How does one get current libstdc++ sources?
289     </para>
290   </question>
291   <answer xml:id="a-how_to_get_sources">
292     <para>
293     Libstdc++ sources for all official releases can be obtained as
294     part of the GCC sources, available from various sites and
295     mirrors. A full <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/mirrors.html">list of
296     download sites</link> is provided on the main GCC site.
297     </para>
298     <para>
299     Current libstdc++ sources can always be checked out of the main
300     GCC source repository using the appropriate version control
301     tool. At this time, that tool
302     is <application>Subversion</application>.
303     </para>
304     <para>
305     <application>Subversion</application>, or <acronym>SVN</acronym>, is
306     one of several revision control packages.  It was selected for GNU
307     projects because it's free (speech), free (beer), and very high
308     quality.  The <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://subversion.tigris.org"> Subversion
309     home page</link> has a better description.
310     </para>
311     <para>
312     The <quote>anonymous client checkout</quote> feature of SVN is
313     similar to anonymous FTP in that it allows anyone to retrieve
314     the latest libstdc++ sources.
315     </para> 
316     <para>
317     For more information
318     see <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/svn.html"><acronym>SVN</acronym>
319     details</link>.
320     </para>
321   </answer>
322 </qandaentry>
324 <qandaentry xml:id="faq.how_to_test">
325   <question xml:id="q-how_to_test">
326     <para>How do I know if it works?
327     </para>
328   </question>
329   <answer xml:id="a-how_to_test">
330     <para>
331     Libstdc++ comes with its own validation testsuite, which includes
332     conformance testing, regression testing, ABI testing, and
333     performance testing. Please consult the 
334     <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/install/test.html">testing
335     documentation</link> for GCC and
336     <link linkend="manual.intro.setup.test">Testing</link> in the libstdc++
337     manual for more details.
338     </para> 
339     <para>
340     If you find bugs in the testsuite programs themselves, or if you
341     think of a new test program that should be added to the suite,
342     <emphasis>please</emphasis> write up your idea and send it to the list!
343     </para>
344   </answer>
345 </qandaentry>
347 <qandaentry xml:id="faq.how_to_set_paths">
348   <question xml:id="q-how_to_set_paths">
349     <para>How do I insure that the dynamically linked library will be found?
350     </para>
351   </question>
352   <answer xml:id="a-how_to_set_paths">
353     <para>
354     Depending on your platform and library version, the error message might
355     be similar to one of the following:
356     </para>
358     <screen>
359     ./a.out: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
361     /usr/libexec/ld-elf.so.1: Shared object "libstdc++.so.6" not found
362     </screen>
364     <para>
365     This doesn't mean that the shared library isn't installed, only
366     that the dynamic linker can't find it. When a dynamically-linked
367     executable is run the linker finds and loads the required shared
368     libraries by searching a pre-configured list of directories. If
369     the directory where you've installed libstdc++ is not in this list
370     then the libraries won't be found.
371     </para>
373     <para>
374     If you already have an older version of libstdc++ installed then the
375     error might look like one of the following instead:
376     </para>
378     <screen>
379     ./a.out: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.20' not found
380     ./a.out: /usr/lib/libstdc++.so.6: version `CXXABI_1.3.8' not found
381     </screen>
383     <para>
384     This means the linker found <filename>/usr/lib/libstdc++.so.6</filename>
385     but that library belongs to an older version of GCC than was used to
386     compile and link the program <filename>a.out</filename> (or some part
387     of it). The program depends on code defined in the newer libstdc++
388     that belongs to the newer version of GCC, so the linker must be told
389     how to find the newer libstdc++ shared library.
390     </para>
392     <para>
393     The simplest way to fix this is
394     to use the <envar>LD_LIBRARY_PATH</envar> environment variable,
395     which is a colon-separated list of directories in which the linker
396     will search for shared libraries:
397     </para>
399     <screen><command>
400     export LD_LIBRARY_PATH=${prefix}/lib:$LD_LIBRARY_PATH
401     </command></screen>
403     <para>
404     Here the shell variable <varname>${prefix}</varname> is assumed to contain
405     the directory prefix where GCC was installed to. The directory containing
406     the library might depend on whether you want the 32-bit or 64-bit copy
407     of the library, so for example would be
408     <filename class="directory">${prefix}/lib64</filename> on some systems.
409     The exact environment variable to use will depend on your
410     platform, e.g. <envar>DYLD_LIBRARY_PATH</envar> for Darwin,
411     <envar>LD_LIBRARY_PATH_32</envar>/<envar>LD_LIBRARY_PATH_64</envar>
412     for Solaris 32-/64-bit,
413     and <envar>SHLIB_PATH</envar> for HP-UX.
414     </para>
415     <para>
416     See the man pages for <command>ld</command>, <command>ldd</command>
417     and <command>ldconfig</command> for more information. The dynamic
418     linker has different names on different platforms but the man page
419     is usually called something such as <filename>ld.so</filename>,
420     <filename>rtld</filename> or <filename>dld.so</filename>.
421     </para>
422     <para>
423     Using <envar>LD_LIBRARY_PATH</envar> is not always the best solution,
424     <link linkend="manual.intro.using.linkage.dynamic">Finding Dynamic or Shared
425     Libraries</link> in the manual gives some alternatives.
426     </para>
427   </answer>
428 </qandaentry>
430 <qandaentry xml:id="faq.what_is_libsupcxx">
431   <question xml:id="q-what_is_libsupcxx">
432     <para>
433       What's libsupc++?
434     </para>
435   </question>
436   <answer xml:id="a-what_is_libsupcxx">
437     <para>
438       If the only functions from <filename class="libraryfile">libstdc++.a</filename>
439       which you need are language support functions (those listed in
440       <link linkend="std.support">clause 18</link> of the
441       standard, e.g., <function>new</function> and
442       <function>delete</function>), then try linking against
443       <filename class="libraryfile">libsupc++.a</filename>, which is a subset of
444       <filename class="libraryfile">libstdc++.a</filename>.  (Using <command>gcc</command>
445       instead of <command>g++</command> and explicitly linking in
446       <filename class="libraryfile">libsupc++.a</filename> via <option>-lsupc++</option>
447       for the final link step will do it).  This library contains only
448       those support routines, one per object file.  But if you are
449       using anything from the rest of the library, such as IOStreams
450       or vectors, then you'll still need pieces from
451       <filename class="libraryfile">libstdc++.a</filename>.
452     </para> 
453   </answer>
454 </qandaentry>
456 <qandaentry xml:id="faq.size">
457   <question xml:id="q-size">
458     <para>
459       This library is HUGE!
460     </para>
461   </question>
462   <answer xml:id="a-size">
463     <para>
464     Usually the size of libraries on disk isn't noticeable.  When a
465     link editor (or simply <quote>linker</quote>) pulls things from a
466     static archive library, only the necessary object files are copied
467     into your executable, not the entire library.  Unfortunately, even
468     if you only need a single function or variable from an object file,
469     the entire object file is extracted.  (There's nothing unique to C++
470     or libstdc++ about this; it's just common behavior, given here
471     for background reasons.)
472     </para>
473     <para>
474     Some of the object files which make up
475     <filename class="libraryfile">libstdc++.a</filename> are rather large.
476     If you create a statically-linked executable with
477     <option>-static</option>, those large object files are suddenly part
478     of your executable.  Historically the best way around this was to
479     only place a very few functions (often only a single one) in each
480     source/object file; then extracting a single function is the same
481     as extracting a single <filename>.o</filename> file.  For libstdc++ this
482     is only possible to a certain extent; the object files in question contain
483     template classes and template functions, pre-instantiated, and
484     splitting those up causes severe maintenance headaches.
485     </para> 
486     <para>
487     On supported platforms, libstdc++ takes advantage of garbage
488     collection in the GNU linker to get a result similar to separating
489     each symbol into a separate source and object files. On these platforms,
490     GNU ld can place each function and variable into its own
491     section in a <filename>.o</filename> file.  The GNU linker can then perform
492     garbage collection on unused sections; this reduces the situation to only
493     copying needed functions into the executable, as before, but all
494     happens automatically.
495     </para>
496   </answer>
497 </qandaentry>
499 </qandadiv>
502 <!-- Platform-Specific Issues -->
503 <qandadiv xml:id="faq.platform-specific" xreflabel="Platform-Specific Issues">
506 <qandaentry xml:id="faq.other_compilers">
507   <question xml:id="q-other_compilers">
508     <para>
509       Can libstdc++ be used with non-GNU compilers?
510     </para>
511   </question>
512   <answer xml:id="a-other_compilers">
513     <para>
514     Perhaps.
515     </para> 
516     <para>
517     Since the goal of ISO Standardization is for all C++
518     implementations to be able to share code, libstdc++ should be
519     usable under any ISO-compliant compiler, at least in theory.
520     </para> 
521     <para>
522     However, the reality is that libstdc++ is targeted and optimized
523     for GCC/G++. This means that often libstdc++ uses specific,
524     non-standard features of G++ that are not present in older
525     versions of proprietary compilers. It may take as much as a year or two
526     after an official release of GCC that contains these features for
527     proprietary tools to support these constructs.
528     </para>
529     <para>
530     Recent versions of libstdc++ are known to work with the Clang compiler.
531     In the near past, specific released versions of libstdc++ have
532     been known to work with versions of the EDG C++ compiler, and
533     vendor-specific proprietary C++ compilers such as the Intel ICC
534     C++ compiler.
535     </para> 
537   </answer>
538 </qandaentry>
540 <qandaentry xml:id="faq.solaris_long_long">
541   <question xml:id="q-solaris_long_long">
542     <para>
543       No '<type>long long</type>' type on Solaris?
544     </para>
545   </question>
546   <answer xml:id="a-solaris_long_long">
547     <note>
548        <para>This answer is old and probably no longer be relevant.</para>
549     </note>
550     <para>
551     By default we try to support the C99 <type>long long</type> type.
552     This requires that certain functions from your C library be present.
553     </para> 
554     <para> 
555     Up through release 3.0.2 the platform-specific tests performed by
556     libstdc++ were too general, resulting in a conservative approach
557     to enabling the <type>long long</type> code paths. The most
558     commonly reported platform affected was Solaris.
559     </para> 
560     <para> 
561     This has been fixed for libstdc++ releases greater than 3.0.3.
562     </para> 
563   </answer>
564 </qandaentry>
566 <qandaentry xml:id="faq.predefined">
567   <question xml:id="q-predefined">
568     <para>
569       <constant>_XOPEN_SOURCE</constant> and <constant>_GNU_SOURCE</constant> are always defined?
570     </para>
571   </question>
572   <answer xml:id="a-predefined">
573       <para>On Solaris, <command>g++</command> (but not <command>gcc</command>)
574          always defines the preprocessor macro
575          <constant>_XOPEN_SOURCE</constant>.  On GNU/Linux, the same happens
576          with <constant>_GNU_SOURCE</constant>.  (This is not an exhaustive list;
577          other macros and other platforms are also affected.)
578       </para>
579       <para>These macros are typically used in C library headers, guarding new
580          versions of functions from their older versions.  The C++98 standard
581          library includes the C standard library, but it requires the C90
582          version, which for backwards-compatibility reasons is often not the
583          default for many vendors.
584       </para>
585       <para>More to the point, the C++ standard requires behavior which is only
586          available on certain platforms after certain symbols are defined.
587          Usually the issue involves I/O-related typedefs.  In order to
588          ensure correctness, the compiler simply predefines those symbols.
589       </para>
590       <para>Note that it's not enough to <literal>#define</literal> them only when the library is
591          being built (during installation).  Since we don't have an 'export'
592          keyword, much of the library exists as headers, which means that
593          the symbols must also be defined as your programs are parsed and
594          compiled.
595       </para>
596       <para>To see which symbols are defined, look for
597          <varname>CPLUSPLUS_CPP_SPEC</varname> in
598          the gcc config headers for your target (and try changing them to
599          see what happens when building complicated code).  You can also run
600          <command>g++ -E -dM - &lt; /dev/null"</command> to display
601          a list of predefined macros for any particular installation.
602       </para>
603       <para>This has been discussed on the mailing lists
604          <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/cgi-bin/htsearch?method=and&amp;format=builtin-long&amp;sort=score&amp;words=_XOPEN_SOURCE+Solaris">quite a bit</link>.
605       </para>
606       <para>This method is something of a wart.  We'd like to find a cleaner
607          solution, but nobody yet has contributed the time.
608       </para>
610   </answer>
611 </qandaentry>
613 <qandaentry xml:id="faq.darwin_ctype">
614   <question xml:id="q-darwin_ctype">
615     <para>
616       Mac OS X <filename class="headerfile">ctype.h</filename> is broken! How can I fix it?
617     </para>
618   </question>
619   <answer xml:id="a-darwin_ctype">
620       <note>
621          <para>This answer is old and probably no longer be relevant.</para>
622       </note>
623       <para>
624          This was a long-standing bug in the OS X support.  Fortunately, the
625          <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/gcc/2002-03/msg00817.html">patch</link>
626          was quite simple, and well-known.
627       </para>
629   </answer>
630 </qandaentry>
632 <qandaentry xml:id="faq.threads_i386">
633   <question xml:id="q-threads_i386">
634     <para>
635       Threading is broken on i386?
636     </para>
637   </question>
638   <answer xml:id="a-threads_i386">
639       <note>
640          <para>This answer is old and probably no longer be relevant.</para>
641       </note>
642       <para>Support for atomic integer operations was broken on i386
643          platforms.  The assembly code accidentally used opcodes that are
644          only available on the i486 and later.  So if you configured GCC
645          to target, for example, i386-linux, but actually used the programs
646          on an i686, then you would encounter no problems.  Only when
647          actually running the code on a i386 will the problem appear.
648       </para>
649       <para>This is fixed in 3.2.2.
650       </para>
652   </answer>
653 </qandaentry>
655 <qandaentry xml:id="faq.atomic_mips">
656   <question xml:id="q-atomic_mips">
657     <para>
658       MIPS atomic operations
659     </para>
660   </question>
661   <answer xml:id="a-atomic_mips">
662     <note>
663       <para>This answer is old and probably no longer be relevant.</para>
664     </note>
665     <para>
666     The atomic locking routines for MIPS targets requires MIPS II
667     and later.  A patch went in just after the 3.3 release to
668     make mips* use the generic implementation instead.  You can also
669     configure for mipsel-elf as a workaround.
670     </para>
671     <para>    
672     The mips*-*-linux* port continues to use the MIPS II routines, and more
673     work in this area is expected.
674     </para> 
675   </answer>
676 </qandaentry>
678 <qandaentry xml:id="faq.linux_glibc">
679   <question xml:id="q-linux_glibc">
680     <para>
681       Recent GNU/Linux glibc required?
682     </para>
683   </question>
684   <answer xml:id="a-linux_glibc">
685       <para>When running on GNU/Linux, libstdc++ 3.2.1 (shared library version
686          5.0.1) and later uses localization and formatting code from the system
687          C library (glibc) version 2.2.5 which contains necessary bugfixes.
688          All GNU/Linux distros make more recent versions available now.
689          libstdc++ 4.6.0 and later require glibc 2.3 or later for this
690          localization and formatting code.
691       </para>
692       <para>The guideline is simple:  the more recent the C++ library, the
693          more recent the C library.  (This is also documented in the main
694          GCC installation instructions.)
695       </para>
697   </answer>
698 </qandaentry>
700 <qandaentry xml:id="faq.freebsd_wchar">
701   <question xml:id="q-freebsd_wchar">
702     <para>
703       Can't use <type>wchar_t</type>/<classname>wstring</classname> on FreeBSD
704     </para>
705   </question>
706   <answer xml:id="a-freebsd_wchar">
707     <note>
708       <para>This answer is old and probably no longer be relevant.</para>
709     </note>
710     <para>
711     Older versions of FreeBSD's C library do not have sufficient
712     support for wide character functions, and as a result the
713     libstdc++ configury decides that <type>wchar_t</type> support should be
714     disabled. In addition, the libstdc++ platform checks that
715     enabled <type>wchar_t</type> were quite strict, and not granular
716     enough to detect when the minimal support to
717     enable <type>wchar_t</type> and C++ library structures
718     like <classname>wstring</classname> were present. This impacted Solaris,
719     Darwin, and BSD variants, and is fixed in libstdc++ versions post 4.1.0.
720     </para> 
721     <para> 
722     </para> 
723   </answer>
724 </qandaentry>
726 </qandadiv>
729 <!-- Known Bugs -->
730 <qandadiv xml:id="faq.known_bugs" xreflabel="Known Bugs">
733 <qandaentry xml:id="faq.what_works">
734   <question xml:id="q-what_works">
735     <para>
736       What works already?
737     </para>
738   </question>
739   <answer xml:id="a-what_works">
740     <para>
741     Short answer: Pretty much everything <emphasis>works</emphasis>
742     except for some corner cases.  Support for localization
743     in <classname>locale</classname> may be incomplete on some non-GNU
744     platforms. Also dependent on the underlying platform is support
745     for <type>wchar_t</type> and <type>long long</type> specializations,
746     and details of thread support.
747     </para>
748     <para>    
749     Long answer: See the implementation status pages for 
750     <link linkend="status.iso.1998">C++98</link>,
751     <link linkend="status.iso.tr1">TR1</link>,
752     <link linkend="status.iso.2011">C++11</link>,
753     <link linkend="status.iso.2014">C++14</link>, and
754     <link linkend="status.iso.2017">C++17</link>.
755     </para> 
756   </answer>
757 </qandaentry>
759 <qandaentry xml:id="faq.standard_bugs">
760   <question xml:id="q-standard_bugs">
761     <para>
762       Bugs in the ISO C++ language or library specification
763     </para>
764   </question>
765   <answer xml:id="a-standard_bugs">
766     <para>
767     Unfortunately, there are some. 
768     </para>
769     <para>
770     For those people who are not part of the ISO Library Group
771     (i.e., nearly all of us needing to read this page in the first
772     place), a public list of the library defects is occasionally
773     published on <link xmlns:xlink="http://www.w3.org/1999/xlink"
774     xlink:href="http://www.open-std.org/jtc1/sc22/wg21/">the WG21
775     website</link>.
776     Many of these issues have resulted in
777     <link linkend="manual.intro.status.bugs.iso">code changes in libstdc++</link>.
778     </para> 
779     <para>
780     If you think you've discovered a new bug that is not listed,
781     please post a message describing your problem to the author of
782     the library issues list.
783     </para>
784   </answer>
785 </qandaentry>
787 <qandaentry xml:id="faq.compiler_bugs">
788   <question xml:id="q-compiler_bugs">
789     <para>
790       Bugs in the compiler (gcc/g++) and not libstdc++
791     </para>
792   </question>
793   <answer xml:id="a-compiler_bugs">
794     <para>
795     On occasion, the compiler is wrong. Please be advised that this
796     happens much less often than one would think, and avoid jumping to
797     conclusions.
798     </para>
799     <para>
800     First, examine the ISO C++ standard. Second, try another compiler
801     or an older version of the GNU compilers. Third, you can find more
802     information on the libstdc++ and the GCC mailing lists: search
803     these lists with terms describing your issue.
804     </para> 
805     <para> 
806     Before reporting a bug, please examine the
807     <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/bugs/">bugs database</link>, with the
808     component set to <quote>c++</quote>.
809     </para> 
810   </answer>
811 </qandaentry>
813 </qandadiv>
815 <!-- Known Non-Bugs -->
816 <qandadiv xml:id="faq.known_non-bugs" xreflabel="Known Non-Bugs">
819 <qandaentry xml:id="faq.stream_reopening_fails">
820   <question xml:id="q-stream_reopening_fails">
821     <para>
822       Reopening a stream fails
823     </para>
824   </question>
825   <answer xml:id="a-stream_reopening_fails">
826     <note>
827       <para>This answer is old and probably no longer be relevant.</para>
828     </note>
829     <para>
830     Prior to GCC 4.0 this was one of the most-reported non-bug reports.
831     Executing a sequence like this would fail:
832     </para>
834     <programlisting>
835     #include &lt;fstream&gt;
836     ...
837     std::fstream  fs("a_file");
838     // .
839     // . do things with fs...
840     // .
841     fs.close();
842     fs.open("a_new_file");
843     </programlisting>
844     
845     <para>
846     All operations on the re-opened <varname>fs</varname> would fail, or at
847     least act very strangely, especially if <varname>fs</varname> reached the
848     EOF state on the previous file.
849     The original C++98 standard did not specify behavior in this case, and
850     the <link linkend="manual.bugs.dr22">resolution of DR #22</link> was to
851     leave the state flags unchanged on a successful call to
852     <function>open()</function>.
853     You had to insert a call to <function>fs.clear()</function> between the
854     calls to <function>close()</function> and <function>open()</function>,
855     and then everything will work as expected.
856     <emphasis>Update:</emphasis> For GCC 4.0 we implemented the resolution
857     of <link linkend="manual.bugs.dr409">DR #409</link> and
858     <function>open()</function>
859     now calls <function>clear()</function> on success.
860     </para> 
861   </answer>
862 </qandaentry>
864 <qandaentry xml:id="faq.wefcxx_verbose">
865   <question xml:id="q-wefcxx_verbose">
866     <para>
867       -Weffc++ complains too much
868     </para>
869   </question>
870   <answer xml:id="a-wefcxx_verbose">
871     <para>
872     Many warnings are emitted when <option>-Weffc++</option> is used.  Making
873     libstdc++ <option>-Weffc++</option>-clean is not a goal of the project,
874     for a few reasons.  Mainly, that option tries to enforce
875     object-oriented programming, while the Standard Library isn't
876     necessarily trying to be OO. The option also enforces outdated guidelines
877     from old editions of the books, and the advice isn't all relevant to
878     modern C++ (especially C++11 and later).
879     </para> 
880     <para>
881     We do, however, try to have libstdc++ sources as clean as possible. If
882     you see some simple changes that pacify <option>-Weffc++</option>
883     without other drawbacks, send us a patch.
884     </para>
885   </answer>
886 </qandaentry>
888 <qandaentry xml:id="faq.ambiguous_overloads">
889   <question xml:id="q-ambiguous_overloads">
890     <para>
891       Ambiguous overloads after including an old-style header
892     </para>
893   </question>
894   <answer xml:id="a-ambiguous_overloads">
895     <note>
896       <para>This answer is old and probably no longer be relevant.</para>
897     </note>
898     <para>
899     Another problem is the <literal>rel_ops</literal> namespace and the template
900     comparison operator functions contained therein.  If they become
901     visible in the same namespace as other comparison functions
902     (e.g., <quote>using</quote> them and the
903     <filename class="headerfile">&lt;iterator&gt;</filename> header),
904     then you will suddenly be faced with huge numbers of ambiguity
905     errors.  This was discussed on the mailing list; Nathan Myers
906     <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/libstdc++/2001-01/msg00247.html">sums
907       things up here</link>.  The collisions with vector/string iterator
908     types have been fixed for 3.1.
909     </para> 
910   </answer>
911 </qandaentry>
913 <qandaentry xml:id="faq.v2_headers">
914   <question xml:id="q-v2_headers">
915     <para>
916       The g++-3 headers are <emphasis>not ours</emphasis>
917     </para>
918   </question>
919   <answer xml:id="a-v2_headers">
920     <note>
921       <para>This answer is old and probably no longer be relevant.</para>
922     </note>
923       <para>
924         If you are using headers in
925         <filename class="directory">${prefix}/include/g++-3</filename>, or if
926         the installed library's name looks like
927         <filename class="libraryfile">libstdc++-2.10.a</filename> or
928         <filename class="libraryfile">libstdc++-libc6-2.10.so</filename>, then
929         you are using the old libstdc++-v2 library, which is non-standard and
930         unmaintained.  Do not report problems with -v2 to the -v3
931         mailing list.
932       </para>
933       <para>
934         For GCC versions 3.0 and 3.1 the libstdc++ header files are installed in
935         <filename class="directory">${prefix}/include/g++-v3</filename>
936         (see the 'v'?).  Starting with version 3.2 the headers are installed in
937         <filename class="directory">${prefix}/include/c++/${version}</filename>
938         as this prevents headers from previous versions being found by mistake.
939       </para>
941   </answer>
942 </qandaentry>
944 <qandaentry xml:id="faq.boost_concept_checks">
945   <question xml:id="q-boost_concept_checks">
946     <para>
947       Errors about <emphasis>*Concept</emphasis> and
948       <emphasis>constraints</emphasis> in the STL
949     </para>
950   </question>
951   <answer xml:id="a-boost_concept_checks">
952     <para>
953     If you see compilation errors containing messages about
954     <errortext>foo Concept</errortext> and something to do with a
955     <errortext>constraints</errortext> member function, then most
956     likely you have violated one of the requirements for types used
957     during instantiation of template containers and functions.  For
958     example, EqualityComparableConcept appears if your types must be
959     comparable with == and you have not provided this capability (a
960     typo, or wrong visibility, or you just plain forgot, etc).
961     </para>
962     <para>
963     More information, including how to optionally enable/disable the
964     checks, is available in the
965     <link linkend="std.diagnostics.concept_checking">Diagnostics</link>.
966     chapter of the manual.
967     </para> 
968   </answer>
969 </qandaentry>
971 <qandaentry xml:id="faq.dlopen_crash">
972   <question xml:id="q-dlopen_crash">
973     <para>
974       Program crashes when using library code in a
975       dynamically-loaded library
976     </para>
977   </question>
978   <answer xml:id="a-dlopen_crash">
979     <para>
980     If you are using the C++ library across dynamically-loaded
981     objects, make certain that you are passing the correct options
982     when compiling and linking:
983     </para>
985     <literallayout class="normal">
986     Compile your library components:
987     <command>g++ -fPIC -c a.cc</command>
988     <command>g++ -fPIC -c b.cc</command>
989     ...
990     <command>g++ -fPIC -c z.cc</command>
992     Create your library:
993     <command>g++ -fPIC -shared -rdynamic -o libfoo.so a.o b.o ... z.o</command>
995     Link the executable:
996     <command>g++ -fPIC -rdynamic -o foo ... -L. -lfoo -ldl</command>
997     </literallayout>
998   </answer>
999 </qandaentry>
1001 <qandaentry xml:id="faq.memory_leaks">
1002   <question xml:id="q-memory_leaks">
1003     <para>
1004       <quote>Memory leaks</quote> in containers
1005     </para>
1006   </question>
1007   <answer xml:id="a-memory_leaks">
1008     <note>
1009       <para>This answer is old and probably no longer be relevant.</para>
1010     </note>
1011     <para>
1012     A few people have reported that the standard containers appear
1013     to leak memory when tested with memory checkers such as
1014     <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://valgrind.org/"><command>valgrind</command></link>.
1015     Under some (non-default) configurations the library's allocators keep
1016     free memory in a
1017     pool for later reuse, rather than returning it to the OS.  Although
1018     this memory is always reachable by the library and is never
1019     lost, memory debugging tools can report it as a leak.  If you
1020     want to test the library for memory leaks please read
1021     <link linkend="debug.memory">Tips for memory leak hunting</link>
1022     first.
1023     </para> 
1024   </answer>
1025 </qandaentry>
1027 <qandaentry xml:id="faq.list_size_on">
1028   <question xml:id="q-list_size_on">
1029     <para>
1030       <code>list::size()</code> is O(n)!
1031     </para>
1032   </question>
1033   <answer xml:id="a-list_size_on">
1034     <para>
1035     See
1036     the <link linkend="std.containers">Containers</link>
1037     chapter.
1038     </para> 
1039   </answer>
1040 </qandaentry>
1042 <qandaentry xml:id="faq.easy_to_fix">
1043   <question xml:id="q-easy_to_fix">
1044     <para>
1045       Aw, that's easy to fix!
1046     </para>
1047   </question>
1048   <answer xml:id="a-easy_to_fix">
1049     <para>
1050     If you have found a bug in the library and you think you have
1051     a working fix, then send it in!  The main GCC site has a page
1052     on <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/contribute.html">submitting
1053     patches</link> that covers the procedure, but for libstdc++ you
1054     should also send the patch to our mailing list in addition to
1055     the GCC patches mailing list.  The libstdc++
1056     <link linkend="appendix.contrib">contributors' page</link>
1057     also talks about how to submit patches.
1058     </para>
1059     <para>
1060     In addition to the description, the patch, and the ChangeLog
1061     entry, it is a Good Thing if you can additionally create a small
1062     test program to test for the presence of the bug that your patch
1063     fixes.  Bugs have a way of being reintroduced; if an old bug
1064     creeps back in, it will be caught immediately by the testsuite -
1065     but only if such a test exists.
1066     </para> 
1067   </answer>
1068 </qandaentry>
1070 </qandadiv>
1073 <!-- Miscellaneous -->
1074 <qandadiv xml:id="faq.misc" xreflabel="Miscellaneous">
1077 <qandaentry xml:id="faq.iterator_as_pod">
1078   <question xml:id="faq.iterator_as_pod_q">
1079     <para>
1080       <classname>string::iterator</classname> is not <code>char*</code>;
1081       <classname>vector&lt;T&gt;::iterator</classname> is not <code>T*</code>
1082     </para>
1083   </question>
1084   <answer xml:id="faq.iterator_as_pod_a">
1085     <para>
1086     If you have code that depends on container&lt;T&gt; iterators
1087     being implemented as pointer-to-T, your code is broken. It's
1088     considered a feature, not a bug, that libstdc++ points this out.
1089     </para>
1090     <para>
1091     While there are arguments for iterators to be implemented in
1092     that manner, A) they aren't very good ones in the long term,
1093     and B) they were never guaranteed by the Standard anyway.  The
1094     type-safety achieved by making iterators a real class rather
1095     than a typedef for <type>T*</type> outweighs nearly all opposing
1096     arguments.
1097     </para>
1098     <para>
1099     Code which does assume that a vector/string iterator <varname>i</varname>
1100     is a pointer can often be fixed by changing <varname>i</varname> in
1101     certain expressions to <varname>&amp;*i</varname>.
1102     </para>
1103   </answer>
1104 </qandaentry>
1106 <qandaentry xml:id="faq.what_is_next">
1107   <question xml:id="q-what_is_next">
1108     <para>
1109       What's next after libstdc++?
1110     </para>
1111   </question>
1112   <answer xml:id="a-what_is_next">
1113       <para>
1114         The goal of libstdc++ is to produce a
1115         fully-compliant, fully-portable Standard Library.
1116         While the C++ Standard continues to evolve the libstdc++ will
1117         continue to track it.
1118       </para>
1119   </answer>
1120 </qandaentry>
1122 <qandaentry xml:id="faq.sgi_stl">
1123   <question xml:id="q-sgi_stl">
1124     <para>
1125       What about the STL from SGI?
1126     </para>
1127   </question>
1128   <answer xml:id="a-sgi_stl">
1129     <para>
1130     The STL (Standard Template Library) was the inspiration for large chunks
1131     of the C++ Standard Library, but the terms are not interchangeable and
1132     they don't mean the same thing. The C++ Standard Library includes lots of
1133     things that didn't come from the STL, and some of them aren't even
1134     templates, such as <classname>std::locale</classname> and
1135     <classname>std::thread</classname>.
1136     </para>
1137     <para>
1138     Libstdc++-v3 incorporates a lot of code from
1139     <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://web.archive.org/web/20171225062613/http://www.sgi.com/tech/stl/">the SGI STL</link>
1140     (the final merge was from
1141     <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://web.archive.org/web/20171225062613/http://www.sgi.com/tech/stl/whats_new.html">release 3.3</link>).
1142     The code in libstdc++ contains many fixes and changes compared to the
1143     original SGI code.
1144     </para>
1145     <para>
1146     In particular, <classname>string</classname> is not from SGI and makes no
1147     use of their "rope" class (although that is included as an optional
1148     extension), neither is <classname>valarray</classname> nor some others.
1149     Classes like <classname>vector&lt;&gt;</classname> were from SGI, but have
1150     been extensively modified.
1151     </para>
1152     <para>
1153     More information on the evolution of libstdc++ can be found at the
1154     <link linkend="appendix.porting.api">API
1155     evolution</link>
1156     and <link linkend="manual.appendix.porting.backwards">backwards
1157     compatibility</link> documentation.
1158     </para>
1159     <para>
1160     The <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://web.archive.org/web/20171225062613/http://www.sgi.com/tech/stl/FAQ.html">FAQ</link>
1161     for SGI's STL is still recommended reading.
1162     </para> 
1163   </answer>
1164 </qandaentry>
1166 <qandaentry xml:id="faq.extensions_and_backwards_compat">
1167   <question xml:id="q-extensions_and_backwards_compat">
1168     <para>
1169       Extensions and Backward Compatibility
1170     </para>
1171   </question>
1172   <answer xml:id="a-extensions_and_backwards_compat">
1173     <para>
1174       See the <link linkend="manual.appendix.porting.backwards">link</link> on backwards compatibility and <link linkend="appendix.porting.api">link</link> on evolution.
1175     </para> 
1176   </answer>
1177 </qandaentry>
1179 <qandaentry xml:id="faq.tr1_support">
1180   <question xml:id="q-tr1_support">
1181     <para>
1182       Does libstdc++ support TR1?
1183     </para>
1184   </question>
1185   <answer xml:id="a-tr1_support">
1186     <para>
1187     Yes.
1188     </para>
1189     <para>
1190     The C++ Standard Library
1191     <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">
1192     Technical Report 1</link> added many new features to the library.
1193     </para>
1194     <para>
1195     The implementation status of TR1 in libstdc++ can be tracked
1196     <link linkend="status.iso.tr1">on the TR1 status page</link>.
1197     </para>
1198     <para>
1199     New code should probably not use TR1, because almost everything in it has
1200     been added to the main C++ Standard Library (usually with significant
1201     improvements).
1202     The TR1 implementation in libstdc++ is no longer actively maintained.
1203     </para>
1204   </answer>
1205 </qandaentry>
1207 <qandaentry xml:id="faq.get_iso_cxx">
1208   <question xml:id="q-get_iso_cxx">
1209     <para>How do I get a copy of the ISO C++ Standard?
1210     </para>
1211   </question>
1212   <answer xml:id="a-get_iso_cxx">
1213     <para>
1214     Please refer to the <link linkend="appendix.contrib">Contributing</link>
1215     section in our manual.
1216     </para> 
1217   </answer>
1218 </qandaentry>
1220 <qandaentry xml:id="faq.what_is_abi">
1221   <question xml:id="q-what_is_abi">
1222     <para>
1223       What's an ABI and why is it so messy?
1224     </para>
1225   </question>
1226   <answer xml:id="a-what_is_abi">
1227     <para>
1228     <acronym>ABI</acronym> stands for <quote>Application Binary
1229     Interface</quote>.  Conventionally, it refers to a great
1230     mass of details about how arguments are arranged on the call
1231     stack and/or in registers, and how various types are arranged
1232     and padded in structs.  A single CPU design may suffer
1233     multiple ABIs designed by different development tool vendors
1234     who made different choices, or even by the same vendor for
1235     different target applications or compiler versions.  In ideal
1236     circumstances the CPU designer presents one ABI and all the
1237     OSes and compilers use it.  In practice every ABI omits
1238     details that compiler implementers (consciously or
1239     accidentally) must choose for themselves.
1240     </para>
1241     <para>
1242     That ABI definition suffices for compilers to generate code so a
1243     program can interact safely with an OS and its lowest-level libraries.
1244     Users usually want an ABI to encompass more detail, allowing libraries
1245     built with different compilers (or different releases of the same
1246     compiler!) to be linked together.  For C++, this includes many more
1247     details than for C, and most CPU designers (for good reasons elaborated
1248     below) have not stepped up to publish C++ ABIs.  Such an ABI has been
1249     defined for the Itanium architecture (see
1250     <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://itanium-cxx-abi.github.io/cxx-abi/">C++
1251     ABI for Itanium</link>) and that is used by G++ and other compilers
1252     as the de facto standard ABI on many common architectures (including x86).
1253     G++ can also use the ARM architecture's EABI, for embedded
1254     systems relying only on a <quote>free-standing implementation</quote> that
1255     doesn't include (much of) the standard library, and the GNU EABI for
1256     hosted implementations on ARM.  Those ABIs cover low-level details
1257     such as virtual function implementation, struct inheritance layout,
1258     name mangling, and exception handling.
1259    </para>
1260     <para>
1261     A useful C++ ABI must also incorporate many details of the standard
1262     library implementation.  For a C ABI, the layouts of a few structs
1263     (such as <type>FILE</type>, <type>stat</type>, <type>jmpbuf</type>,
1264     and the like) and a few macros suffice.
1265     For C++, the details include the complete set of names of functions
1266     and types used, the offsets of class members and virtual functions,
1267     and the actual definitions of all inlines.  C++ exposes many more
1268     library details to the caller than C does.  It makes defining
1269     a complete ABI a much bigger undertaking, and requires not just
1270     documenting library implementation details, but carefully designing
1271     those details so that future bug fixes and optimizations don't
1272     force breaking the ABI.
1273     </para>
1274     <para>
1275     There are ways to help isolate library implementation details from the
1276     ABI, but they trade off against speed.  Library details used in inner
1277     loops (e.g., <function>getchar</function>) must be exposed and frozen for
1278     all time, but many others may reasonably be kept hidden from user code,
1279     so they may later be changed.  Deciding which, and implementing
1280     the decisions, must happen before you can reasonably document a
1281     candidate C++ ABI that encompasses the standard library.
1282     </para> 
1283   </answer>
1284 </qandaentry>
1286 <qandaentry xml:id="faq.size_equals_capacity">
1287   <question xml:id="q-size_equals_capacity">
1288     <para>
1289       How do I make <code>std::vector&lt;T&gt;::capacity() == std::vector&lt;T&gt;::size</code>?
1290     </para>
1291   </question>
1292   <answer xml:id="a-size_equals_capacity">
1293     <para>
1294     Since C++11 just call the <function>shrink_to_fit()</function> member
1295     function.
1296     </para>
1297     <para>
1298     Before C++11, the standard idiom for deallocating a
1299     <classname>vector&lt;T&gt;</classname>'s
1300     unused memory was to create a temporary copy of the vector and swap their
1301     contents, e.g. for <classname>vector&lt;T&gt; v</classname>
1302     </para>
1303     <literallayout class="normal">
1304      std::vector&lt;T&gt;(v).swap(v);
1305     </literallayout>
1306     <para>
1307     The copy will take O(n) time and the swap is constant time.
1308     </para>
1309     <para>
1310     See <link linkend="strings.string.shrink">Shrink-to-fit
1311     strings</link> for a similar solution for strings.
1312     </para> 
1313   </answer>
1314 </qandaentry>
1316 </qandadiv>
1319 <!-- FAQ ends here -->
1320 </qandaset>
1322 </article>
1324 </book>