diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 29b1e0f4acd..958482e0213 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,7 @@
+2009-04-15 Benjamin Kosnik
diff --git a/libstdc++-v3/doc/html/faq.html b/libstdc++-v3/doc/html/faq.html index 64674007a6c..74fa9fa54b9 100644 --- a/libstdc++-v3/doc/html/faq.html +++ b/libstdc++-v3/doc/html/faq.html @@ -164,7 +164,7 @@
1.5.
How do I contribute to the effort?
- Here is a page devoted to + Here is a page devoted to this topic. Subscribing to the mailing list (see above, or the homepage) is a very good idea if you have something to contribute, or if you have spare time and want to @@ -204,7 +204,7 @@
2.1.
What are the license terms for libstdc++?
- See our license description + See our license description for these and related questions.
2.2.
So any program which uses libstdc++ falls under the GPL? @@ -243,7 +243,7 @@ the source: please consult your vendor for details.
To build and install from the GNU GCC sources, please consult the - setup + setup documentation for detailed instructions. You may wish to browse those files ahead of time to get a feel for what's required. @@ -320,7 +320,7 @@
If the only functions from libstdc++.a
which you need are language support functions (those listed in
- clause 18 of the
+ clause 18 of the
standard, e.g., new
and
delete
), then try linking against
libsupc++.a
, which is a subset of
@@ -506,9 +506,9 @@
long specializations, and details of thread support.
Long answer: See the implementation status pages for - C++98, - TR1, and - C++0x. + C++98, + TR1, and + C++0x.
5.2.
Bugs in the ISO C++ language or library specification
@@ -579,12 +579,12 @@
reason is that the state flags are not cleared
on a successful call to open(). The standard unfortunately did
not specify behavior in this case, and to everybody's great sorrow,
- the proposed LWG resolution in
+ the proposed LWG resolution in
DR #22 is to leave the flags unchanged. You must insert a call
to fs.clear()
between the calls to close() and open(),
and then everything will work like we all expect it to work.
Update: for GCC 4.0 we implemented the resolution
- of DR #409 and open()
+ of DR #409 and open()
now calls clear()
on success!
6.2.
-Weffc++ complains too much @@ -685,7 +685,7 @@ list::size() is O(n)!
See - the Containers + the Containers chapter.
6.9.
Aw, that's easy to fix! @@ -696,7 +696,7 @@ patches that covers the procedure, but for libstdc++ you should also send the patch to our mailing list in addition to the GCC patches mailing list. The libstdc++ - contributors' page + contributors' page also talks about how to submit patches.
In addition to the description, the patch, and the ChangeLog @@ -789,7 +789,7 @@ Technical Report 1.
- The implementation status of TR1 in libstdc++ can be tracked on the TR1 status + The implementation status of TR1 in libstdc++ can be tracked on the TR1 status page.
7.6.
How do I get a copy of the ISO C++ Standard?
diff --git a/libstdc++-v3/doc/html/manual/abi.html b/libstdc++-v3/doc/html/manual/abi.html index b924bed5d68..9659c189141 100644 --- a/libstdc++-v3/doc/html/manual/abi.html +++ b/libstdc++-v3/doc/html/manual/abi.html @@ -1,6 +1,9 @@ -
+
C++ applications often dependent on specific language support routines, say for throwing exceptions, or catching exceptions, and @@ -461,54 +464,54 @@ gcc test.c -g -O2 -L. -lone -ltwo /usr/lib/libstdc++.so.5 /usr/lib/libstdc++.so. 24660: versioning weak symbols in libstdc++
19664: libstdc++ headers should have pop/push of the visibility around the declarations -
Versioning With Namespaces
.
ISO C++ J16/06-0083
diff --git a/libstdc++-v3/doc/html/manual/algorithms.html b/libstdc++-v3/doc/html/manual/algorithms.html
index 07f9a45b7bb..4ac3c2c1c09 100644
--- a/libstdc++-v3/doc/html/manual/algorithms.html
+++ b/libstdc++-v3/doc/html/manual/algorithms.html
@@ -1,3 +1,9 @@
- Table of Contents Table of Contents
+
A list of user-visible changes, in chronological order
Extensions moved to Table B.1. Extension Allocators Releases after gcc-3.4 have continued to add to the collection
+ Table B.1. Extension Allocators Releases after gcc-3.4 have continued to add to the collection
of available allocators. All of these new allocators are
standard-style. The following table includes details, along with
the first released version of GCC that included the extension allocator.
- Table B.2. Extension Allocators Continued
+ Table B.2. Extension Allocators Continued
Debug mode first appears.
Precompiled header support PCH support.
diff --git a/libstdc++-v3/doc/html/manual/appendix_contributing.html b/libstdc++-v3/doc/html/manual/appendix_contributing.html
index 7268e9bec37..fa350f4b34f 100644
--- a/libstdc++-v3/doc/html/manual/appendix_contributing.html
+++ b/libstdc++-v3/doc/html/manual/appendix_contributing.html
@@ -1,6 +1,12 @@
- Table of Contents
+ Table of Contents
The GNU C++ Library follows an open development model. Active
contributors are assigned maintainer-ship responsibility, and given
write access to the source repository. First time contributors
@@ -36,11 +42,11 @@
Be familiar with the extensions that preceded these
general GNU rules. These style issues for libstdc++ can be
- found here.
+ found here.
And last but certainly not least, read the
library-specific information
- found here.
+ found here.
Small changes can be accepted without a copyright assignment form on
file. New code and additions to the library need completed copyright
@@ -104,4 +110,4 @@
mail message and send it to libstdc++@gcc.gnu.org. All
patches and related discussion should be sent to the
libstdc++ mailing list.
- include/ext
.
@@ -72,11 +75,11 @@ _Alloc_traits have been removed.
__alloc to select an underlying allocator that
satisfied memory allocation requests. The selection of this
underlying allocator was not user-configurable.
- Allocator (3.4) Header (3.4) Allocator (3.[0-3]) Header (3.[0-3]) __gnu_cxx::new_allocator<T>
ext/new_allocator.h
std::__new_alloc
memory
__gnu_cxx::malloc_allocator<T>
ext/malloc_allocator.h
std::__malloc_alloc_template<int>
memory
__gnu_cxx::debug_allocator<T>
ext/debug_allocator.h
std::debug_alloc<T>
memory
__gnu_cxx::__pool_alloc<T>
ext/pool_allocator.h
std::__default_alloc_template<bool,int>
memory
__gnu_cxx::__mt_alloc<T>
ext/mt_allocator.h
__gnu_cxx::bitmap_allocator<T>
ext/bitmap_allocator.h
Allocator (3.4) Header (3.4) Allocator (3.[0-3]) Header (3.[0-3]) __gnu_cxx::new_allocator<T>
ext/new_allocator.h
std::__new_alloc
memory
__gnu_cxx::malloc_allocator<T>
ext/malloc_allocator.h
std::__malloc_alloc_template<int>
memory
__gnu_cxx::debug_allocator<T>
ext/debug_allocator.h
std::debug_alloc<T>
memory
__gnu_cxx::__pool_alloc<T>
ext/pool_allocator.h
std::__default_alloc_template<bool,int>
memory
__gnu_cxx::__mt_alloc<T>
ext/mt_allocator.h
__gnu_cxx::bitmap_allocator<T>
ext/bitmap_allocator.h
Allocator Include Version __gnu_cxx::array_allocator<T>
ext/array_allocator.h
4.0.0 __gnu_cxx::throw_allocator<T>
ext/throw_allocator.h
4.2.0 Allocator Include Version __gnu_cxx::array_allocator<T>
ext/array_allocator.h
4.0.0 __gnu_cxx::throw_allocator<T>
ext/throw_allocator.h
4.2.0
+
The biggest deficiency in free operating systems is not in the software--it is the lack of good free manuals that we can include in these systems. Many of our most important programs do not come with @@ -113,4 +119,6 @@ prefer copylefted manuals to non-copylefted ones. that lists free books available from other publishers].
Copyright © 2004, 2005, 2006, 2007 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Verbatim copying and distribution of this entire article are permitted worldwide, without royalty, in any medium, provided this -notice is preserved.
Report any problems or suggestions to <webmaster@fsf.org>
.
Report any problems or suggestions to <webmaster@fsf.org>
.
+ Copyright (C) 2000, 2001, 2002 Free Software Foundation, + Inc. 51 Franklin St, Fifth Floor, + Boston, MA 02110-1301 USA. Everyone is permitted to copy and + distribute verbatim copies of this license document, but changing it is + not allowed. +
+ The purpose of this License is to make a manual, textbook, or other + functional and useful document "free" in the sense of freedom: to assure + everyone the effective freedom to copy and redistribute it, with or + without modifying it, either commercially or noncommercially. + Secondarily, this License preserves for the author and publisher a way to + get credit for their work, while not being considered responsible for + modifications made by others. +
+ This License is a kind of "copyleft", which means that derivative works of + the document must themselves be free in the same sense. It complements + the GNU General Public License, which is a copyleft license designed for + free software. +
+ We have designed this License in order to use it for manuals for free + software, because free software needs free documentation: a free program + should come with manuals providing the same freedoms that the software + does. But this License is not limited to software manuals; it can be used + for any textual work, regardless of subject matter or whether it is + published as a printed book. We recommend this License principally for + works whose purpose is instruction or reference.
+ This License applies to any manual or other work, in any medium, that + contains a notice placed by the copyright holder saying it can be + distributed under the terms of this License. Such a notice grants a + world-wide, royalty-free license, unlimited in duration, to use that work + under the conditions stated herein. The "Document", below, refers to any + such manual or work. Any member of the public is a licensee, and is + addressed as "you". You accept the license if you copy, modify or + distribute the work in a way requiring permission under copyright + law. +
+ A "Modified Version" of the Document means any work containing the + Document or a portion of it, either copied verbatim, or with modifications + and/or translated into another language. +
+ A "Secondary Section" is a named appendix or a front-matter section of the + Document that deals exclusively with the relationship of the publishers or + authors of the Document to the Document's overall subject (or to related + matters) and contains nothing that could fall directly within that overall + subject. (Thus, if the Document is in part a textbook of mathematics, a + Secondary Section may not explain any mathematics.) The relationship + could be a matter of historical connection with the subject or with + related matters, or of legal, commercial, philosophical, ethical or + political position regarding them. +
+ The "Invariant Sections" are certain Secondary Sections whose titles are + designated, as being those of Invariant Sections, in the notice that says + that the Document is released under this License. If a section does not + fit the above definition of Secondary then it is not allowed to be + designated as Invariant. The Document may contain zero Invariant + Sections. If the Document does not identify any Invariant Sections then + there are none. +
+ The "Cover Texts" are certain short passages of text that are listed, as + Front-Cover Texts or Back-Cover Texts, in the notice that says that the + Document is released under this License. A Front-Cover Text may be at + most 5 words, and a Back-Cover Text may be at most 25 words. +
+ A "Transparent" copy of the Document means a machine-readable copy, + represented in a format whose specification is available to the general + public, that is suitable for revising the document straightforwardly with + generic text editors or (for images composed of pixels) generic paint + programs or (for drawings) some widely available drawing editor, and that + is suitable for input to text formatters or for automatic translation to a + variety of formats suitable for input to text formatters. A copy made in + an otherwise Transparent file format whose markup, or absence of markup, + has been arranged to thwart or discourage subsequent modification by + readers is not Transparent. An image format is not Transparent if used + for any substantial amount of text. A copy that is not "Transparent" is + called "Opaque". +
+ Examples of suitable formats for Transparent copies include plain ASCII + without markup, Texinfo input format, LaTeX input format, SGML or XML + using a publicly available DTD, and standard-conforming simple HTML, + PostScript or PDF designed for human modification. Examples of + transparent image formats include PNG, XCF and JPG. Opaque formats + include proprietary formats that can be read and edited only by + proprietary word processors, SGML or XML for which the DTD and/or + processing tools are not generally available, and the machine-generated + HTML, PostScript or PDF produced by some word processors for output + purposes only. +
+ The "Title Page" means, for a printed book, the title page itself, plus + such following pages as are needed to hold, legibly, the material this + License requires to appear in the title page. For works in formats which + do not have any title page as such, "Title Page" means the text near the + most prominent appearance of the work's title, preceding the beginning of + the body of the text. +
+ A section "Entitled XYZ" means a named subunit of the Document whose title + either is precisely XYZ or contains XYZ in parentheses following text that + translates XYZ in another language. (Here XYZ stands for a specific + section name mentioned below, such as "Acknowledgements", "Dedications", + "Endorsements", or "History".) To "Preserve the Title" of such a section + when you modify the Document means that it remains a section "Entitled + XYZ" according to this definition. +
+ The Document may include Warranty Disclaimers next to the notice which + states that this License applies to the Document. These Warranty + Disclaimers are considered to be included by reference in this License, + but only as regards disclaiming warranties: any other implication that + these Warranty Disclaimers may have is void and has no effect on the + meaning of this License. +
+ You may copy and distribute the Document in any medium, either + commercially or noncommercially, provided that this License, the copyright + notices, and the license notice saying this License applies to the + Document are reproduced in all copies, and that you add no other + conditions whatsoever to those of this License. You may not use technical + measures to obstruct or control the reading or further copying of the + copies you make or distribute. However, you may accept compensation in + exchange for copies. If you distribute a large enough number of copies + you must also follow the conditions in section 3. +
+ You may also lend copies, under the same conditions stated above, and you + may publicly display copies. +
+ If you publish printed copies (or copies in media that commonly have + printed covers) of the Document, numbering more than 100, and the + Document's license notice requires Cover Texts, you must enclose the + copies in covers that carry, clearly and legibly, all these Cover Texts: + Front-Cover Texts on the front cover, and Back-Cover Texts on the back + cover. Both covers must also clearly and legibly identify you as the + publisher of these copies. The front cover must present the full title + with all words of the title equally prominent and visible. You may add + other material on the covers in addition. Copying with changes limited to + the covers, as long as they preserve the title of the Document and satisfy + these conditions, can be treated as verbatim copying in other + respects. +
+ If the required texts for either cover are too voluminous to fit legibly, + you should put the first ones listed (as many as fit reasonably) on the + actual cover, and continue the rest onto adjacent pages. +
+ If you publish or distribute Opaque copies of the Document numbering more + than 100, you must either include a machine-readable Transparent copy + along with each Opaque copy, or state in or with each Opaque copy a + computer-network location from which the general network-using public has + access to download using public-standard network protocols a complete + Transparent copy of the Document, free of added material. If you use the + latter option, you must take reasonably prudent steps, when you begin + distribution of Opaque copies in quantity, to ensure that this Transparent + copy will remain thus accessible at the stated location until at least one + year after the last time you distribute an Opaque copy (directly or + through your agents or retailers) of that edition to the public. +
+ It is requested, but not required, that you contact the authors of the + Document well before redistributing any large number of copies, to give + them a chance to provide you with an updated version of the + Document. +
+ You may copy and distribute a Modified Version of the Document under the + conditions of sections 2 and 3 above, provided that you release the + Modified Version under precisely this License, with the Modified Version + filling the role of the Document, thus licensing distribution and + modification of the Modified Version to whoever possesses a copy of it. + In addition, you must do these things in the Modified Version: +
+ If the Modified Version includes new front-matter sections or appendices + that qualify as Secondary Sections and contain no material copied from the + Document, you may at your option designate some or all of these sections + as invariant. To do this, add their titles to the list of Invariant + Sections in the Modified Version's license notice. These titles must be + distinct from any other section titles. +
+ You may add a section Entitled "Endorsements", provided it contains + nothing but endorsements of your Modified Version by various parties--for + example, statements of peer review or that the text has been approved by + an organization as the authoritative definition of a standard. +
+ You may add a passage of up to five words as a Front-Cover Text, and a + passage of up to 25 words as a Back-Cover Text, to the end of the list of + Cover Texts in the Modified Version. Only one passage of Front-Cover Text + and one of Back-Cover Text may be added by (or through arrangements made + by) any one entity. If the Document already includes a cover text for the + same cover, previously added by you or by arrangement made by the same + entity you are acting on behalf of, you may not add another; but you may + replace the old one, on explicit permission from the previous publisher + that added the old one. +
+ The author(s) and publisher(s) of the Document do not by this License give + permission to use their names for publicity for or to assert or imply + endorsement of any Modified Version. +
+ You may combine the Document with other documents released under this + License, under the terms defined in section 4 above for modified versions, + provided that you include in the combination all of the Invariant Sections + of all of the original documents, unmodified, and list them all as + Invariant Sections of your combined work in its license notice, and that + you preserve all their Warranty Disclaimers. +
+ The combined work need only contain one copy of this License, and multiple + identical Invariant Sections may be replaced with a single copy. If there + are multiple Invariant Sections with the same name but different contents, + make the title of each such section unique by adding at the end of it, in + parentheses, the name of the original author or publisher of that section + if known, or else a unique number. Make the same adjustment to the + section titles in the list of Invariant Sections in the license notice of + the combined work. +
+ In the combination, you must combine any sections Entitled "History" in + the various original documents, forming one section Entitled "History"; + likewise combine any sections Entitled "Acknowledgements", and any + sections Entitled "Dedications". You must delete all sections Entitled + "Endorsements". +
+ You may make a collection consisting of the Document and other documents + released under this License, and replace the individual copies of this + License in the various documents with a single copy that is included in + the collection, provided that you follow the rules of this License for + verbatim copying of each of the documents in all other respects. +
+ You may extract a single document from such a collection, and distribute + it individually under this License, provided you insert a copy of this + License into the extracted document, and follow this License in all other + respects regarding verbatim copying of that document. +
+ A compilation of the Document or its derivatives with other separate and + independent documents or works, in or on a volume of a storage or + distribution medium, is called an "aggregate" if the copyright resulting + from the compilation is not used to limit the legal rights of the + compilation's users beyond what the individual works permit. When the + Document is included in an aggregate, this License does not apply to the + other works in the aggregate which are not themselves derivative works of + the Document. +
+ If the Cover Text requirement of section 3 is applicable to these copies + of the Document, then if the Document is less than one half of the entire + aggregate, the Document's Cover Texts may be placed on covers that bracket + the Document within the aggregate, or the electronic equivalent of covers + if the Document is in electronic form. Otherwise they must appear on + printed covers that bracket the whole aggregate. +
+ Translation is considered a kind of modification, so you may distribute + translations of the Document under the terms of section 4. Replacing + Invariant Sections with translations requires special permission from + their copyright holders, but you may include translations of some or all + Invariant Sections in addition to the original versions of these Invariant + Sections. You may include a translation of this License, and all the + license notices in the Document, and any Warranty Disclaimers, provided + that you also include the original English version of this License and the + original versions of those notices and disclaimers. In case of a + disagreement between the translation and the original version of this + License or a notice or disclaimer, the original version will prevail. +
+ If a section in the Document is Entitled "Acknowledgements", + "Dedications", or "History", the requirement (section 4) to Preserve its + Title (section 1) will typically require changing the actual title. +
+ You may not copy, modify, sublicense, or distribute the Document except as + expressly provided for under this License. Any other attempt to copy, + modify, sublicense or distribute the Document is void, and will + automatically terminate your rights under this License. However, parties + who have received copies, or rights, from you under this License will not + have their licenses terminated so long as such parties remain in full + compliance. +
+ The Free Software Foundation may publish new, revised versions of the GNU + Free Documentation License from time to time. Such new versions will be + similar in spirit to the present version, but may differ in detail to + address new problems or concerns. See http://www.gnu.org/copyleft/. +
+ Each version of the License is given a distinguishing version number. If + the Document specifies that a particular numbered version of this License + "or any later version" applies to it, you have the option of following the + terms and conditions either of that specified version or of any later + version that has been published (not as a draft) by the Free Software + Foundation. If the Document does not specify a version number of this + License, you may choose any version ever published (not as a draft) by the + Free Software Foundation. +
+ To use this License in a document you have written, include a copy of the + License in the document and put the following copyright and license + notices just after the title page: +
+ Copyright (C) YEAR YOUR NAME. +
+ Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.2 or + any later version published by the Free Software Foundation; with no + Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A + copy of the license is included in the section entitled "GNU Free + Documentation License". +
+ If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, + replace the "with...Texts." line with this: +
+ with the Invariant Sections being LIST THEIR TITLES, with the + Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. +
+ If you have Invariant Sections without Cover Texts, or some other + combination of the three, merge those two alternatives to suit the + situation. +
+ If your document contains nontrivial examples of program code, we + recommend releasing these examples in parallel under your choice of free + software license, such as the GNU General Public License, to permit their + use in free software. +
+ Version 3, 29 June 2007 +
+ Copyright © 2007 Free Software Foundation, Inc. + http://fsf.org/ +
+ Everyone is permitted to copy and distribute verbatim copies of this license + document, but changing it is not allowed. +
+ The GNU General Public License is a free, copyleft + license for software and other kinds of works. +
+ The licenses for most software and other practical works are designed to + take away your freedom to share and change the works. By contrast, the + GNU General Public License is intended to guarantee your + freedom to share and change all versions of a program—to make sure it + remains free software for all its users. We, the Free Software Foundation, + use the GNU General Public License for most of our + software; it applies also to any other work released this way by its + authors. You can apply it to your programs, too. +
+ When we speak of free software, we are referring to freedom, not price. Our + General Public Licenses are designed to make sure that you have the freedom + to distribute copies of free software (and charge for them if you wish), + that you receive source code or can get it if you want it, that you can + change the software or use pieces of it in new free programs, and that you + know you can do these things. +
+ To protect your rights, we need to prevent others from denying you these + rights or asking you to surrender the rights. Therefore, you have certain + responsibilities if you distribute copies of the software, or if you modify + it: responsibilities to respect the freedom of others. +
+ For example, if you distribute copies of such a program, whether gratis or + for a fee, you must pass on to the recipients the same freedoms that you + received. You must make sure that they, too, receive or can get the source + code. And you must show them these terms so they know their rights. +
+ Developers that use the GNU GPL + protect your rights with two steps: (1) assert copyright on the software, + and (2) offer you this License giving you legal permission to copy, + distribute and/or modify it. +
+ For the developers’ and authors’ protection, the + GPL clearly explains that there is no warranty for this + free software. For both users’ and authors’ sake, the + GPL requires that modified versions be marked as changed, + so that their problems will not be attributed erroneously to authors of + previous versions. +
+ Some devices are designed to deny users access to install or run modified + versions of the software inside them, although the manufacturer can do so. + This is fundamentally incompatible with the aim of protecting users’ + freedom to change the software. The systematic pattern of such abuse occurs + in the area of products for individuals to use, which is precisely where it + is most unacceptable. Therefore, we have designed this version of the + GPL to prohibit the practice for those products. If such + problems arise substantially in other domains, we stand ready to extend this + provision to those domains in future versions of the GPL, + as needed to protect the freedom of users. +
+ Finally, every program is threatened constantly by software patents. States + should not allow patents to restrict development and use of software on + general-purpose computers, but in those that do, we wish to avoid the + special danger that patents applied to a free program could make it + effectively proprietary. To prevent this, the GPL + assures that patents cannot be used to render the program non-free. +
+ The precise terms and conditions for copying, distribution and modification + follow. +
+ “This License” refers to version 3 of the GNU + General Public License. +
+ “Copyright” also means copyright-like laws that apply to other + kinds of works, such as semiconductor masks. +
+ “The Program” refers to any copyrightable work licensed under + this License. Each licensee is addressed as “you”. + “Licensees” and “recipients” may be individuals or + organizations. +
+ To “modify” a work means to copy from or adapt all or part of + the work in a fashion requiring copyright permission, other than the making + of an exact copy. The resulting work is called a “modified + version” of the earlier work or a work “based on” the + earlier work. +
+ A “covered work” means either the unmodified Program or a work + based on the Program. +
+ To “propagate” a work means to do anything with it that, without + permission, would make you directly or secondarily liable for infringement + under applicable copyright law, except executing it on a computer or + modifying a private copy. Propagation includes copying, distribution (with + or without modification), making available to the public, and in some + countries other activities as well. +
+ To “convey” a work means any kind of propagation that enables + other parties to make or receive copies. Mere interaction with a user + through a computer network, with no transfer of a copy, is not conveying. +
+ An interactive user interface displays “Appropriate Legal + Notices” to the extent that it includes a convenient and prominently + visible feature that (1) displays an appropriate copyright notice, and (2) + tells the user that there is no warranty for the work (except to the extent + that warranties are provided), that licensees may convey the work under this + License, and how to view a copy of this License. If the interface presents + a list of user commands or options, such as a menu, a prominent item in the + list meets this criterion. +
+ The “source code” for a work means the preferred form of the + work for making modifications to it. “Object code” means any + non-source form of a work. +
+ A “Standard Interface” means an interface that either is an + official standard defined by a recognized standards body, or, in the case of + interfaces specified for a particular programming language, one that is + widely used among developers working in that language. +
+ The “System Libraries” of an executable work include anything, + other than the work as a whole, that (a) is included in the normal form of + packaging a Major Component, but which is not part of that Major Component, + and (b) serves only to enable use of the work with that Major Component, or + to implement a Standard Interface for which an implementation is available + to the public in source code form. A “Major Component”, in this + context, means a major essential component (kernel, window system, and so + on) of the specific operating system (if any) on which the executable work + runs, or a compiler used to produce the work, or an object code interpreter + used to run it. +
+ The “Corresponding Source” for a work in object code form means + all the source code needed to generate, install, and (for an executable + work) run the object code and to modify the work, including scripts to + control those activities. However, it does not include the work’s + System Libraries, or general-purpose tools or generally available free + programs which are used unmodified in performing those activities but which + are not part of the work. For example, Corresponding Source includes + interface definition files associated with source files for the work, and + the source code for shared libraries and dynamically linked subprograms that + the work is specifically designed to require, such as by intimate data + communication or control flow between those subprograms and other parts of + the work. +
+ The Corresponding Source need not include anything that users can regenerate + automatically from other parts of the Corresponding Source. +
+ The Corresponding Source for a work in source code form is that same work. +
+ All rights granted under this License are granted for the term of copyright + on the Program, and are irrevocable provided the stated conditions are met. + This License explicitly affirms your unlimited permission to run the + unmodified Program. The output from running a covered work is covered by + this License only if the output, given its content, constitutes a covered + work. This License acknowledges your rights of fair use or other + equivalent, as provided by copyright law. +
+ You may make, run and propagate covered works that you do not convey, + without conditions so long as your license otherwise remains in force. You + may convey covered works to others for the sole purpose of having them make + modifications exclusively for you, or provide you with facilities for + running those works, provided that you comply with the terms of this License + in conveying all material for which you do not control copyright. Those + thus making or running the covered works for you must do so exclusively on + your behalf, under your direction and control, on terms that prohibit them + from making any copies of your copyrighted material outside their + relationship with you. +
+ Conveying under any other circumstances is permitted solely under the + conditions stated below. Sublicensing is not allowed; section 10 makes it + unnecessary. +
+ No covered work shall be deemed part of an effective technological measure + under any applicable law fulfilling obligations under article 11 of the WIPO + copyright treaty adopted on 20 December 1996, or similar laws prohibiting or + restricting circumvention of such measures. +
+ When you convey a covered work, you waive any legal power to forbid + circumvention of technological measures to the extent such circumvention is + effected by exercising rights under this License with respect to the covered + work, and you disclaim any intention to limit operation or modification of + the work as a means of enforcing, against the work’s users, your or + third parties’ legal rights to forbid circumvention of technological + measures. +
+ You may convey verbatim copies of the Program’s source code as you + receive it, in any medium, provided that you conspicuously and appropriately + publish on each copy an appropriate copyright notice; keep intact all + notices stating that this License and any non-permissive terms added in + accord with section 7 apply to the code; keep intact all notices of the + absence of any warranty; and give all recipients a copy of this License + along with the Program. +
+ You may charge any price or no price for each copy that you convey, and you + may offer support or warranty protection for a fee. +
+ You may convey a work based on the Program, or the modifications to produce + it from the Program, in the form of source code under the terms of section + 4, provided that you also meet all of these conditions: +
+ The work must carry prominent notices stating that you modified it, and + giving a relevant date. +
+ The work must carry prominent notices stating that it is released under + this License and any conditions added under section 7. This requirement + modifies the requirement in section 4 to “keep intact all + notices”. +
+ You must license the entire work, as a whole, under this License to + anyone who comes into possession of a copy. This License will therefore + apply, along with any applicable section 7 additional terms, to the + whole of the work, and all its parts, regardless of how they are + packaged. This License gives no permission to license the work in any + other way, but it does not invalidate such permission if you have + separately received it. +
+ If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your work need + not make them do so. +
+ A compilation of a covered work with other separate and independent works, + which are not by their nature extensions of the covered work, and which are + not combined with it such as to form a larger program, in or on a volume of + a storage or distribution medium, is called an “aggregate” if + the compilation and its resulting copyright are not used to limit the access + or legal rights of the compilation’s users beyond what the individual works + permit. Inclusion of a covered work in an aggregate does not cause + this License to apply to the other parts of the aggregate. +
+ You may convey a covered work in object code form under the terms of + sections 4 and 5, provided that you also convey the machine-readable + Corresponding Source under the terms of this License, in one of these ways: +
+ Convey the object code in, or embodied in, a physical product (including + a physical distribution medium), accompanied by the Corresponding Source + fixed on a durable physical medium customarily used for software + interchange. +
+ Convey the object code in, or embodied in, a physical product (including + a physical distribution medium), accompanied by a written offer, valid + for at least three years and valid for as long as you offer spare parts + or customer support for that product model, to give anyone who possesses + the object code either (1) a copy of the Corresponding Source for all + the software in the product that is covered by this License, on a + durable physical medium customarily used for software interchange, for a + price no more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the Corresponding Source from + a network server at no charge. +
+ Convey individual copies of the object code with a copy of the written + offer to provide the Corresponding Source. This alternative is allowed + only occasionally and noncommercially, and only if you received the + object code with such an offer, in accord with subsection 6b. +
+ Convey the object code by offering access from a designated place + (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to copy + the object code is a network server, the Corresponding Source may be on + a different server (operated by you or a third party) that supports + equivalent copying facilities, provided you maintain clear directions + next to the object code saying where to find the Corresponding Source. + Regardless of what server hosts the Corresponding Source, you remain + obligated to ensure that it is available for as long as needed to + satisfy these requirements. +
+ Convey the object code using peer-to-peer transmission, provided you + inform other peers where the object code and Corresponding Source of the + work are being offered to the general public at no charge under + subsection 6d. +
+ A separable portion of the object code, whose source code is excluded from + the Corresponding Source as a System Library, need not be included in + conveying the object code work. +
+ A “User Product” is either (1) a “consumer product”, + which means any tangible personal property which is normally used for + personal, family, or household purposes, or (2) anything designed or sold + for incorporation into a dwelling. In determining whether a product is a + consumer product, doubtful cases shall be resolved in favor of coverage. + For a particular product received by a particular user, “normally + used” refers to a typical or common use of that class of product, + regardless of the status of the particular user or of the way in which the + particular user actually uses, or expects or is expected to use, the + product. A product is a consumer product regardless of whether the product + has substantial commercial, industrial or non-consumer uses, unless such + uses represent the only significant mode of use of the product. +
+ “Installation Information” for a User Product means any methods, + procedures, authorization keys, or other information required to install and + execute modified versions of a covered work in that User Product from a + modified version of its Corresponding Source. The information must suffice + to ensure that the continued functioning of the modified object code is in + no case prevented or interfered with solely because modification has been + made. +
+ If you convey an object code work under this section in, or with, or + specifically for use in, a User Product, and the conveying occurs as part of + a transaction in which the right of possession and use of the User Product + is transferred to the recipient in perpetuity or for a fixed term + (regardless of how the transaction is characterized), the Corresponding + Source conveyed under this section must be accompanied by the Installation + Information. But this requirement does not apply if neither you nor any + third party retains the ability to install modified object code on the User + Product (for example, the work has been installed in + ROM). +
+ The requirement to provide Installation Information does not include a + requirement to continue to provide support service, warranty, or updates for + a work that has been modified or installed by the recipient, or for the User + Product in which it has been modified or installed. Access to a network may + be denied when the modification itself materially and adversely affects the + operation of the network or violates the rules and protocols for + communication across the network. +
+ Corresponding Source conveyed, and Installation Information provided, in + accord with this section must be in a format that is publicly documented + (and with an implementation available to the public in source code form), + and must require no special password or key for unpacking, reading or + copying. +
+ “Additional permissions” are terms that supplement the terms of + this License by making exceptions from one or more of its conditions. + Additional permissions that are applicable to the entire Program shall be + treated as though they were included in this License, to the extent that + they are valid under applicable law. If additional permissions apply only + to part of the Program, that part may be used separately under those + permissions, but the entire Program remains governed by this License + without regard to the additional permissions. +
+ When you convey a copy of a covered work, you may at your option remove any + additional permissions from that copy, or from any part of it. (Additional + permissions may be written to require their own removal in certain cases + when you modify the work.) You may place additional permissions on + material, added by you to a covered work, for which you have or can give + appropriate copyright permission. +
+ Notwithstanding any other provision of this License, for material you add + to a covered work, you may (if authorized by the copyright holders of that + material) supplement the terms of this License with terms: +
+ Disclaiming warranty or limiting liability differently from the terms + of sections 15 and 16 of this License; or +
+ Requiring preservation of specified reasonable legal notices or author + attributions in that material or in the Appropriate Legal Notices + displayed by works containing it; or +
+ Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or +
+ Limiting the use for publicity purposes of names of licensors or + authors of the material; or +
+ Declining to grant rights under trademark law for use of some trade + names, trademarks, or service marks; or +
+ Requiring indemnification of licensors and authors of that material by + anyone who conveys the material (or modified versions of it) with + contractual assumptions of liability to the recipient, for any + liability that these contractual assumptions directly impose on those + licensors and authors. +
+ All other non-permissive additional terms are considered “further + restrictions” within the meaning of section 10. If the Program as + you received it, or any part of it, contains a notice stating that it is + governed by this License along with a term that is a further restriction, + you may remove that term. If a license document contains a further + restriction but permits relicensing or conveying under this License, you + may add to a covered work material governed by the terms of that license + document, provided that the further restriction does not survive such + relicensing or conveying. +
+ If you add terms to a covered work in accord with this section, you must + place, in the relevant source files, a statement of the additional terms + that apply to those files, or a notice indicating where to find the + applicable terms. +
+ Additional terms, permissive or non-permissive, may be stated in the form + of a separately written license, or stated as exceptions; the above + requirements apply either way. +
+ You may not propagate or modify a covered work except as expressly provided + under this License. Any attempt otherwise to propagate or modify it is + void, and will automatically terminate your rights under this License + (including any patent licenses granted under the third paragraph of section + 11). +
+ However, if you cease all violation of this License, then your license from + a particular copyright holder is reinstated (a) provisionally, unless and + until the copyright holder explicitly and finally terminates your license, + and (b) permanently, if the copyright holder fails to notify you of the + violation by some reasonable means prior to 60 days after the cessation. +
+ Moreover, your license from a particular copyright holder is reinstated + permanently if the copyright holder notifies you of the violation by some + reasonable means, this is the first time you have received notice of + violation of this License (for any work) from that copyright holder, and + you cure the violation prior to 30 days after your receipt of the notice. +
+ Termination of your rights under this section does not terminate the + licenses of parties who have received copies or rights from you under this + License. If your rights have been terminated and not permanently + reinstated, you do not qualify to receive new licenses for the same + material under section 10. +
+ You are not required to accept this License in order to receive or run a + copy of the Program. Ancillary propagation of a covered work occurring + solely as a consequence of using peer-to-peer transmission to receive a + copy likewise does not require acceptance. However, nothing other than + this License grants you permission to propagate or modify any covered work. + These actions infringe copyright if you do not accept this License. + Therefore, by modifying or propagating a covered work, you indicate your + acceptance of this License to do so. +
+ Each time you convey a covered work, the recipient automatically receives a + license from the original licensors, to run, modify and propagate that + work, subject to this License. You are not responsible for enforcing + compliance by third parties with this License. +
+ An “entity transaction” is a transaction transferring control + of an organization, or substantially all assets of one, or subdividing an + organization, or merging organizations. If propagation of a covered work + results from an entity transaction, each party to that transaction who + receives a copy of the work also receives whatever licenses to the work the + party’s predecessor in interest had or could give under the previous + paragraph, plus a right to possession of the Corresponding Source of the + work from the predecessor in interest, if the predecessor has it or can get + it with reasonable efforts. +
+ You may not impose any further restrictions on the exercise of the rights + granted or affirmed under this License. For example, you may not impose a + license fee, royalty, or other charge for exercise of rights granted under + this License, and you may not initiate litigation (including a cross-claim + or counterclaim in a lawsuit) alleging that any patent claim is infringed + by making, using, selling, offering for sale, or importing the Program or + any portion of it. +
+ A “contributor” is a copyright holder who authorizes use under + this License of the Program or a work on which the Program is based. The + work thus licensed is called the contributor’s “contributor + version”. +
+ A contributor’s “essential patent claims” are all patent + claims owned or controlled by the contributor, whether already acquired or + hereafter acquired, that would be infringed by some manner, permitted by + this License, of making, using, or selling its contributor version, but do + not include claims that would be infringed only as a consequence of further + modification of the contributor version. For purposes of this definition, + “control” includes the right to grant patent sublicenses in a + manner consistent with the requirements of this License. +
+ Each contributor grants you a non-exclusive, worldwide, royalty-free patent + license under the contributor’s essential patent claims, to make, use, + sell, offer for sale, import and otherwise run, modify and propagate the + contents of its contributor version. +
+ In the following three paragraphs, a “patent license” is any + express agreement or commitment, however denominated, not to enforce a + patent (such as an express permission to practice a patent or covenant not + to sue for patent infringement). To “grant” such a patent + license to a party means to make such an agreement or commitment not to + enforce a patent against the party. +
+ If you convey a covered work, knowingly relying on a patent license, and the + Corresponding Source of the work is not available for anyone to copy, free + of charge and under the terms of this License, through a publicly available + network server or other readily accessible means, then you must either (1) + cause the Corresponding Source to be so available, or (2) arrange to deprive + yourself of the benefit of the patent license for this particular work, or + (3) arrange, in a manner consistent with the requirements of this License, + to extend the patent license to downstream recipients. “Knowingly + relying” means you have actual knowledge that, but for the patent + license, your conveying the covered work in a country, or your + recipient’s use of the covered work in a country, would infringe one + or more identifiable patents in that country that you have reason to believe + are valid. +
+ If, pursuant to or in connection with a single transaction or arrangement, + you convey, or propagate by procuring conveyance of, a covered work, and + grant a patent license to some of the parties receiving the covered work + authorizing them to use, propagate, modify or convey a specific copy of the + covered work, then the patent license you grant is automatically extended to + all recipients of the covered work and works based on it. +
+ A patent license is “discriminatory” if it does not include + within the scope of its coverage, prohibits the exercise of, or is + conditioned on the non-exercise of one or more of the rights that are + specifically granted under this License. You may not convey a covered work + if you are a party to an arrangement with a third party that is in the + business of distributing software, under which you make payment to the third + party based on the extent of your activity of conveying the work, and under + which the third party grants, to any of the parties who would receive the + covered work from you, a discriminatory patent license (a) in connection + with copies of the covered work conveyed by you (or copies made from those + copies), or (b) primarily for and in connection with specific products or + compilations that contain the covered work, unless you entered into that + arrangement, or that patent license was granted, prior to 28 March 2007. +
+ Nothing in this License shall be construed as excluding or limiting any + implied license or other defenses to infringement that may otherwise be + available to you under applicable patent law. +
+ If conditions are imposed on you (whether by court order, agreement or + otherwise) that contradict the conditions of this License, they do not + excuse you from the conditions of this License. If you cannot convey a + covered work so as to satisfy simultaneously your obligations under this + License and any other pertinent obligations, then as a consequence you may + not convey it at all. For example, if you agree to terms that obligate you + to collect a royalty for further conveying from those to whom you convey the + Program, the only way you could satisfy both those terms and this License + would be to refrain entirely from conveying the Program. +
+ Notwithstanding any other provision of this License, you have permission to + link or combine any covered work with a work licensed under version 3 of the + GNU Affero General Public License into a single combined + work, and to convey the resulting work. The terms of this License will + continue to apply to the part which is the covered work, but the special + requirements of the GNU Affero General Public License, + section 13, concerning interaction through a network will apply to the + combination as such. +
+ The Free Software Foundation may publish revised and/or new versions of the + GNU General Public License from time to time. Such new + versions will be similar in spirit to the present version, but may differ in + detail to address new problems or concerns. +
+ Each version is given a distinguishing version number. If the Program + specifies that a certain numbered version of the GNU + General Public License “or any later version” applies to it, you + have the option of following the terms and conditions either of that + numbered version or of any later version published by the Free Software + Foundation. If the Program does not specify a version number of the + GNU General Public License, you may choose any version + ever published by the Free Software Foundation. +
+ If the Program specifies that a proxy can decide which future versions of + the GNU General Public License can be used, that + proxy’s public statement of acceptance of a version permanently + authorizes you to choose that version for the Program. +
+ Later license versions may give you additional or different permissions. + However, no additional obligations are imposed on any author or copyright + holder as a result of your choosing to follow a later version. +
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE + LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR + OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF + ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH + YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL + NECESSARY SERVICING, REPAIR OR CORRECTION. +
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL + ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE + PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY + GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE + OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA + OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD + PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), + EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF + SUCH DAMAGES. +
+ If the disclaimer of warranty and limitation of liability provided above + cannot be given local legal effect according to their terms, reviewing + courts shall apply local law that most closely approximates an absolute + waiver of all civil liability in connection with the Program, unless a + warranty or assumption of liability accompanies a copy of the Program in + return for a fee. +
+ If you develop a new program, and you want it to be of the greatest possible + use to the public, the best way to achieve this is to make it free software + which everyone can redistribute and change under these terms. +
+ To do so, attach the following notices to the program. It is safest to + attach them to the start of each source file to most effectively state the + exclusion of warranty; and each file should have at least the + “copyright” line and a pointer to where the full notice is + found. +
+one line to give the program’s name and a brief idea of what it does.
+Copyright (C)year
name of author
+ +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see http://www.gnu.org/licenses/. +
+ Also add information on how to contact you by electronic and paper mail. +
+ If the program does terminal interaction, make it output a short notice like + this when it starts in an interactive mode: +
+program
Copyright (C)year
name of author
+This program comes with ABSOLUTELY NO WARRANTY; for details type ‘show w
’. +This is free software, and you are welcome to redistribute it +under certain conditions; type ‘show c
’ for details. +
+ The hypothetical commands ‘show w
’ and
+ ‘show c
’ should show the appropriate parts of
+ the General Public License. Of course, your program’s commands might be
+ different; for a GUI interface, you would use an “about box”.
+
+ You should also get your employer (if you work as a programmer) or school, + if any, to sign a “copyright disclaimer” for the program, if + necessary. For more information on this, and how to apply and follow the + GNU GPL, see + http://www.gnu.org/licenses/. +
+ The GNU General Public License does not permit + incorporating your program into proprietary programs. If your program is a + subroutine library, you may consider it more useful to permit linking + proprietary applications with the library. If this is what you want to do, + use the GNU Lesser General Public License instead of this + License. But first, please read http://www.gnu.org/philosophy/why-not-lgpl.html. +
Table of Contents
+
Table of Contents
As noted previously,
certain other tools are necessary for hacking on files that
control configure (configure.ac
,
@@ -221,4 +227,4 @@
argument checking at all is done in this signature. See
GLIBCXX_ENABLE_CXX_FLAGS for an example of handling, and an error
message.
-
Table of Contents
+ Section [23.1.2], Table 69, of the C++ standard lists this + function for all of the associative containers (map, set, etc): +
+ a.insert(p,t); +
+ where 'p' is an iterator into the container 'a', and 't' is the
+ item to insert. The standard says that “t
is
+ inserted as close as possible to the position just prior to
+ p
.” (Library DR #233 addresses this topic,
+ referring to N1780.
+ Since version 4.2 GCC implements the resolution to DR 233, so
+ that insertions happen as close as possible to the hint. For
+ earlier releases the hint was only used as described below.
+
+ Here we'll describe how the hinting works in the libstdc++ + implementation, and what you need to do in order to take + advantage of it. (Insertions can change from logarithmic + complexity to amortized constant time, if the hint is properly + used.) Also, since the current implementation is based on the + SGI STL one, these points may hold true for other library + implementations also, since the HP/SGI code is used in a lot of + places. +
+ In the following text, the phrases greater + than and less than refer to the + results of the strict weak ordering imposed on the container by + its comparison object, which defaults to (basically) + “<”. Using those phrases is semantically sloppy, + but I didn't want to get bogged down in syntax. I assume that if + you are intelligent enough to use your own comparison objects, + you are also intelligent enough to assign “greater” + and “lesser” their new meanings in the next + paragraph. *grin* +
+ If the hint
parameter ('p' above) is equivalent to:
+
+ begin()
, then the item being inserted should
+ have a key less than all the other keys in the container.
+ The item will be inserted at the beginning of the container,
+ becoming the new entry at begin()
.
+
+ end()
, then the item being inserted should have
+ a key greater than all the other keys in the container. The
+ item will be inserted at the end of the container, becoming
+ the new entry at end()
.
+
+ neither begin()
nor end()
, then:
+ Let h
be the entry in the container pointed to
+ by hint
, that is, h = *hint
. Then
+ the item being inserted should have a key less than that of
+ h
, and greater than that of the item preceding
+ h
. The new item will be inserted between
+ h
and h
's predecessor.
+
+ For multimap
and multiset
, the
+ restrictions are slightly looser: “greater than”
+ should be replaced by “not less than”and “less
+ than” should be replaced by “not greater
+ than.” (Why not replace greater with
+ greater-than-or-equal-to? You probably could in your head, but
+ the mathematicians will tell you that it isn't the same thing.)
+
+ If the conditions are not met, then the hint is not used, and the
+ insertion proceeds as if you had called a.insert(t)
+
instead. (Note that GCC releases
+ prior to 3.0.2 had a bug in the case with hint ==
+ begin()
for the map
and set
+ classes. You should not use a hint argument in those releases.)
+
+ This behavior goes well with other containers'
+ insert()
functions which take an iterator: if used,
+ the new item will be inserted before the iterator passed as an
+ argument, same as the other containers.
+
+ Note also that the hint in this + implementation is a one-shot. The older insertion-with-hint + routines check the immediately surrounding entries to ensure that + the new item would in fact belong there. If the hint does not + point to the correct place, then no further local searching is + done; the search begins from scratch in logarithmic time. +
Explaining all of the fun and delicious things that can +
The first generation GNU C++ library was called libg++. It was a +
The first generation GNU C++ library was called libg++. It was a separate GNU project, although reliably paired with GCC. Rumors imply that it had a working relationship with at least two kinds of dinosaur. @@ -14,8 +17,8 @@ ISO Standard (e.g., statistical analysis). While there are a lot of really useful things that are used by a lot of people, the Standards Committee couldn't include everything, and so a lot of those “obvious” classes didn't get included. -
Known Issues include many of the limitations of its immediate ancestor.
Portability notes and known implementation limitations are as follows.
At least some older implementations don't have std::ios_base
, so you should use std::ios::badbit
, std::ios::failbit
and std::ios::eofbit
and std::ios::goodbit
.
-
+
Known Issues include many of the limitations of its immediate ancestor.
Portability notes and known implementation limitations are as follows.
At least some older implementations don't have std::ios_base
, so you should use std::ios::badbit
, std::ios::failbit
and std::ios::eofbit
and std::ios::goodbit
.
+
In earlier versions of the standard,
fstream.h
,
ostream.h
@@ -41,7 +44,7 @@ considered replaced and rewritten.
archived. The code is considered replaced and rewritten.
Portability notes and known implementation limitations are as follows. -
+
Some care is required to support C++ compiler and or library
implementation that do not have the standard library in
namespace std
.
@@ -105,7 +108,7 @@ AC_DEFUN([AC_CXX_NAMESPACE_STD], [
AC_DEFINE(HAVE_NAMESPACE_STD,,[Define if g++ supports namespace std. ])
fi
])
-
The following illustrate implementation-allowed illegal iterator use, and then correct use.
@@ -118,7 +121,7 @@ AC_DEFUN([AC_CXX_NAMESPACE_STD], [
if (iterator)
won't work any more => use
if (iterator != iterator_type())
-
Glibc 2.0.x and 2.1.x define ctype.h
functionality as macros
(isspace, isalpha etc.).
@@ -151,7 +154,7 @@ std:: (__ctype_b[(int) ( ( 'X' ) )] & (unsigned short int) _ISspace ) ;
(ctype.h
) and the
definitions in namespace std::
(<cctype>
).
-
One solution is to add an autoconf-test for this:
AC_MSG_CHECKING(for container::at) @@ -177,7 +180,7 @@ AC_DEFINE(HAVE_CONTAINER_AT)],
If you are using other (non-GNU) compilers it might be a good idea
to check for string::at
separately.
-
Use some kind of autoconf test, plus this:
#ifdef HAVE_CHAR_TRAITS @@ -185,7 +188,7 @@ AC_DEFINE(HAVE_CONTAINER_AT)], #else #define CPP_EOF EOF #endif -
There are two functions for deleting the contents of a string:
clear
and erase
(the latter returns the
string).
@@ -203,12 +206,12 @@ erase(size_type __pos = 0, size_type __n = npos)
Unfortunately, clear
is not implemented in this
version, so you should use erase
(which is probably
faster than operator=(charT*)
).
-
These are no longer supported. Please use stringstreams instead. -
Although the ISO standard i/ostringstream
-classes are
provided, (sstream
), for
compatibility with older implementations the pre-ISO
@@ -296,14 +299,14 @@ any = temp;
Another example of using stringstreams is in this howto.
There is additional information in the libstdc++-v2 info files, in particular “info iostream”. -
Earlier GCC releases had a somewhat different approach to threading configuration and proper compilation. Before GCC 3.0, configuration of the threading model was dictated by compiler @@ -361,7 +364,7 @@ libstdc++-v3. of the SGI STL (version 3.3), with extensive changes.
A more formal description of the V3 goals can be found in the official design document. -
Portability notes and known implementation limitations are as follows.
The pre-ISO C++ headers +
Portability notes and known implementation limitations are as follows.
The pre-ISO C++ headers
(iostream.h
, defalloc.h
etc.) are
available, unlike previous libstdc++ versions, but inclusion
generates a warning that you are using deprecated headers.
@@ -433,7 +436,7 @@ like vector.h
can be replaced with using namespace std;
can be put at the global
scope. This should be enough to get this code compiling, assuming the
other usage is correct.
-
At this time most of the features of the SGI STL extension have been +
At this time most of the features of the SGI STL extension have been replaced by standardized libraries. In particular, the unordered_map and unordered_set containers of TR1 are suitable replacement for the non-standard hash_map and hash_set @@ -505,7 +508,7 @@ AC_DEFUN([AC_HEADER_EXT_HASH_SET], [ AC_DEFINE(HAVE_EXT_HASH_SET,,[Define if ext/hash_set is present. ]) fi ]) -
The existence of ios::nocreate
being used for
input-streams has been confirmed, most probably because the author
thought it would be more correct to specify nocreate explicitly. So
@@ -516,7 +519,7 @@ open the file for reading, check if it has been opened, and then
decide whether you want to create/replace or not. To my knowledge,
even older implementations support app
, ate
and trunc
(except for app
?).
-
Phil Edwards writes: It was considered and rejected for the ISO
@@ -539,7 +542,7 @@ No stream::attach(int fd)
For another example of this, refer to
fdstream example
by Nicolai Josuttis.
-
Check for complete library coverage of the C++1998/2003 standard.
@@ -607,7 +610,7 @@ AC_DEFUN([AC_HEADER_STDCXX_98], [ AC_DEFINE(STDCXX_98_HEADERS,,[Define if ISO C++ 1998 header files are present. ]) fi ]) -
Check for library coverage of the TR1 standard.
@@ -684,7 +687,7 @@ AC_DEFUN([AC_HEADER_TR1_UNORDERED_SET], [ AC_DEFINE(HAVE_TR1_UNORDERED_SET,,[Define if tr1/unordered_set is present. ]) fi ]) -
Check for baseline language coverage in the compiler for the C++0xstandard.
@@ -896,31 +899,34 @@ AC_DEFUN([AC_HEADER_UNORDERED_SET], [ AC_DEFINE(HAVE_UNORDERED_SET,,[Define if unordered_set is present. ]) fi ]) -
+
As this name suggests, this allocator uses a bit-map to keep track of the used and unused memory locations for it's book-keeping @@ -103,7 +103,7 @@ else return false.
Consider a block of size 64 ints. In memory, it would look like this: (assume a 32-bit system where, size_t is a 32-bit entity). -
+
The first Column(268) represents the size of the Block in bytes as seen by the Bitmap Allocator. Internally, a global free list is used to keep track of the free blocks used and given back by the @@ -337,4 +337,4 @@ equivalent.
And also this would preserve the cache as far as poss sizeof(size_t) x 8 which is the number of bits in an integer, which can fit exactly in a CPU register. Hence, the term given is exponential growth of the internal pool. -
+ No, you cannot write code of the form +
+ #include <bitset> + + void foo (size_t n) + { + std::bitset<n> bits; + .... + } +
+ because n
must be known at compile time. Your
+ compiler is correct; it is not a bug. That's the way templates
+ work. (Yes, it is a feature.)
+
+ There are a couple of ways to handle this kind of thing. Please + consider all of them before passing judgement. They include, in + no particular order: +
A very large N in bitset<N>
.
A container<bool>.
Extremely weird solutions.
+ A very large N in
+ bitset<N>
. It has been
+ pointed out a few times in newsgroups that N bits only takes up
+ (N/8) bytes on most systems, and division by a factor of eight is
+ pretty impressive when speaking of memory. Half a megabyte given
+ over to a bitset (recall that there is zero space overhead for
+ housekeeping info; it is known at compile time exactly how large
+ the set is) will hold over four million bits. If you're using
+ those bits as status flags (e.g.,
+ “changed”/“unchanged” flags), that's a
+ lot of state.
+
+ You can then keep track of the “maximum bit used” + during some testing runs on representative data, make note of how + many of those bits really need to be there, and then reduce N to + a smaller number. Leave some extra space, of course. (If you + plan to write code like the incorrect example above, where the + bitset is a local variable, then you may have to talk your + compiler into allowing that much stack space; there may be zero + space overhead, but it's all allocated inside the object.) +
+ A container<bool>. The
+ Committee made provision for the space savings possible with that
+ (N/8) usage previously mentioned, so that you don't have to do
+ wasteful things like Container<char>
or
+ Container<short int>
. Specifically,
+ vector<bool>
is required to be specialized for
+ that space savings.
+
+ The problem is that vector<bool>
doesn't
+ behave like a normal vector anymore. There have been recent
+ journal articles which discuss the problems (the ones by Herb
+ Sutter in the May and July/August 1999 issues of C++ Report cover
+ it well). Future revisions of the ISO C++ Standard will change
+ the requirement for vector<bool>
+ specialization. In the meantime, deque<bool>
+ is recommended (although its behavior is sane, you probably will
+ not get the space savings, but the allocation scheme is different
+ than that of vector).
+
+ Extremely weird solutions. If
+ you have access to the compiler and linker at runtime, you can do
+ something insane, like figuring out just how many bits you need,
+ then writing a temporary source code file. That file contains an
+ instantiation of bitset
for the required number of
+ bits, inside some wrapper functions with unchanging signatures.
+ Have your program then call the compiler on that file using
+ Position Independent Code, then open the newly-created object
+ file and load those wrapper functions. You'll have an
+ instantiation of bitset<N>
for the exact
+ N
that you need at the time. Don't forget to delete
+ the temporary files. (Yes, this can be, and
+ has been, done.)
+
+ This would be the approach of either a visionary genius or a + raving lunatic, depending on your programming and management + style. Probably the latter. +
+ Which of the above techniques you use, if any, are up to you and + your intended application. Some time/space profiling is + indicated if it really matters (don't just guess). And, if you + manage to do anything along the lines of the third category, the + author would love to hear from you... +
+ Also note that the implementation of bitset used in libstdc++ has + some extensions. +
+
+ Bitmasks do not take char* nor const char* arguments in their + constructors. This is something of an accident, but you can read + about the problem: follow the library's “Links” from + the homepage, and from the C++ information “defect + reflector” link, select the library issues list. Issue + number 116 describes the problem. +
+ For now you can simply make a temporary string object using the + constructor expression: +
+ std::bitset<5> b ( std::string(“10110”) );
+
+ instead of +
+ std::bitset<5> b ( “10110” ); // invalid
+
+
+
The only change that might affect people is the type of
NULL
: while it is required to be a macro,
the definition of that macro is not allowed
@@ -26,4 +26,4 @@
+
This part deals with the functions called and objects created automatically during the course of a program's existence.
@@ -8,4 +11,7 @@ need to get your own copy from your nation's member body; see our homepage for help), we can mention a couple of changes in what kind of support a C++ program gets from the Standard Library. -
+
+
In 1999, SGI added “concept checkers” to their implementation of the STL: code which checked the template parameters of instantiated pieces of the STL, in order to insure @@ -36,4 +39,7 @@ support for template parameter constraints based on concepts in the core language. This will obviate the need for the library-simulated concept checking described above. -
Table of Contents
+
Table of Contents
Here are Standard, simple, and portable ways to perform common
transformations on a string
instance, such as
"convert to all upper case." The word transformations
@@ -86,4 +89,7 @@
str.erase(notwhite+1);
Obviously, the calls to find
could be inserted directly
into the calls to erase
, in case your compiler does not
optimize named temporaries out of existence.
-
+
A common lament seen in various newsgroups deals with the Standard string class as opposed to the Microsoft Foundation Class called CString. Often programmers realize that a standard portable @@ -88,4 +88,7 @@ libstdc++ string, the SGI string, and the SGI rope, and this is all before any allocator or traits customizations! (More choices than you can shake a stick at -- want fries with that?) -
Table of Contents
FAQ 5.1 points out that iterators +
Table of Contents
FAQ 5.1 points out that iterators are not implemented as pointers. They are a generalization of pointers, but they are implemented in libstdc++ as separate classes.
Keeping that simple fact in mind as you design your code will @@ -27,4 +30,7 @@ information gets passed down through inheritance, so while the compiler has to do work looking up all the names, your runtime code does not. (This has been a prime concern from the beginning.) -
This starts off sounding complicated, but is actually very easy, +
This starts off sounding complicated, but is actually very easy, especially towards the end. Trust me.
Beginners usually have a little trouble understand the whole 'past-the-end' thing, until they remember their early algebra classes @@ -80,4 +80,7 @@ sequences very simple to recognize: if the two endpoints compare equal, then the {array, sequence, container, whatever} is empty.
Just don't dereference end()
.
-
Table of Contents
If you call std::swap(x,y);
where x and y are standard
+
Table of Contents
If you call std::swap(x,y);
where x and y are standard
containers, then the call will automatically be replaced by a call to
x.swap(y);
instead.
This allows member functions of each container class to take over, and @@ -10,4 +13,7 @@ fact use constant-time swaps.) This should not be surprising, since for two containers of the same type to swap contents, only some internal pointers to storage need to be exchanged. -
+
The neatest accomplishment of the algorithms chapter is that all the work is done via iterators, not containers directly. This means two important things: @@ -32,4 +35,7 @@ this simple rule that seems to cause so much confusion. Once you get range into your head (it's not that hard, honest!), then the algorithms are a cakewalk. -
In addition to the other topics on this page, we'll note here some +
In addition to the other topics on this page, we'll note here some of the C99 features that appear in libstdc++.
The C99 features depend on the --enable-c99
configure flag.
This flag is already on by default, but it can be disabled by the
@@ -13,4 +13,7 @@
are supported, as is the lldiv_t
typedef. Also supported
are the wide character functions using 'long long', like
wcstoll
.
-
First, are you sure that you understand buffering? Particularly +
First, are you sure that you understand buffering? Particularly the fact that C++ may not, in fact, have anything to do with it?
The rules for buffering can be a little odd, but they aren't any different from those of C. (Maybe that's why they can be a bit @@ -74,4 +74,4 @@ just those at the language/library level. Kernel buffers, disk buffers, and the like will also have an effect. Inspecting and changing those are system-dependent. -
+
The first and most important thing to remember about binary I/O is
that opening a file with ios::binary
is not, repeat
not, the only thing you have to do. It is not a silver
@@ -92,4 +92,4 @@
article and continuing to the end of the thread. (You'll have to
sort through some flames every couple of paragraphs, but the points
made are good ones.)
-
Towards the beginning of February 2001, the subject of +
Towards the beginning of February 2001, the subject of "binary" I/O was brought up in a couple of places at the same time. One notable place was Usenet, where James Kanze and Dietmar Kühl separately posted articles on why attempting @@ -19,4 +19,4 @@ Dietmar Kühl mentioned that he had written a pair of stream classes that would read and write XDR, which is a good step towards a portable binary format. -
+
Pathetic Performance? Ditch C.
It sounds like a flame on C, but it isn't. Really. Calm down.
I'm just saying it to get your attention.
@@ -43,4 +43,7 @@
clog
, and their wide-character counterparts). File stream
objects that you declare yourself have no such requirement and are fully
buffered.
-
Table 30.1. Debugging Containers
Container | Header | Debug container | Debug header | ||
---|---|---|---|---|---|
std::bitset | bitset | __gnu_debug::bitset | bitset | ||
std::deque | deque | __gnu_debug::deque | deque | ||
std::list | list | __gnu_debug::list | list | ||
std::map | map | __gnu_debug::map | map | ||
std::multimap | map | __gnu_debug::multimap | map | ||
std::multiset | set | __gnu_debug::multiset | set | ||
std::set | set | __gnu_debug::set | set | ||
std::string | string | __gnu_debug::string | string | ||
std::wstring | string | __gnu_debug::wstring | string | ||
std::basic_string | string | __gnu_debug::basic_string | string | ||
std::vector | vector | __gnu_debug::vector | vector |
In addition, when compiling in C++0x mode, these additional +
Table 30.1. Debugging Containers
Container | Header | Debug container | Debug header | ||
---|---|---|---|---|---|
std::bitset | bitset | __gnu_debug::bitset | bitset | ||
std::deque | deque | __gnu_debug::deque | deque | ||
std::list | list | __gnu_debug::list | list | ||
std::map | map | __gnu_debug::map | map | ||
std::multimap | map | __gnu_debug::multimap | map | ||
std::multiset | set | __gnu_debug::multiset | set | ||
std::set | set | __gnu_debug::set | set | ||
std::string | string | __gnu_debug::string | string | ||
std::wstring | string | __gnu_debug::wstring | string | ||
std::basic_string | string | __gnu_debug::basic_string | string | ||
std::vector | vector | __gnu_debug::vector | vector |
In addition, when compiling in C++0x mode, these additional containers have additional debug capability. -
Table 30.2. Debugging Containers C++0x
Container | Header | Debug container | Debug header | ||
---|---|---|---|---|---|
std::unordered_map | unordered_map | __gnu_debug::unordered_map | unordered_map | ||
std::unordered_multimap | unordered_map | __gnu_debug::unordered_multimap | unordered_map | ||
std::unordered_set | unordered_set | __gnu_debug::unordered_set | unordered_set | ||
std::unordered_multiset | unordered_set | __gnu_debug::unordered_multiset | unordered_set |
Table 30.2. Debugging Containers C++0x
Container | Header | Debug container | Debug header | ||
---|---|---|---|---|---|
std::unordered_map | unordered_map | __gnu_debug::unordered_map | unordered_map | ||
std::unordered_multimap | unordered_map | __gnu_debug::unordered_multimap | unordered_map | ||
std::unordered_set | unordered_set | __gnu_debug::unordered_set | unordered_set | ||
std::unordered_multiset | unordered_set | __gnu_debug::unordered_multiset | unordered_set |
The following table provides the names and headers of all the parallel algorithms that can be used in a similar manner: -
Table 31.1. Parallel Algorithms
Algorithm | Header | Parallel algorithm | Parallel header |
---|---|---|---|
std::accumulate | numeric | __gnu_parallel::accumulate | parallel/numeric |
std::adjacent_difference | numeric | __gnu_parallel::adjacent_difference | parallel/numeric |
std::inner_product | numeric | __gnu_parallel::inner_product | parallel/numeric |
std::partial_sum | numeric | __gnu_parallel::partial_sum | parallel/numeric |
std::adjacent_find | algorithm | __gnu_parallel::adjacent_find | parallel/algorithm |
std::count | algorithm | __gnu_parallel::count | parallel/algorithm |
std::count_if | algorithm | __gnu_parallel::count_if | parallel/algorithm |
std::equal | algorithm | __gnu_parallel::equal | parallel/algorithm |
std::find | algorithm | __gnu_parallel::find | parallel/algorithm |
std::find_if | algorithm | __gnu_parallel::find_if | parallel/algorithm |
std::find_first_of | algorithm | __gnu_parallel::find_first_of | parallel/algorithm |
std::for_each | algorithm | __gnu_parallel::for_each | parallel/algorithm |
std::generate | algorithm | __gnu_parallel::generate | parallel/algorithm |
std::generate_n | algorithm | __gnu_parallel::generate_n | parallel/algorithm |
std::lexicographical_compare | algorithm | __gnu_parallel::lexicographical_compare | parallel/algorithm |
std::mismatch | algorithm | __gnu_parallel::mismatch | parallel/algorithm |
std::search | algorithm | __gnu_parallel::search | parallel/algorithm |
std::search_n | algorithm | __gnu_parallel::search_n | parallel/algorithm |
std::transform | algorithm | __gnu_parallel::transform | parallel/algorithm |
std::replace | algorithm | __gnu_parallel::replace | parallel/algorithm |
std::replace_if | algorithm | __gnu_parallel::replace_if | parallel/algorithm |
std::max_element | algorithm | __gnu_parallel::max_element | parallel/algorithm |
std::merge | algorithm | __gnu_parallel::merge | parallel/algorithm |
std::min_element | algorithm | __gnu_parallel::min_element | parallel/algorithm |
std::nth_element | algorithm | __gnu_parallel::nth_element | parallel/algorithm |
std::partial_sort | algorithm | __gnu_parallel::partial_sort | parallel/algorithm |
std::partition | algorithm | __gnu_parallel::partition | parallel/algorithm |
std::random_shuffle | algorithm | __gnu_parallel::random_shuffle | parallel/algorithm |
std::set_union | algorithm | __gnu_parallel::set_union | parallel/algorithm |
std::set_intersection | algorithm | __gnu_parallel::set_intersection | parallel/algorithm |
std::set_symmetric_difference | algorithm | __gnu_parallel::set_symmetric_difference | parallel/algorithm |
std::set_difference | algorithm | __gnu_parallel::set_difference | parallel/algorithm |
std::sort | algorithm | __gnu_parallel::sort | parallel/algorithm |
std::stable_sort | algorithm | __gnu_parallel::stable_sort | parallel/algorithm |
std::unique_copy | algorithm | __gnu_parallel::unique_copy | parallel/algorithm |
Table 31.1. Parallel Algorithms
Algorithm | Header | Parallel algorithm | Parallel header |
---|---|---|---|
std::accumulate | numeric | __gnu_parallel::accumulate | parallel/numeric |
std::adjacent_difference | numeric | __gnu_parallel::adjacent_difference | parallel/numeric |
std::inner_product | numeric | __gnu_parallel::inner_product | parallel/numeric |
std::partial_sum | numeric | __gnu_parallel::partial_sum | parallel/numeric |
std::adjacent_find | algorithm | __gnu_parallel::adjacent_find | parallel/algorithm |
std::count | algorithm | __gnu_parallel::count | parallel/algorithm |
std::count_if | algorithm | __gnu_parallel::count_if | parallel/algorithm |
std::equal | algorithm | __gnu_parallel::equal | parallel/algorithm |
std::find | algorithm | __gnu_parallel::find | parallel/algorithm |
std::find_if | algorithm | __gnu_parallel::find_if | parallel/algorithm |
std::find_first_of | algorithm | __gnu_parallel::find_first_of | parallel/algorithm |
std::for_each | algorithm | __gnu_parallel::for_each | parallel/algorithm |
std::generate | algorithm | __gnu_parallel::generate | parallel/algorithm |
std::generate_n | algorithm | __gnu_parallel::generate_n | parallel/algorithm |
std::lexicographical_compare | algorithm | __gnu_parallel::lexicographical_compare | parallel/algorithm |
std::mismatch | algorithm | __gnu_parallel::mismatch | parallel/algorithm |
std::search | algorithm | __gnu_parallel::search | parallel/algorithm |
std::search_n | algorithm | __gnu_parallel::search_n | parallel/algorithm |
std::transform | algorithm | __gnu_parallel::transform | parallel/algorithm |
std::replace | algorithm | __gnu_parallel::replace | parallel/algorithm |
std::replace_if | algorithm | __gnu_parallel::replace_if | parallel/algorithm |
std::max_element | algorithm | __gnu_parallel::max_element | parallel/algorithm |
std::merge | algorithm | __gnu_parallel::merge | parallel/algorithm |
std::min_element | algorithm | __gnu_parallel::min_element | parallel/algorithm |
std::nth_element | algorithm | __gnu_parallel::nth_element | parallel/algorithm |
std::partial_sort | algorithm | __gnu_parallel::partial_sort | parallel/algorithm |
std::partition | algorithm | __gnu_parallel::partition | parallel/algorithm |
std::random_shuffle | algorithm | __gnu_parallel::random_shuffle | parallel/algorithm |
std::set_union | algorithm | __gnu_parallel::set_union | parallel/algorithm |
std::set_intersection | algorithm | __gnu_parallel::set_intersection | parallel/algorithm |
std::set_symmetric_difference | algorithm | __gnu_parallel::set_symmetric_difference | parallel/algorithm |
std::set_difference | algorithm | __gnu_parallel::set_difference | parallel/algorithm |
std::sort | algorithm | __gnu_parallel::sort | parallel/algorithm |
std::stable_sort | algorithm | __gnu_parallel::stable_sort | parallel/algorithm |
std::unique_copy | algorithm | __gnu_parallel::unique_copy | parallel/algorithm |
+
+
A few extensions and nods to backwards-compatibility have been made with containers. Those dealing with older SGI-style allocators are dealt with elsewhere. The remaining ones all deal with bits: @@ -40,4 +40,4 @@
size_t _Find_first() const; size_t _Find_next (size_t prev) const;
The same caveat given for the _Unchecked_* functions applies here also. -
The functions for atomic operations described above are either +
The functions for atomic operations described above are either implemented via compiler intrinsics (if the underlying host is capable) or by library fallbacks.
Compiler intrinsics (builtins) are always preferred. However, as
the compiler builtins for atomics are not universally implemented,
@@ -38,4 +38,4 @@ use this layer. More detail as to the specific interface can be found in the sou
functions, and usage found in the usual <pthread.h> file,
including pthread_t
, pthread_once_t
, pthread_create
,
etc.
-
Typical usage of the last two constructs is demonstrated as follows: +
Typical usage of the last two constructs is demonstrated as follows:
#include <ext/concurrence.h> @@ -31,4 +31,7 @@ the mutex as control moves out of this block. concurrence-related errors. These classes are:__concurrence_lock_error
,__concurrence_unlock_error
,__concurrence_wait_error
, and__concurrence_broadcast_error
. -
+
Here we will make an attempt at describing the non-Standard extensions to the library. Some of these are from SGI's STL, some of these are GNU's, and some just seemed to appear on the doorstep. @@ -18,4 +21,7 @@ extensions, be aware of two things:
You should know how to access these headers properly. -
+ Information on known bugs, details on efforts to fix them, and
+ fixed bugs are all available as part of the GCC bug tracking
+ system, bugzilla, with the
+ category set to libstdc++
.
+
+ Everybody's got issues. Even the C++ Standard Library. +
+ The Library Working Group, or LWG, is the ISO subcommittee responsible + for making changes to the library. They periodically publish an + Issues List containing problems and possible solutions. As they reach + a consensus on proposed solutions, we often incorporate the solution. +
+ Here are the issues which have resulted in code changes to the library. + The links are to the specific defect reports from a partial + copy of the Issues List. You can read the full version online + at the ISO C++ + Committee homepage, linked to on the + GCC "Readings" + page. If + you spend a lot of time reading the issues, we recommend downloading + the ZIP file and reading them locally. +
+ (NB: partial copy means that not all + links within the lwg-*.html pages will work. Specifically, + links to defect reports that have not been accorded full DR + status will probably break. Rather than trying to mirror the + entire issues list on our overworked web server, we recommend + you go to the LWG homepage instead.) +
+ If a DR is not listed here, we may simply not have gotten to
+ it yet; feel free to submit a patch. Search the include/bits
+ and src directories for appearances of
+ _GLIBCXX_RESOLVE_LIB_DEFECTS
for examples
+ of style. Note that we usually do not make changes to the
+ code until an issue has reached DR status.
+
This should be two overloaded functions rather than a single function. +
Apparently extracting Boolean values was messed up... +
If codecvt::do_in
returns noconv
there are
+ no changes to the values in [to, to_limit)
.
+
Re-opening a file stream does not clear the state flags. +
Implement the proposed resolution. +
Padding issues. +
An instance of ios_base::failure
is constructed instead.
+
The return type is the previous state of synchronization. +
These members functions are declared private
and are
+ thus inaccessible. Specifying the correct semantics of
+ "copying stream state" was deemed too complicated.
+
This DR made many widespread changes to basic_istream
+ and basic_ostream
all of which have been implemented.
+
Make the policy consistent with that of formatted input, unformatted + input, and formatted output. +
And they do now. An editing glitch in the last item in the list of + [27.6.1.2.3]/7. +
The text of the standard was gibberish. Typos gone rampant. +
Change the first parameter to stateT&
and implement
+ the new effects paragraph.
+
Safety checks on the size of the string should test against
+ max_size()
rather than npos
.
+
The effect contain isspace(c,getloc())
which must be
+ replaced by isspace(c,is.getloc())
.
+
They behave as a formatted input function and as an unformatted
+ input function, respectively (except that getline
is
+ not required to set gcount
).
+
For associative containers where the value type is the same as
+ the key type, both iterator
and const_iterator
+
are constant iterators.
+
The binder1st
and binder2nd
didn't have an
+ operator()
taking a non-const parameter.
+
This was not a const member function. Note that the DR says to + replace the function with a const one; we have instead provided an + overloaded version with identical contents. +
num_put::put()
was overloaded on the wrong types.
+
Same as 117, but for num_get::get()
.
+
These functions set failbit
on error now.
+
seekp
should only set the output stream, and
+ seekg
should only set the input stream.
+
op<<
with a const char*
was
+ calculating an incorrect number of characters to write.
+
Grow efficiently the internal array object. +
Quite complex to summarize... +
This function used to take its arguments as reference-to-const, now + it copies them (pass by value). +
Yes, it can, specifically if EOF is reached while skipping whitespace. +
If nothing is extracted into the string, op>>
now
+ sets failbit
(which can cause an exception, etc., etc.).
+
Both set
and multiset
were missing
+ overloaded find, lower_bound, upper_bound, and equal_range functions
+ for const instances.
+
For conversion from a floating-point type, str.precision()
+ is specified in the conversion specification.
+
Implement N1780, first check before then check after, insert as close + to hint as possible. +
The declaration of reverse_iterator
lists a default constructor.
+ However, no specification is given what this constructor should do.
+
Add a helper for forward_iterator/output_iterator, fix the existing + one for input_iterator/output_iterator to not rely on Assignability. +
Store a null character only if the character array has a non-zero size. +
This nested typedef was originally not specified. +
Make the copy constructor and copy-assignment operator declarations + public in gslice_array, indirect_array, mask_array, slice_array; provide + definitions. +
The default ctor would build its members from copies of temporaries; + now it simply uses their respective default ctors. +
The bad_
* classes no longer have destructors (they
+ are trivial), since no description of them was ever given.
+
The typedefs it inherits from its base classes can't be used, since
+ (for example) basic_iostream<T>::traits_type
is ambiguous.
+
Similar to 118. +
Add global functions with two template parameters. + (NB: not added for now a templated assignment operator) +
If (this == &rhs)
do nothing.
+
If (this == &x)
do nothing.
+
Basically, compare the input character to
+ is.widen(0)
and is.widen(1)
.
+
Do not specify what codecvt<wchar_t, char,
+ mbstate_t>::do_length
must return.
+
Change the format string to "%.0Lf". +
Add const overloads of is_open
.
+
Add the real(T)
and imag(T)
+ members; in C++0x mode, also adjust the existing
+ real()
and imag()
members and
+ free functions.
+
Change it to return a const T&
.
+
Implement the proposed resolution. +
Replace "new" with "::new". +
Have open
clear the error flags.
+
Implement Option 3, as per N1599. +
Implement the resolution, beyond DR 169. +
Add three overloads, taking fewer template arguments. +
Implement the resolution, basically cast less. +
Don't fail if the next pointer is null and newoff is zero. +
Initialize cerr tied to cout and wcerr tied to wcout. +
Add data()
to std::vector
and
+ at(const key_type&)
to std::map
.
+
Fix the parameters. +
Construct a linear_congruential
engine and seed with it.
+
Use &value. +
In case of input_iterator/output_iterator rely on Assignability of + input_iterator' value_type. +
Add an auto_ptr<void> specialization. +
Follow the straightforward proposed resolution. +
In C++0x mode, remove the pow(float,int), etc., signatures. +
Change it to be a formatted output function (i.e. catch exceptions). +
Add the missing modes to fopen_mode. +
Add the missing operations. +
In C++0x mode add cbegin(size_type) and cend(size_type) + to the unordered containers. +
Add it, consistently with the discussion. +
Make the member functions table and classic_table public. +
In C++0x mode, add at() and at() const. +
Implement the int -> size_t replacements. +
In C++0x mode, remove assign, add fill. +
In C++0x mode, add std::proj. +
Add the overload. +
In C++0x mode, remove the pow(complex<T>, int) signature. +
Update / add the signatures. +
+
The standard class codecvt attempts to address conversions between different character encoding schemes. In particular, the standard attempts to detail conversions between the implementation-defined wide @@ -337,43 +337,43 @@ codecvt usage.
wchar_t/char internal buffers and conversions between internal/external buffers? -
The GNU C Library - . Copyright © 2007 FSF. Chapters 6 Character Set Handling and 7 Locales and Internationalization.
System Interface Definitions, Issue 6 (IEEE Std. 1003.1-200x) . Copyright © 1999 The Open Group/The Institute of Electrical and Electronics Engineers, Inc.. - .
The C++ Programming Language, Special Edition . Copyright © 2000 Addison Wesley, Inc.. Appendix D. Addison Wesley - .
Table of Contents
+
+
Using complex<>
becomes even more comple- er, sorry,
+ complicated, with the not-quite-gratuitously-incompatible
+ addition of complex types to the C language. David Tribble has
+ compiled a list of C++98 and C99 conflict points; his description of
+ C's new type versus those of C++ and how to get them playing together
+ nicely is
+here.
+
complex<>
is intended to be instantiated with a
+ floating-point type. As long as you meet that and some other basic
+ requirements, then the resulting instantiation has all of the usual
+ math operators defined, as well as definitions of op<<
+ and op>>
that work with iostreams: op<<
+ prints (u,v)
and op>>
can read u
,
+ (u)
, and (u,v)
.
+
+
When configuring libstdc++, you'll have to configure the entire gccsrcdir directory. Consider using the toplevel gcc configuration option @@ -70,7 +70,7 @@ specify a wrapper for malloc, 'mt' for a fixed power of two allocator, 'pool' for the SGI pooled allocator or 'bitmap' for a bitmap allocator. This option can change the library ABI. See this page for more information on allocator - extensions + extensions
--enable-cheaders=OPTION
This allows the user to define the approach taken for C header compatibility with C++. Options are c, c_std, and c_global. These correspond to the source directory's include/c, @@ -198,4 +198,4 @@ linking of libpthread too, which activates locking, a large overhead for single-thread programs. OPTION=no skips the tests completely. The default is OPTION=no. -
Table of Contents
+ You're writing some code and can't decide whether to use builtin + arrays or some kind of container. There are compelling reasons + to use one of the container classes, but you're afraid that + you'll eventually run into difficulties, change everything back + to arrays, and then have to change all the code that uses those + data types to keep up with the change. +
+ If your code makes use of the standard algorithms, this isn't as
+ scary as it sounds. The algorithms don't know, nor care, about
+ the kind of “container” on which they work, since
+ the algorithms are only given endpoints to work with. For the
+ container classes, these are iterators (usually
+ begin()
and end()
, but not always).
+ For builtin arrays, these are the address of the first element
+ and the past-the-end element.
+
+ Some very simple wrapper functions can hide all of that from the
+ rest of the code. For example, a pair of functions called
+ beginof
can be written, one that takes an array,
+ another that takes a vector. The first returns a pointer to the
+ first element, and the second returns the vector's
+ begin()
iterator.
+
+ The functions should be made template functions, and should also
+ be declared inline. As pointed out in the comments in the code
+ below, this can lead to beginof
being optimized out
+ of existence, so you pay absolutely nothing in terms of increased
+ code size or execution time.
+
+ The result is that if all your algorithm calls look like +
+ std::transform(beginof(foo), endof(foo), beginof(foo), SomeFunction); +
+ then the type of foo can change from an array of ints to a vector + of ints to a deque of ints and back again, without ever changing + any client code. +
+ This author has a collection of such functions, called + “*of” because they all extend the builtin + “sizeof”. It started with some Usenet discussions + on a transparent way to find the length of an array. A + simplified and much-reduced version for easier reading is given here. +
+ Astute readers will notice two things at once: first, that the
+ container class is still a vector<T>
instead
+ of a more general Container<T>
. This would
+ mean that three functions for deque
would have to be
+ added, another three for list
, and so on. This is
+ due to problems with getting template resolution correct; I find
+ it easier just to give the extra three lines and avoid confusion.
+
+ Second, the line +
+ inline unsigned int lengthof (T (&)[sz]) { return sz; } +
+ looks just weird! Hint: unused parameters can be left nameless. +
+
There are numerous things that can be done to improve the ease with
which C++ binaries are debugged when using the GNU tool chain. Here
are some of them.
@@ -67,7 +67,7 @@
thing of great importance to keep in mind when debugging C++ code
that uses new
and delete
: there are
different kinds of allocation schemes that can be used by
- std::allocator
. For implementation details, see the mt allocator documentation and
+ std::allocator . For implementation details, see the mt allocator documentation and
look specifically for GLIBCXX_FORCE_NEW
.
In a nutshell, the default allocator used by
@@ -138,12 +138,15 @@
set print demangle on
set demangle-style gnu-v3
- The verbose + The verbose termination handler gives information about uncaught exceptions which are killing the program. It is described in the linked-to page.
The Debug Mode has compile and run-time checks for many containers. -
The Compile-Time +
The Compile-Time Checks Extension has compile-time checks for many algorithms. -
Table of Contents
+
Table of Contents
By default, libstdc++ is built with efficiency in mind, and
therefore performs little or no error checking that is not
required by the C++ standard. This means that programs that
@@ -31,4 +34,4 @@
the same predicate that was passed
to set_intersection
; the libstdc++ debug mode will
detect an error if the sequence is not sorted or was sorted by a
- different predicate.
+ Prerequisite tools are Bash 2.x, + Doxygen, and + the GNU + coreutils. (GNU versions of find, xargs, and possibly + sed and grep are used, just because the GNU versions make + things very easy.) +
+ To generate the pretty pictures and hierarchy + graphs, the + Graphviz + package will need to be installed. +
+ The following Makefile rules run Doxygen to generate HTML + docs, XML docs, and the man pages. +
+
make doc-html-doxygen
+
+
make doc-xml-doxygen
+
+
make doc-man-doxygen
+
+ Careful observers will see that the Makefile rules simply call
+ a script from the source tree, run_doxygen
, which
+ does the actual work of running Doxygen and then (most
+ importantly) massaging the output files. If for some reason
+ you prefer to not go through the Makefile, you can call this
+ script directly. (Start by passing --help
.)
+
+ If you wish to tweak the Doxygen settings, do so by editing
+ doc/doxygen/user.cfg.in
. Notes to fellow
+ library hackers are written in triple-# comments.
+
+ In general, libstdc++ files should be formatted according to + the rules found in the + Coding Standard. Before + any doxygen-specific formatting tweaks are made, please try to + make sure that the initial formatting is sound. +
+ Adding Doxygen markup to a file (informally called + “doxygenating”) is very simple. The Doxygen manual can be + found + here. + We try to use a very-recent version of Doxygen. +
+ For classes, use
+ deque
/vector
/list
+ and std::pair
as examples. For
+ functions, see their member functions, and the free functions
+ in stl_algobase.h
. Member functions of
+ other container-like types should read similarly to these
+ member functions.
+
+ These points accompany the first list in section 3.1 of the + Doxygen manual: +
Use the Javadoc style...
+ ...not the Qt style. The intermediate *'s are preferred. +
+ Use the triple-slash style only for one-line comments (the + “brief” mode). Very recent versions of Doxygen permit + full-mode comments in triple-slash blocks, but the + formatting still comes out wonky. +
+ This is disgusting. Don't do this. +
+ Use the @-style of commands, not the !-style. Please be + careful about whitespace in your markup comments. Most of the + time it doesn't matter; doxygen absorbs most whitespace, and + both HTML and *roff are agnostic about whitespace. However, + in <pre> blocks and @code/@endcode sections, spacing can + have “interesting” effects. +
+ Use either kind of grouping, as
+ appropriate. doxygroups.cc
exists for this
+ purpose. See stl_iterator.h
for a good example
+ of the “other” kind of grouping.
+
+ Please use markup tags like @p and @a when referring to things + such as the names of function parameters. Use @e for emphasis + when necessary. Use @c to refer to other standard names. + (Examples of all these abound in the present code.) +
+ Editing the DocBook sources requires an XML editor. Many + exist: some notable options + include emacs, Kate, + or Conglomerate. +
+ Some editors support special “XML Validation” + modes that can validate the file as it is + produced. Recommended is the nXML Mode + for emacs. +
+ Besides an editor, additional DocBook files and XML tools are + also required. +
+ Access to the DocBook stylesheets and DTD is required. The
+ stylesheets are usually packaged by vendor, in something
+ like docbook-style-xsl
. To exactly match
+ generated output, please use a version of the stylesheets
+ equivalent
+ to docbook-style-xsl-1.74.0-5
. The
+ installation directory for this package corresponds to
+ the XSL_STYLE_DIR
+ in doc/Makefile.am
and defaults
+ to /usr/share/sgml/docbook/xsl-stylesheets
.
+
+ For processing XML, an XML processor and some style
+ sheets are necessary. Defaults are xsltproc
+ provided by libxslt
.
+
+ For validating the XML document, you'll need
+ something like xmllint and access to the
+ DocBook DTD. These are provided
+ by a vendor package like lixml2
.
+
+ For PDF output, something that transforms valid XML to PDF is
+ required. Possible solutions include xmlto,
+ Apache
+ FOP, or prince. Other options are
+ listed on the DocBook web pages. Please
+ consult the <libstdc++@gcc.gnu.org>
list when
+ preparing printed manuals for current best practice and suggestions.
+
+ Make sure that the XML documentation and markup is valid for
+ any change. This can be done easily, with the validation rules
+ in the Makefile
, which is equivalent to doing:
+
+
+xmllint --noout --valid xml/index.xml
+
+
+ The following Makefile rules generate (in order): an HTML + version of all the documentation, a PDF version of the same, a + single XML document, and the result of validating the entire XML + document. +
+
make doc-html
+
+
make doc-pdf
+
+
make doc-xml-single
+
+
make doc-xml-validate
+
+ Which files are important
+
+ All Docbook files are in the directory
+ libstdc++-v3/doc/xml
+
+ Inside this directory, the files of importance:
+ spine.xml - index to documentation set
+ manual/spine.xml - index to manual
+ manual/*.xml - individual chapters and sections of the manual
+ faq.xml - index to FAQ
+ api.xml - index to source level / API
+
+ All *.txml files are template xml files, i.e., otherwise empty files with
+ the correct structure, suitable for filling in with new information.
+
+ Canonical Writing Style
+
+ class template
+ function template
+ member function template
+ (via C++ Templates, Vandevoorde)
+
+ class in namespace std: allocator, not std::allocator
+
+ header file: iostream, not <iostream>
+
+
+ General structure
+
+ <set>
+ <book>
+ </book>
+
+ <book>
+ <chapter>
+ </chapter>
+ </book>
+
+ <book>
+ <part>
+ <chapter>
+ <section>
+ </section>
+
+ <sect1>
+ </sect1>
+
+ <sect1>
+ <sect2>
+ </sect2>
+ </sect1>
+ </chapter>
+
+ <chapter>
+ </chapter>
+ </part>
+ </book>
+
+ </set>
+
+Complete details on Docbook markup can be found in the DocBook Element +Reference, online. An +incomplete reference for HTML to Docbook conversion is detailed in the +table below. +
Table A.1. HTML to Docbook XML markup comparison
HTML | XML |
---|---|
<p> | <para> |
<pre> | <computeroutput>, <programlisting>, + <literallayout> |
<ul> | <itemizedlist> |
<ol> | <orderedlist> |
<il> | <listitem> |
<dl> | <variablelist> |
<dt> | <term> |
<dd> | <listitem> |
<a href=""> | <ulink url=""> |
<code> | <literal>, <programlisting> |
<strong> | <emphasis> |
<em> | <emphasis> |
" | <quote> |
+ And examples of detailed markup for which there are no real HTML + equivalents are listed in the table below. +
Table A.2. Docbook XML Element Use
Element | Use |
---|---|
<structname> | <structname>char_traits</structname> |
<classname> | <classname>string</classname> |
<function> |
+ <function>clear()</function> +<function>fs.clear()</function> + |
<type> | <type>long long</type> |
<varname> | <varname>fs</varname> |
<literal> |
+ <literal>-Weffc++</literal> +<literal>rel_ops</literal> + |
<constant> |
+ <constant>_GNU_SOURCE</constant> +<constant>3.0</constant> + |
<command> | <command>g++</command> |
<errortext> | <errortext>In instantiation of</errortext> |
<filename> |
+ <filename class="headerfile">ctype.h</filename> +<filename class="directory">/home/gcc/build</filename> + |
+ There are six flavors each of new
and
+ delete
, so make certain that you're using the right
+ ones. Here are quickie descriptions of new
:
+
+ single object form, throwing a
+ bad_alloc
on errors; this is what most
+ people are used to using
+
+ Single object "nothrow" form, returning NULL on errors +
+ Array new
, throwing
+ bad_alloc
on errors
+
+ Array nothrow new
, returning
+ NULL
on errors
+
+ Placement new
, which does nothing (like
+ it's supposed to)
+
+ Placement array new
, which also does
+ nothing
+
+ They are distinguished by the parameters that you pass to them, like
+ any other overloaded function. The six flavors of delete
+ are distinguished the same way, but none of them are allowed to throw
+ an exception under any circumstances anyhow. (They match up for
+ completeness' sake.)
+
+ Remember that it is perfectly okay to call delete
on a
+ NULL pointer! Nothing happens, by definition. That is not the
+ same thing as deleting a pointer twice.
+
+ By default, if one of the “throwing new
s” can't
+ allocate the memory requested, it tosses an instance of a
+ bad_alloc
exception (or, technically, some class derived
+ from it). You can change this by writing your own function (called a
+ new-handler) and then registering it with set_new_handler()
:
+
+ typedef void (*PFV)(void); + + static char* safety; + static PFV old_handler; + + void my_new_handler () + { + delete[] safety; + popup_window ("Dude, you are running low on heap memory. You + should, like, close some windows, or something. + The next time you run out, we're gonna burn!"); + set_new_handler (old_handler); + return; + } + + int main () + { + safety = new char[500000]; + old_handler = set_new_handler (&my_new_handler); + ... + } +
+ bad_alloc
is derived from the base exception
+ class defined in Chapter 19.
+
Table of Contents
+ All exception objects are defined in one of the standard header
+ files: exception
,
+ stdexcept
, new
, and
+ typeinfo
.
+
+ The base exception object is exception
,
+ located in exception
. This object has no
+ string
member.
+
+ Derived from this are several classes that may have a
+ string
member: a full hierarchy can be
+ found in the source documentation.
+
25.1.6 (count, count_if) is extended with two more versions of count + and count_if. The standard versions return their results. The + additional signatures return void, but take a final parameter by + reference to which they assign their results, e.g., +
+ void count (first, last, value, n);
25.2 (mutating algorithms) is extended with two families of signatures, + random_sample and random_sample_n. +
25.2.1 (copy) is extended with +
+ copy_n (_InputIter first, _Size count, _OutputIter result);
which copies the first 'count' elements at 'first' into 'result'. +
25.3 (sorting 'n' heaps 'n' stuff) is extended with some helper + predicates. Look in the doxygen-generated pages for notes on these. +
is_heap
tests whether or not a range is a heap.
is_sorted
tests whether or not a range is sorted in
+ nondescending order.
25.3.8 (lexicographical_compare) is extended with +
+ lexicographical_compare_3way(_InputIter1 first1, _InputIter1 last1, + _InputIter2 first2, _InputIter2 last2)
which does... what? +
Table of Contents
+
+ The mt allocator [hereinafter referred to simply as "the allocator"] + is a fixed size (power of two) allocator that was initially + developed specifically to suit the needs of multi threaded + applications [hereinafter referred to as an MT application]. Over + time the allocator has evolved and been improved in many ways, in + particular it now also does a good job in single threaded + applications [hereinafter referred to as a ST application]. (Note: + In this document, when referring to single threaded applications + this also includes applications that are compiled with gcc without + thread support enabled. This is accomplished using ifdef's on + __GTHREADS). This allocator is tunable, very flexible, and capable + of high-performance. +
+ The aim of this document is to describe - from an application point of + view - the "inner workings" of the allocator. +
There are three general components to the allocator: a datum +describing the characteristics of the memory pool, a policy class +containing this pool that links instantiation types to common or +individual pools, and a class inheriting from the policy class that is +the actual allocator. +
The datum describing pools characteristics is +
+ template<bool _Thread> + class __pool +
This class is parametrized on thread support, and is explicitly
+specialized for both multiple threads (with bool==true
)
+and single threads (via bool==false
.) It is possible to
+use a custom pool datum instead of the default class that is provided.
+
There are two distinct policy classes, each of which can be used +with either type of underlying pool datum. +
+ template<bool _Thread> + struct __common_pool_policy + + template<typename _Tp, bool _Thread> + struct __per_type_pool_policy +
The first policy, __common_pool_policy
, implements a
+common pool. This means that allocators that are instantiated with
+different types, say char
and long
will both
+use the same pool. This is the default policy.
+
The second policy, __per_type_pool_policy
, implements
+a separate pool for each instantiating type. Thus, char
+and long
will use separate pools. This allows per-type
+tuning, for instance.
+
Putting this all together, the actual allocator class is +
+ template<typename _Tp, typename _Poolp = __default_policy> + class __mt_alloc : public __mt_alloc_base<_Tp>, _Poolp +
This class has the interface required for standard library allocator
+classes, namely member functions allocate
and
+deallocate
, plus others.
+
Certain allocation parameters can be modified, or tuned. There
+exists a nested struct __pool_base::_Tune
that contains all
+these parameters, which include settings for
+
Alignment
Maximum bytes before calling ::operator new
directly
Minimum bytes
Size of underlying global allocations
Maximum number of supported threads
Migration of deallocations to the global free list
Shunt for global new
and delete
Adjusting parameters for a given instance of an allocator can only +happen before any allocations take place, when the allocator itself is +initialized. For instance: +
+#include <ext/mt_allocator.h> + +struct pod +{ + int i; + int j; +}; + +int main() +{ + typedef pod value_type; + typedef __gnu_cxx::__mt_alloc<value_type> allocator_type; + typedef __gnu_cxx::__pool_base::_Tune tune_type; + + tune_type t_default; + tune_type t_opt(16, 5120, 32, 5120, 20, 10, false); + tune_type t_single(16, 5120, 32, 5120, 1, 10, false); + + tune_type t; + t = allocator_type::_M_get_options(); + allocator_type::_M_set_options(t_opt); + t = allocator_type::_M_get_options(); + + allocator_type a; + allocator_type::pointer p1 = a.allocate(128); + allocator_type::pointer p2 = a.allocate(5128); + + a.deallocate(p1, 128); + a.deallocate(p2, 5128); + + return 0; +} +
+The static variables (pointers to freelists, tuning parameters etc) +are initialized as above, or are set to the global defaults. +
+The very first allocate() call will always call the +_S_initialize_once() function. In order to make sure that this +function is called exactly once we make use of a __gthread_once call +in MT applications and check a static bool (_S_init) in ST +applications. +
+The _S_initialize() function: +- If the GLIBCXX_FORCE_NEW environment variable is set, it sets the bool + _S_force_new to true and then returns. This will cause subsequent calls to + allocate() to return memory directly from a new() call, and deallocate will + only do a delete() call. +
+- If the GLIBCXX_FORCE_NEW environment variable is not set, both ST and MT + applications will: + - Calculate the number of bins needed. A bin is a specific power of two size + of bytes. I.e., by default the allocator will deal with requests of up to + 128 bytes (or whatever the value of _S_max_bytes is when _S_init() is + called). This means that there will be bins of the following sizes + (in bytes): 1, 2, 4, 8, 16, 32, 64, 128. + + - Create the _S_binmap array. All requests are rounded up to the next + "large enough" bin. I.e., a request for 29 bytes will cause a block from + the "32 byte bin" to be returned to the application. The purpose of + _S_binmap is to speed up the process of finding out which bin to use. + I.e., the value of _S_binmap[ 29 ] is initialized to 5 (bin 5 = 32 bytes). +
+ - Create the _S_bin array. This array consists of bin_records. There will be + as many bin_records in this array as the number of bins that we calculated + earlier. I.e., if _S_max_bytes = 128 there will be 8 entries. + Each bin_record is then initialized: + - bin_record->first = An array of pointers to block_records. There will be + as many block_records pointers as there are maximum number of threads + (in a ST application there is only 1 thread, in a MT application there + are _S_max_threads). + This holds the pointer to the first free block for each thread in this + bin. I.e., if we would like to know where the first free block of size 32 + for thread number 3 is we would look this up by: _S_bin[ 5 ].first[ 3 ] + + The above created block_record pointers members are now initialized to + their initial values. I.e. _S_bin[ n ].first[ n ] = NULL; +
+- Additionally a MT application will: + - Create a list of free thread id's. The pointer to the first entry + is stored in _S_thread_freelist_first. The reason for this approach is + that the __gthread_self() call will not return a value that corresponds to + the maximum number of threads allowed but rather a process id number or + something else. So what we do is that we create a list of thread_records. + This list is _S_max_threads long and each entry holds a size_t thread_id + which is initialized to 1, 2, 3, 4, 5 and so on up to _S_max_threads. + Each time a thread calls allocate() or deallocate() we call + _S_get_thread_id() which looks at the value of _S_thread_key which is a + thread local storage pointer. If this is NULL we know that this is a newly + created thread and we pop the first entry from this list and saves the + pointer to this record in the _S_thread_key variable. The next time + we will get the pointer to the thread_record back and we use the + thread_record->thread_id as identification. I.e., the first thread that + calls allocate will get the first record in this list and thus be thread + number 1 and will then find the pointer to its first free 32 byte block + in _S_bin[ 5 ].first[ 1 ] + When we create the _S_thread_key we also define a destructor + (_S_thread_key_destr) which means that when the thread dies, this + thread_record is returned to the front of this list and the thread id + can then be reused if a new thread is created. + This list is protected by a mutex (_S_thread_freelist_mutex) which is only + locked when records are removed or added to the list. +
+ - Initialize the free and used counters of each bin_record: + - bin_record->free = An array of size_t. This keeps track of the number + of blocks on a specific thread's freelist in each bin. I.e., if a thread + has 12 32-byte blocks on it's freelists and allocates one of these, this + counter would be decreased to 11. + + - bin_record->used = An array of size_t. This keeps track of the number + of blocks currently in use of this size by this thread. I.e., if a thread + has made 678 requests (and no deallocations...) of 32-byte blocks this + counter will read 678. + + The above created arrays are now initialized with their initial values. + I.e. _S_bin[ n ].free[ n ] = 0; +
+ - Initialize the mutex of each bin_record: The bin_record->mutex + is used to protect the global freelist. This concept of a global + freelist is explained in more detail in the section "A multi + threaded example", but basically this mutex is locked whenever a + block of memory is retrieved or returned to the global freelist + for this specific bin. This only occurs when a number of blocks + are grabbed from the global list to a thread specific list or when + a thread decides to return some blocks to the global freelist. +
Notes about deallocation. This allocator does not explicitly
+release memory. Because of this, memory debugging programs like
+valgrind or purify may notice leaks: sorry about this
+inconvenience. Operating systems will reclaim allocated memory at
+program termination anyway. If sidestepping this kind of noise is
+desired, there are three options: use an allocator, like
+new_allocator
that releases memory while debugging, use
+GLIBCXX_FORCE_NEW to bypass the allocator's internal pools, or use a
+custom pool datum that releases resources on destruction.
+
+ On systems with the function __cxa_atexit
, the
+allocator can be forced to free all memory allocated before program
+termination with the member function
+__pool_type::_M_destroy
. However, because this member
+function relies on the precise and exactly-conforming ordering of
+static destructors, including those of a static local
+__pool
object, it should not be used, ever, on systems
+that don't have the necessary underlying support. In addition, in
+practice, forcing deallocation can be tricky, as it requires the
+__pool
object to be fully-constructed before the object
+that uses it is fully constructed. For most (but not all) STL
+containers, this works, as an instance of the allocator is constructed
+as part of a container's constructor. However, this assumption is
+implementation-specific, and subject to change. For an example of a
+pool that frees memory, see the following
+
+ example.
+
+Let's start by describing how the data on a freelist is laid out in memory. +This is the first two blocks in freelist for thread id 3 in bin 3 (8 bytes): +
++----------------+ +| next* ---------|--+ (_S_bin[ 3 ].first[ 3 ] points here) +| | | +| | | +| | | ++----------------+ | +| thread_id = 3 | | +| | | +| | | +| | | ++----------------+ | +| DATA | | (A pointer to here is what is returned to the +| | | the application when needed) +| | | +| | | +| | | +| | | +| | | +| | | ++----------------+ | ++----------------+ | +| next* |<-+ (If next == NULL it's the last one on the list) +| | +| | +| | ++----------------+ +| thread_id = 3 | +| | +| | +| | ++----------------+ +| DATA | +| | +| | +| | +| | +| | +| | +| | ++----------------+ +
+With this in mind we simplify things a bit for a while and say that there is +only one thread (a ST application). In this case all operations are made to +what is referred to as the global pool - thread id 0 (No thread may be +assigned this id since they span from 1 to _S_max_threads in a MT application). +
+When the application requests memory (calling allocate()) we first look at the +requested size and if this is > _S_max_bytes we call new() directly and return. +
+If the requested size is within limits we start by finding out from which +bin we should serve this request by looking in _S_binmap. +
+A quick look at _S_bin[ bin ].first[ 0 ] tells us if there are any blocks of +this size on the freelist (0). If this is not NULL - fine, just remove the +block that _S_bin[ bin ].first[ 0 ] points to from the list, +update _S_bin[ bin ].first[ 0 ] and return a pointer to that blocks data. +
+If the freelist is empty (the pointer is NULL) we must get memory from the +system and build us a freelist within this memory. All requests for new memory +is made in chunks of _S_chunk_size. Knowing the size of a block_record and +the bytes that this bin stores we then calculate how many blocks we can create +within this chunk, build the list, remove the first block, update the pointer +(_S_bin[ bin ].first[ 0 ]) and return a pointer to that blocks data. +
+Deallocation is equally simple; the pointer is casted back to a block_record +pointer, lookup which bin to use based on the size, add the block to the front +of the global freelist and update the pointer as needed +(_S_bin[ bin ].first[ 0 ]). +
+The decision to add deallocated blocks to the front of the freelist was made +after a set of performance measurements that showed that this is roughly 10% +faster than maintaining a set of "last pointers" as well. +
+In the ST example we never used the thread_id variable present in each block. +Let's start by explaining the purpose of this in a MT application. +
+The concept of "ownership" was introduced since many MT applications +allocate and deallocate memory to shared containers from different +threads (such as a cache shared amongst all threads). This introduces +a problem if the allocator only returns memory to the current threads +freelist (I.e., there might be one thread doing all the allocation and +thus obtaining ever more memory from the system and another thread +that is getting a longer and longer freelist - this will in the end +consume all available memory). +
+Each time a block is moved from the global list (where ownership is +irrelevant), to a threads freelist (or when a new freelist is built +from a chunk directly onto a threads freelist or when a deallocation +occurs on a block which was not allocated by the same thread id as the +one doing the deallocation) the thread id is set to the current one. +
+What's the use? Well, when a deallocation occurs we can now look at +the thread id and find out if it was allocated by another thread id +and decrease the used counter of that thread instead, thus keeping the +free and used counters correct. And keeping the free and used counters +corrects is very important since the relationship between these two +variables decides if memory should be returned to the global pool or +not when a deallocation occurs. +
+When the application requests memory (calling allocate()) we first +look at the requested size and if this is >_S_max_bytes we call new() +directly and return. +
+If the requested size is within limits we start by finding out from which +bin we should serve this request by looking in _S_binmap. +
+A call to _S_get_thread_id() returns the thread id for the calling thread +(and if no value has been set in _S_thread_key, a new id is assigned and +returned). +
+A quick look at _S_bin[ bin ].first[ thread_id ] tells us if there are +any blocks of this size on the current threads freelist. If this is +not NULL - fine, just remove the block that _S_bin[ bin ].first[ +thread_id ] points to from the list, update _S_bin[ bin ].first[ +thread_id ], update the free and used counters and return a pointer to +that blocks data. +
+If the freelist is empty (the pointer is NULL) we start by looking at +the global freelist (0). If there are blocks available on the global +freelist we lock this bins mutex and move up to block_count (the +number of blocks of this bins size that will fit into a _S_chunk_size) +or until end of list - whatever comes first - to the current threads +freelist and at the same time change the thread_id ownership and +update the counters and pointers. When the bins mutex has been +unlocked, we remove the block that _S_bin[ bin ].first[ thread_id ] +points to from the list, update _S_bin[ bin ].first[ thread_id ], +update the free and used counters, and return a pointer to that blocks +data. +
+The reason that the number of blocks moved to the current threads +freelist is limited to block_count is to minimize the chance that a +subsequent deallocate() call will return the excess blocks to the +global freelist (based on the _S_freelist_headroom calculation, see +below). +
+However if there isn't any memory on the global pool we need to get +memory from the system - this is done in exactly the same way as in a +single threaded application with one major difference; the list built +in the newly allocated memory (of _S_chunk_size size) is added to the +current threads freelist instead of to the global. +
+The basic process of a deallocation call is simple: always add the +block to the front of the current threads freelist and update the +counters and pointers (as described earlier with the specific check of +ownership that causes the used counter of the thread that originally +allocated the block to be decreased instead of the current threads +counter). +
+And here comes the free and used counters to service. Each time a +deallocation() call is made, the length of the current threads +freelist is compared to the amount memory in use by this thread. +
+Let's go back to the example of an application that has one thread +that does all the allocations and one that deallocates. Both these +threads use say 516 32-byte blocks that was allocated during thread +creation for example. Their used counters will both say 516 at this +point. The allocation thread now grabs 1000 32-byte blocks and puts +them in a shared container. The used counter for this thread is now +1516. +
+The deallocation thread now deallocates 500 of these blocks. For each +deallocation made the used counter of the allocating thread is +decreased and the freelist of the deallocation thread gets longer and +longer. But the calculation made in deallocate() will limit the length +of the freelist in the deallocation thread to _S_freelist_headroom % +of it's used counter. In this case, when the freelist (given that the +_S_freelist_headroom is at it's default value of 10%) exceeds 52 +(516/10) blocks will be returned to the global pool where the +allocating thread may pick them up and reuse them. +
+In order to reduce lock contention (since this requires this bins +mutex to be locked) this operation is also made in chunks of blocks +(just like when chunks of blocks are moved from the global freelist to +a threads freelist mentioned above). The "formula" used can probably +be improved to further reduce the risk of blocks being "bounced back +and forth" between freelists. +
+ Also known as concept checking. +
In 1999, SGI added concept checkers to their implementation
+ of the STL: code which checked the template parameters of
+ instantiated pieces of the STL, in order to insure that the parameters
+ being used met the requirements of the standard. For example,
+ the Standard requires that types passed as template parameters to
+ vector
be “Assignable” (which means what you think
+ it means). The checking was done during compilation, and none of
+ the code was executed at runtime.
+
Unfortunately, the size of the compiler files grew significantly + as a result. The checking code itself was cumbersome. And bugs + were found in it on more than one occasion. +
The primary author of the checking code, Jeremy Siek, had already + started work on a replacement implementation. The new code has been + formally reviewed and accepted into + the + Boost libraries, and we are pleased to incorporate it into the + GNU C++ library. +
The new version imposes a much smaller space overhead on the generated + object file. The checks are also cleaner and easier to read and + understand. +
They are off by default for all versions of GCC from 3.0 to 3.4 (the
+ latest release at the time of writing).
+ They can be enabled at configure time with
+ --enable-concept-checks
.
+ You can enable them on a per-translation-unit basis with
+ #define _GLIBCXX_CONCEPT_CHECKS
for GCC 3.4 and higher
+ (or with #define _GLIBCPP_CONCEPT_CHECKS
for versions
+ 3.1, 3.2 and 3.3).
+
Please note that the upcoming C++ standard has first-class + support for template parameter constraints based on concepts in the core + language. This will obviate the need for the library-simulated concept + checking described above. +
Table of Contents
The file <ext/concurrence.h> contains all the higher-level
+constructs for playing with threads. In contrast to the atomics layer,
+the concurrence layer consists largely of types. All types are defined within namespace __gnu_cxx
.
+
+These types can be used in a portable manner, regardless of the +specific environment. They are carefully designed to provide optimum +efficiency and speed, abstracting out underlying thread calls and +accesses when compiling for single-threaded situations (even on hosts +that support multiple threads.) +
The enumerated type _Lock_policy
details the set of
+available locking
+policies: _S_single
, _S_mutex
,
+and _S_atomic
.
+
_S_single
Indicates single-threaded code that does not need locking. +
_S_mutex
Indicates multi-threaded code using thread-layer abstractions. +
_S_atomic
Indicates multi-threaded code using atomic operations. +
The compile-time constant __default_lock_policy
is set
+to one of the three values above, depending on characteristics of the
+host environment and the current compilation flags.
+
Two more datatypes make up the rest of the
+interface: __mutex
, and __scoped_lock
.
+
+
The scoped lock idiom is well-discussed within the C++
+community. This version takes a __mutex
reference, and
+locks it during construction of __scoped_locke
and
+unlocks it during destruction. This is an efficient way of locking
+critical sections, while retaining exception-safety.
+
+Two functions and one type form the base of atomic support. +
The type _Atomic_word
is a signed integral type
+supporting atomic operations.
+
+The two functions functions are: +
+_Atomic_word +__exchange_and_add_dispatch(volatile _Atomic_word*, int); + +void +__atomic_add_dispatch(volatile _Atomic_word*, int); +
Both of these functions are declared in the header file
+<ext/atomicity.h>, and are in namespace __gnu_cxx
.
+
+
+__exchange_and_add_dispatch
+
+
Adds the second argument's value to the first argument. Returns the old value. +
+
+__atomic_add_dispatch
+
+
Adds the second argument's value to the first argument. Has no return value. +
+These functions forward to one of several specialized helper +functions, depending on the circumstances. For instance, +
+
+__exchange_and_add_dispatch
+
+
+Calls through to either of: +
__exchange_and_add
+
Multi-thread version. Inlined if compiler-generated builtin atomics +can be used, otherwise resolved at link time to a non-builtin code +sequence. +
__exchange_and_add_single
+
Single threaded version. Inlined.
However, only __exchange_and_add_dispatch
+and __atomic_add_dispatch
should be used. These functions
+can be used in a portable manner, regardless of the specific
+environment. They are carefully designed to provide optimum efficiency
+and speed, abstracting out atomic accesses when they are not required
+(even on hosts that support compiler intrinsics for atomic
+operations.)
+
+In addition, there are two macros +
+
+_GLIBCXX_READ_MEM_BARRIER
+
+
+
+_GLIBCXX_WRITE_MEM_BARRIER
+
+
+Which expand to the appropriate write and read barrier required by the +host hardware and operating system. +
+ Transforming C++ ABI identifiers (like RTTI symbols) into the + original C++ source identifiers is called + “demangling.” +
+ If you have read the source
+ documentation for namespace abi
then you are
+ aware of the cross-vendor C++ ABI in use by GCC. One of the
+ exposed functions is used for demangling,
+ abi::__cxa_demangle
.
+
+ In programs like c++filt, the linker, and other tools + have the ability to decode C++ ABI names, and now so can you. +
+ (The function itself might use different demanglers, but that's the + whole point of abstract interfaces. If we change the implementation, + you won't notice.) +
+ Probably the only times you'll be interested in demangling at runtime
+ are when you're seeing typeid
strings in RTTI, or when
+ you're handling the runtime-support exception classes. For example:
+
+#include <exception> +#include <iostream> +#include <cxxabi.h> + +struct empty { }; + +template <typename T, int N> + struct bar { }; + + +int main() +{ + int status; + char *realname; + + // exception classes not in <stdexcept>, thrown by the implementation + // instead of the user + std::bad_exception e; + realname = abi::__cxa_demangle(e.what(), 0, 0, &status); + std::cout << e.what() << "\t=> " << realname << "\t: " << status << '\n'; + free(realname); + + + // typeid + bar<empty,17> u; + const std::type_info &ti = typeid(u); + + realname = abi::__cxa_demangle(ti.name(), 0, 0, &status); + std::cout << ti.name() << "\t=> " << realname << "\t: " << status << '\n'; + free(realname); + + return 0; +} +
+ This prints +
+
+ St13bad_exception => std::bad_exception : 0
+ 3barI5emptyLi17EE => bar<empty, 17> : 0
+
+
+ The demangler interface is described in the source documentation + linked to above. It is actually written in C, so you don't need to + be writing C++ in order to demangle C++. (That also means we have to + use crummy memory management facilities, so don't forget to free() + the returned char array.) +
Table of Contents
+ Extensions allowing filebuf
s to be constructed from
+ "C" types like FILE*s and file descriptors.
+
The v2 library included non-standard extensions to construct
+ std::filebuf
s from C stdio types such as
+ FILE*
s and POSIX file descriptors.
+ Today the recommended way to use stdio types with libstdc++
+ IOStreams is via the stdio_filebuf
class (see below),
+ but earlier releases provided slightly different mechanisms.
+
3.0.x filebuf
s have another ctor with this signature:
+ basic_filebuf(__c_file_type*, ios_base::openmode, int_type);
+
+ This comes in very handy in a number of places, such as
+ attaching Unix sockets, pipes, and anything else which uses file
+ descriptors, into the IOStream buffering classes. The three
+ arguments are as follows:
+
__c_file_type* F
+ // the __c_file_type typedef usually boils down to stdio's FILE
+
ios_base::openmode M
+ // same as all the other uses of openmode
+
int_type B
+ // buffer size, defaults to BUFSIZ if not specified
+
+ For those wanting to use file descriptors instead of FILE*'s, I
+ invite you to contemplate the mysteries of C's fdopen()
.
+
In library snapshot 3.0.95 and later, filebuf
s bring
+ back an old extension: the fd()
member function. The
+ integer returned from this function can be used for whatever file
+ descriptors can be used for on your platform. Naturally, the
+ library cannot track what you do on your own with a file descriptor,
+ so if you perform any I/O directly, don't expect the library to be
+ aware of it.
+
Beginning with 3.1, the extra filebuf
constructor and
+ the fd()
function were removed from the standard
+ filebuf. Instead, <ext/stdio_filebuf.h>
contains
+ a derived class called
+ __gnu_cxx::stdio_filebuf
.
+ This class can be constructed from a C FILE*
or a file
+ descriptor, and provides the fd()
function.
+
If you want to access a filebuf
's file descriptor to
+ implement file locking (e.g. using the fcntl()
system
+ call) then you might be interested in Henry Suter's
+ RWLock
+ class.
+
+
24.3.2 describes struct iterator
, which didn't exist in the
+ original HP STL implementation (the language wasn't rich enough at the
+ time). For backwards compatibility, base classes are provided which
+ declare the same nested typedefs:
+
input_iterator
output_iterator
forward_iterator
bidirectional_iterator
random_access_iterator
24.3.4 describes iterator operation distance
, which takes
+ two iterators and returns a result. It is extended by another signature
+ which takes two iterators and a reference to a result. The result is
+ modified, and the function returns nothing.
+
26.4, the generalized numeric operations such as accumulate, are extended + with the following functions: +
+ power (x, n); + power (x, n, moniod_operation);
Returns, in FORTRAN syntax, "x ** n" where n>=0. In the + case of n == 0, returns the identity element for the + monoid operation. The two-argument signature uses multiplication (for + a true "power" implementation), but addition is supported as well. + The operation functor must be associative. +
The iota
function wins the award for Extension With the
+ Coolest Name. It "assigns sequentially increasing values to a range.
+ That is, it assigns value to *first, value + 1 to *(first + 1) and so
+ on." Quoted from SGI documentation.
+
+ void iota(_ForwardIter first, _ForwardIter last, _Tp value);
+ The <functional> header contains many additional functors + and helper functions, extending section 20.3. They are + implemented in the file stl_function.h: +
identity_element
for addition and multiplication. *
+
The functor identity
, whose operator()
+ returns the argument unchanged. *
+
Composition functors unary_function
and
+ binary_function
, and their helpers compose1
+ and compose2
. *
+
select1st
and select2nd
, to strip pairs. *
+
project1st
and project2nd
. *
A set of functors/functions which always return the same result. They
+ are constant_void_fun
, constant_binary_fun
,
+ constant_unary_fun
, constant0
,
+ constant1
, and constant2
. *
The class subtractive_rng
. *
mem_fun adaptor helpers mem_fun1
and
+ mem_fun1_ref
are provided for backwards compatibility.
+ 20.4.1 can use several different allocators; they are described on the + main extensions page. +
+ 20.4.3 is extended with a special version of
+ get_temporary_buffer
taking a second argument. The
+ argument is a pointer, which is ignored, but can be used to specify
+ the template type (instead of using explicit function template
+ arguments like the standard version does). That is, in addition to
+
+get_temporary_buffer<int>(5); +
+you can also use +
+get_temporary_buffer(5, (int*)0); +
+ A class temporary_buffer
is given in stl_tempbuf.h. *
+
+ The specialized algorithms of section 20.4.4 are extended with
+ uninitialized_copy_n
. *
+
Table of Contents
+For the required specialization codecvt<wchar_t, char, mbstate_t> , +conversions are made between the internal character set (always UCS4 +on GNU/Linux) and whatever the currently selected locale for the +LC_CTYPE category implements. +
+The two required specializations are implemented as follows: +
+
+ctype<char>
+
+
+This is simple specialization. Implementing this was a piece of cake. +
+
+ctype<wchar_t>
+
+
+This specialization, by specifying all the template parameters, pretty +much ties the hands of implementors. As such, the implementation is +straightforward, involving mcsrtombs for the conversions between char +to wchar_t and wcsrtombs for conversions between wchar_t and char. +
+Neither of these two required specializations deals with Unicode +characters. +
+ How to deal with the global locale issue? +
+ How to deal with different types than char, wchar_t?
+ Overlap between codecvt/ctype: narrow/widen +
+ Mask typedef in codecvt_base, argument types in codecvt. what + is know about this type? +
+ Why mask* argument in codecvt? +
+ Can this be made (more) generic? is there a simple way to + straighten out the configure-time mess that is a by-product of + this class? +
+ Get the ctype<wchar_t>::mask stuff under control. Need to + make some kind of static table, and not do lookup every time + somebody hits the do_is... functions. Too bad we can't just + redefine mask for ctype<wchar_t> +
+ Rename abstract base class. See if just smash-overriding is a + better approach. Clarify, add sanity to naming. +
+ The GNU C Library + . Copyright © 2007 FSF. Chapters 6 Character Set Handling and 7 Locales and Internationalization.
+ System Interface Definitions, Issue 6 (IEEE Std. 1003.1-200x) + . Copyright © 1999 + The Open Group/The Institute of Electrical and Electronics Engineers, Inc.. + + + .
Table of Contents
+
So you want to copy a file quickly and easily, and most important, + completely portably. And since this is C++, you have an open + ifstream (call it IN) and an open ofstream (call it OUT): +
+ #include <fstream> + + std::ifstream IN ("input_file"); + std::ofstream OUT ("output_file");
Here's the easiest way to get it completely wrong: +
+ OUT << IN;
For those of you who don't already know why this doesn't work + (probably from having done it before), I invite you to quickly + create a simple text file called "input_file" containing + the sentence +
+ The quick brown fox jumped over the lazy dog.
surrounded by blank lines. Code it up and try it. The contents + of "output_file" may surprise you. +
Seriously, go do it. Get surprised, then come back. It's worth it. +
The thing to remember is that the basic_[io]stream
classes
+ handle formatting, nothing else. In particular, they break up on
+ whitespace. The actual reading, writing, and storing of data is
+ handled by the basic_streambuf
family. Fortunately, the
+ operator<<
is overloaded to take an ostream and
+ a pointer-to-streambuf, in order to help with just this kind of
+ "dump the data verbatim" situation.
+
Why a pointer to streambuf and not just a streambuf? Well,
+ the [io]streams hold pointers (or references, depending on the
+ implementation) to their buffers, not the actual
+ buffers. This allows polymorphic behavior on the part of the buffers
+ as well as the streams themselves. The pointer is easily retrieved
+ using the rdbuf()
member function. Therefore, the easiest
+ way to copy the file is:
+
+ OUT << IN.rdbuf();
So what was happening with OUT<<IN? Undefined + behavior, since that particular << isn't defined by the Standard. + I have seen instances where it is implemented, but the character + extraction process removes all the whitespace, leaving you with no + blank lines and only "Thequickbrownfox...". With + libraries that do not define that operator, IN (or one of IN's + member pointers) sometimes gets converted to a void*, and the output + file then contains a perfect text representation of a hexadecimal + address (quite a big surprise). Others don't compile at all. +
Also note that none of this is specific to o*f*streams. + The operators shown above are all defined in the parent + basic_ostream class and are therefore available with all possible + descendants. +
If you don't know what functors are, you're not alone. Many people + get slightly the wrong idea. In the interest of not reinventing + the wheel, we will refer you to the introduction to the functor + concept written by SGI as part of their STL, in + their + http://www.sgi.com/tech/stl/functors.html. +
Table of Contents
+ C++ has the following builtin types: +
+ char +
+ signed char +
+ unsigned char +
+ signed short +
+ signed int +
+ signed long +
+ unsigned short +
+ unsigned int +
+ unsigned long +
+ bool +
+ wchar_t +
+ float +
+ double +
+ long double +
+ These fundamental types are always available, without having to + include a header file. These types are exactly the same in + either C++ or in C. +
+ Specializing parts of the library on these types is prohibited: + instead, use a POD. +
+
There are four generalized functions in the <numeric> header + that follow the same conventions as those in <algorithm>. Each + of them is overloaded: one signature for common default operations, + and a second for fully general operations. Their names are + self-explanatory to anyone who works with numerics on a regular basis: +
accumulate
inner_product
partial_sum
adjacent_difference
Here is a simple example of the two forms of accumulate
.
+
+ int ar[50]; + int someval = somefunction(); + + // ...initialize members of ar to something... + + int sum = std::accumulate(ar,ar+50,0); + int sum_stuff = std::accumulate(ar,ar+50,someval); + int product = std::accumulate(ar,ar+50,1,std::multiplies<int>()); +
The first call adds all the members of the array, using zero as an
+ initial value for sum
. The second does the same, but uses
+ someval
as the starting value (thus, sum_stuff == sum +
+ someval
). The final call uses the second of the two signatures,
+ and multiplies all the members of the array; here we must obviously
+ use 1 as a starting value instead of 0.
+
The other three functions have similar dual-signature forms. +
+
This document explains how to port libstdc++ (the GNU C++ library) to a new target.
In order to make the GNU C++ library (libstdc++) work with a new
@@ -365,4 +368,7 @@ do this is to build the library using gcc -shared
.
ltcf-c.sh
in the top-level directory. Find the switch statement
that sets archive_cmds
. Here, adjust the setting for your
operating system.
-
Table of Contents
+ See the extensions for using
+ FILE and file descriptors with
+ ofstream
and
+ ifstream
.
+
To minimize the time you have to wait on the compiler, it's good to + only include the headers you really need. Many people simply include + <iostream> when they don't need to -- and that can penalize + your runtime as well. Here are some tips on which header to use + for which situations, starting with the simplest. +
<iosfwd> should be included whenever you simply + need the name of an I/O-related class, such as + "ofstream" or "basic_streambuf". Like the name + implies, these are forward declarations. (A word to all you fellow + old school programmers: trying to forward declare classes like + "class istream;" won't work. Look in the iosfwd header if + you'd like to know why.) For example, +
+ #include <iosfwd> + + class MyClass + { + .... + std::ifstream& input_file; + }; + + extern std::ostream& operator<< (std::ostream&, MyClass&); +
<ios> declares the base classes for the entire + I/O stream hierarchy, std::ios_base and std::basic_ios<charT>, the + counting types std::streamoff and std::streamsize, the file + positioning type std::fpos, and the various manipulators like + std::hex, std::fixed, std::noshowbase, and so forth. +
The ios_base class is what holds the format flags, the state flags, + and the functions which change them (setf(), width(), precision(), + etc). You can also store extra data and register callback functions + through ios_base, but that has been historically underused. Anything + which doesn't depend on the type of characters stored is consolidated + here. +
The template class basic_ios is the highest template class in the + hierarchy; it is the first one depending on the character type, and + holds all general state associated with that type: the pointer to the + polymorphic stream buffer, the facet information, etc. +
<streambuf> declares the template class + basic_streambuf, and two standard instantiations, streambuf and + wstreambuf. If you need to work with the vastly useful and capable + stream buffer classes, e.g., to create a new form of storage + transport, this header is the one to include. +
<istream>/<ostream> are + the headers to include when you are using the >>/<< + interface, or any of the other abstract stream formatting functions. + For example, +
+ #include <istream> + + std::ostream& operator<< (std::ostream& os, MyClass& c) + { + return os << c.data1() << c.data2(); + } +
The std::istream and std::ostream classes are the abstract parents of + the various concrete implementations. If you are only using the + interfaces, then you only need to use the appropriate interface header. +
<iomanip> provides "extractors and inserters
+ that alter information maintained by class ios_base and its derived
+ classes," such as std::setprecision and std::setw. If you need
+ to write expressions like os << setw(3);
or
+ is >> setbase(8);
, you must include <iomanip>.
+
<sstream>/<fstream> + declare the six stringstream and fstream classes. As they are the + standard concrete descendants of istream and ostream, you will already + know about them. +
Finally, <iostream> provides the eight standard + global objects (cin, cout, etc). To do this correctly, this header + also provides the contents of the <istream> and <ostream> + headers, but nothing else. The contents of this header look like +
+ #include <ostream>
+ #include <istream>
+
+ namespace std
+ {
+ extern istream cin;
+ extern ostream cout;
+ ....
+
+ // this is explained below
+ static ios_base::Init __foo; // not its real name
+ }
+
Now, the runtime penalty mentioned previously: the global objects + must be initialized before any of your own code uses them; this is + guaranteed by the standard. Like any other global object, they must + be initialized once and only once. This is typically done with a + construct like the one above, and the nested class ios_base::Init is + specified in the standard for just this reason. +
How does it work? Because the header is included before any of your + code, the __foo object is constructed before any of + your objects. (Global objects are built in the order in which they + are declared, and destroyed in reverse order.) The first time the + constructor runs, the eight stream objects are set up. +
The static
keyword means that each object file compiled
+ from a source file containing <iostream> will have its own
+ private copy of __foo. There is no specified order
+ of construction across object files (it's one of those pesky NP
+ problems that make life so interesting), so one copy in each object
+ file means that the stream objects are guaranteed to be set up before
+ any of your code which uses them could run, thereby meeting the
+ requirements of the standard.
+
The penalty, of course, is that after the first copy of + __foo is constructed, all the others are just wasted + processor time. The time spent is merely for an increment-and-test + inside a function call, but over several dozen or hundreds of object + files, that time can add up. (It's not in a tight loop, either.) +
The lesson? Only include <iostream> when you need to use one of + the standard objects in that source file; you'll pay less startup + time. Only include the header files you need to in general; your + compile times will go down when there's less parsing work to do. +
Table of Contents
Table of Contents
+ There are two licenses affecting GNU libstdc++: one for the code, + and one for the documentation. +
+ There is a license section in the FAQ regarding common questions. If you have more + questions, ask the FSF or the gcc mailing list. +
+ The source code is distributed under the GNU General Public License version 3, + with the addition under section 7 of an exception described in + the “GCC Runtime Library Exception, version 3.1” + as follows (or see the file COPYING.RUNTIME): +
+GCC RUNTIME LIBRARY EXCEPTION
+
+Version 3.1, 31 March 2009
+
+Copyright (C) 2009 Free Software Foundation, Inc.
+
+Everyone is permitted to copy and distribute verbatim copies of this
+license document, but changing it is not allowed.
+
+This GCC Runtime Library Exception ("Exception") is an additional
+permission under section 7 of the GNU General Public License, version
+3 ("GPLv3"). It applies to a given file (the "Runtime Library") that
+bears a notice placed by the copyright holder of the file stating that
+the file is governed by GPLv3 along with this Exception.
+
+When you use GCC to compile a program, GCC may combine portions of
+certain GCC header files and runtime libraries with the compiled
+program. The purpose of this Exception is to allow compilation of
+non-GPL (including proprietary) programs to use, in this way, the
+header files and runtime libraries covered by this Exception.
+
+0. Definitions.
+
+A file is an "Independent Module" if it either requires the Runtime
+Library for execution after a Compilation Process, or makes use of an
+interface provided by the Runtime Library, but is not otherwise based
+on the Runtime Library.
+
+"GCC" means a version of the GNU Compiler Collection, with or without
+modifications, governed by version 3 (or a specified later version) of
+the GNU General Public License (GPL) with the option of using any
+subsequent versions published by the FSF.
+
+"GPL-compatible Software" is software whose conditions of propagation,
+modification and use would permit combination with GCC in accord with
+the license of GCC.
+
+"Target Code" refers to output from any compiler for a real or virtual
+target processor architecture, in executable form or suitable for
+input to an assembler, loader, linker and/or execution
+phase. Notwithstanding that, Target Code does not include data in any
+format that is used as a compiler intermediate representation, or used
+for producing a compiler intermediate representation.
+
+The "Compilation Process" transforms code entirely represented in
+non-intermediate languages designed for human-written code, and/or in
+Java Virtual Machine byte code, into Target Code. Thus, for example,
+use of source code generators and preprocessors need not be considered
+part of the Compilation Process, since the Compilation Process can be
+understood as starting with the output of the generators or
+preprocessors.
+
+A Compilation Process is "Eligible" if it is done using GCC, alone or
+with other GPL-compatible software, or if it is done without using any
+work based on GCC. For example, using non-GPL-compatible Software to
+optimize any GCC intermediate representations would not qualify as an
+Eligible Compilation Process.
+
+1. Grant of Additional Permission.
+
+You have permission to propagate a work of Target Code formed by
+combining the Runtime Library with Independent Modules, even if such
+propagation would otherwise violate the terms of GPLv3, provided that
+all Target Code was generated by Eligible Compilation Processes. You
+may then convey such a combination under terms of your choice,
+consistent with the licensing of the Independent Modules.
+
+2. No Weakening of GCC Copyleft.
+
+The availability of this Exception does not imply any general
+presumption that third-party software is unaffected by the copyleft
+requirements of the license of GCC.
+
+ Hopefully that text is self-explanatory. If it isn't, you need to speak + to your lawyer, or the Free Software Foundation. +
+ The documentation shipped with the library and made available over + the web, excluding the pages generated from source comments, are + copyrighted by the Free Software Foundation, and placed under the + GNU Free Documentation + License version 1.2. There are no Front-Cover Texts, no + Back-Cover Texts, and no Invariant Sections. +
+ For documentation generated by doxygen or other automated tools + via processing source code comments and markup, the original source + code license applies to the generated files. Thus, the doxygen + documents are licensed GPL. +
+ If you plan on making copies of the documentation, please let us know. + We can probably offer suggestions. +
Table of Contents
+Describes the basic locale object, including nested +classes id, facet, and the reference-counted implementation object, +class _Impl. +
+Class locale is non-templatized and has two distinct types nested +inside of it: +
+ +class facet +22.1.1.1.2 Class locale::facet + +
+Facets actually implement locale functionality. For instance, a facet +called numpunct is the data objects that can be used to query for the +thousands separator is in the German locale. +
+Literally, a facet is strictly defined: +
+ Containing the following public data member: +
+ static locale::id id;
+
+ Derived from another facet: +
+ class gnu_codecvt: public std::ctype<user-defined-type>
+
+Of interest in this class are the memory management options explicitly +specified as an argument to facet's constructor. Each constructor of a +facet class takes a std::size_t __refs argument: if __refs == 0, the +facet is deleted when the locale containing it is destroyed. If __refs +== 1, the facet is not destroyed, even when it is no longer +referenced. +
+ +class id +22.1.1.1.3 - Class locale::id + +
+Provides an index for looking up specific facets. +
+The major design challenge is fitting an object-orientated and +non-global locale design on top of POSIX and other relevant standards, +which include the Single Unix (nee X/Open.) +
+Because C and earlier versions of POSIX fall down so completely, +portability is an issue. +
+ `locale -a`
displays available locales.
+
+af_ZA +ar_AE +ar_AE.utf8 +ar_BH +ar_BH.utf8 +ar_DZ +ar_DZ.utf8 +ar_EG +ar_EG.utf8 +ar_IN +ar_IQ +ar_IQ.utf8 +ar_JO +ar_JO.utf8 +ar_KW +ar_KW.utf8 +ar_LB +ar_LB.utf8 +ar_LY +ar_LY.utf8 +ar_MA +ar_MA.utf8 +ar_OM +ar_OM.utf8 +ar_QA +ar_QA.utf8 +ar_SA +ar_SA.utf8 +ar_SD +ar_SD.utf8 +ar_SY +ar_SY.utf8 +ar_TN +ar_TN.utf8 +ar_YE +ar_YE.utf8 +be_BY +be_BY.utf8 +bg_BG +bg_BG.utf8 +br_FR +bs_BA +C +ca_ES +ca_ES@euro +ca_ES.utf8 +ca_ES.utf8@euro +cs_CZ +cs_CZ.utf8 +cy_GB +da_DK +da_DK.iso885915 +da_DK.utf8 +de_AT +de_AT@euro +de_AT.utf8 +de_AT.utf8@euro +de_BE +de_BE@euro +de_BE.utf8 +de_BE.utf8@euro +de_CH +de_CH.utf8 +de_DE +de_DE@euro +de_DE.utf8 +de_DE.utf8@euro +de_LU +de_LU@euro +de_LU.utf8 +de_LU.utf8@euro +el_GR +el_GR.utf8 +en_AU +en_AU.utf8 +en_BW +en_BW.utf8 +en_CA +en_CA.utf8 +en_DK +en_DK.utf8 +en_GB +en_GB.iso885915 +en_GB.utf8 +en_HK +en_HK.utf8 +en_IE +en_IE@euro +en_IE.utf8 +en_IE.utf8@euro +en_IN +en_NZ +en_NZ.utf8 +en_PH +en_PH.utf8 +en_SG +en_SG.utf8 +en_US +en_US.iso885915 +en_US.utf8 +en_ZA +en_ZA.utf8 +en_ZW +en_ZW.utf8 +es_AR +es_AR.utf8 +es_BO +es_BO.utf8 +es_CL +es_CL.utf8 +es_CO +es_CO.utf8 +es_CR +es_CR.utf8 +es_DO +es_DO.utf8 +es_EC +es_EC.utf8 +es_ES +es_ES@euro +es_ES.utf8 +es_ES.utf8@euro +es_GT +es_GT.utf8 +es_HN +es_HN.utf8 +es_MX +es_MX.utf8 +es_NI +es_NI.utf8 +es_PA +es_PA.utf8 +es_PE +es_PE.utf8 +es_PR +es_PR.utf8 +es_PY +es_PY.utf8 +es_SV +es_SV.utf8 +es_US +es_US.utf8 +es_UY +es_UY.utf8 +es_VE +es_VE.utf8 +et_EE +et_EE.utf8 +eu_ES +eu_ES@euro +eu_ES.utf8 +eu_ES.utf8@euro +fa_IR +fi_FI +fi_FI@euro +fi_FI.utf8 +fi_FI.utf8@euro +fo_FO +fo_FO.utf8 +fr_BE +fr_BE@euro +fr_BE.utf8 +fr_BE.utf8@euro +fr_CA +fr_CA.utf8 +fr_CH +fr_CH.utf8 +fr_FR +fr_FR@euro +fr_FR.utf8 +fr_FR.utf8@euro +fr_LU +fr_LU@euro +fr_LU.utf8 +fr_LU.utf8@euro +ga_IE +ga_IE@euro +ga_IE.utf8 +ga_IE.utf8@euro +gl_ES +gl_ES@euro +gl_ES.utf8 +gl_ES.utf8@euro +gv_GB +gv_GB.utf8 +he_IL +he_IL.utf8 +hi_IN +hr_HR +hr_HR.utf8 +hu_HU +hu_HU.utf8 +id_ID +id_ID.utf8 +is_IS +is_IS.utf8 +it_CH +it_CH.utf8 +it_IT +it_IT@euro +it_IT.utf8 +it_IT.utf8@euro +iw_IL +iw_IL.utf8 +ja_JP.eucjp +ja_JP.utf8 +ka_GE +kl_GL +kl_GL.utf8 +ko_KR.euckr +ko_KR.utf8 +kw_GB +kw_GB.utf8 +lt_LT +lt_LT.utf8 +lv_LV +lv_LV.utf8 +mi_NZ +mk_MK +mk_MK.utf8 +mr_IN +ms_MY +ms_MY.utf8 +mt_MT +mt_MT.utf8 +nl_BE +nl_BE@euro +nl_BE.utf8 +nl_BE.utf8@euro +nl_NL +nl_NL@euro +nl_NL.utf8 +nl_NL.utf8@euro +nn_NO +nn_NO.utf8 +no_NO +no_NO.utf8 +oc_FR +pl_PL +pl_PL.utf8 +POSIX +pt_BR +pt_BR.utf8 +pt_PT +pt_PT@euro +pt_PT.utf8 +pt_PT.utf8@euro +ro_RO +ro_RO.utf8 +ru_RU +ru_RU.koi8r +ru_RU.utf8 +ru_UA +ru_UA.utf8 +se_NO +sk_SK +sk_SK.utf8 +sl_SI +sl_SI.utf8 +sq_AL +sq_AL.utf8 +sr_YU +sr_YU@cyrillic +sr_YU.utf8 +sr_YU.utf8@cyrillic +sv_FI +sv_FI@euro +sv_FI.utf8 +sv_FI.utf8@euro +sv_SE +sv_SE.iso885915 +sv_SE.utf8 +ta_IN +te_IN +tg_TJ +th_TH +th_TH.utf8 +tl_PH +tr_TR +tr_TR.utf8 +uk_UA +uk_UA.utf8 +ur_PK +uz_UZ +vi_VN +vi_VN.tcvn +wa_BE +wa_BE@euro +yi_US +zh_CN +zh_CN.gb18030 +zh_CN.gbk +zh_CN.utf8 +zh_HK +zh_HK.utf8 +zh_TW +zh_TW.euctw +zh_TW.utf8 +
+ `locale`
displays environmental variables that
+ impact how locale("") will be deduced.
+
+LANG=en_US +LC_CTYPE="en_US" +LC_NUMERIC="en_US" +LC_TIME="en_US" +LC_COLLATE="en_US" +LC_MONETARY="en_US" +LC_MESSAGES="en_US" +LC_PAPER="en_US" +LC_NAME="en_US" +LC_ADDRESS="en_US" +LC_TELEPHONE="en_US" +LC_MEASUREMENT="en_US" +LC_IDENTIFICATION="en_US" +LC_ALL= +
+From Josuttis, p. 697-698, which says, that "there is only *one* +relation (of the C++ locale mechanism) to the C locale mechanism: the +global C locale is modified if a named C++ locale object is set as the +global locale" (emphasis Paolo), that is: +
std::locale::global(std::locale(""));
affects the C functions as if the following call was made:
std::setlocale(LC_ALL, "");
+ On the other hand, there is *no* vice versa, that is, calling + setlocale has *no* whatsoever on the C++ locale mechanism, in + particular on the working of locale(""), which constructs the locale + object from the environment of the running program, that is, in + practice, the set of LC_ALL, LANG, etc. variable of the shell. +
+ Locale initialization: at what point does _S_classic, _S_global + get initialized? Can named locales assume this initialization + has already taken place? +
+ Document how named locales error check when filling data + members. I.e., a fr_FR locale that doesn't have + numpunct::truename(): does it use "true"? Or is it a blank + string? What's the convention? +
+ Explain how locale aliasing happens. When does "de_DE" use "de" + information? What is the rule for locales composed of just an + ISO language code (say, "de") and locales with both an ISO + language code and ISO country code (say, "de_DE"). +
+ What should non-required facet instantiations do? If the + generic implementation is provided, then how to end-users + provide specializations? +
+ The GNU C Library + . Copyright © 2007 FSF. Chapters 6 Character Set Handling and 7 Locales and Internationalization.
+ System Interface Definitions, Issue 6 (IEEE Std. 1003.1-200x) + . Copyright © 1999 + The Open Group/The Institute of Electrical and Electronics Engineers, Inc.. + + + .
If you have never done this before, you should read the basic + GCC Installation + Instructions first. Read all of them. + Twice. +
Then type:make, and congratulations, you're +started to build. +
Table of Contents
+ Memory contains three general areas. First, function and operator
+ calls via new
and delete
+ operator or member function calls. Second, allocation via
+ allocator
. And finally, smart pointer and
+ intelligent pointer abstractions.
+
+ Memory management for Standard Library entities is encapsulated in a
+ class template called allocator
. The
+ allocator
abstraction is used throughout the
+ library in string
, container classes,
+ algorithms, and parts of iostreams. This class, and base classes of
+ it, are the superset of available free store (“heap”)
+ management classes.
+
+ The C++ standard only gives a few directives in this area: +
+ When you add elements to a container, and the container must + allocate more memory to hold them, the container makes the + request via its Allocator template + parameter, which is usually aliased to + allocator_type. This includes adding chars + to the string class, which acts as a regular STL container in + this respect. +
+ The default Allocator argument of every
+ container-of-T is allocator<T>
.
+
+ The interface of the allocator<T>
class is
+ extremely simple. It has about 20 public declarations (nested
+ typedefs, member functions, etc), but the two which concern us most
+ are:
+
+ T* allocate (size_type n, const void* hint = 0); + void deallocate (T* p, size_type n); +
+ The n
arguments in both those
+ functions is a count of the number of
+ T's to allocate space for, not their
+ total size.
+ (This is a simplification; the real signatures use nested typedefs.)
+
+ The storage is obtained by calling ::operator
+ new
, but it is unspecified when or how
+ often this function is called. The use of the
+ hint
is unspecified, but intended as an
+ aid to locality if an implementation so
+ desires. [20.4.1.1]/6
+
+ Complete details cam be found in the C++ standard, look in
+ [20.4 Memory]
.
+
+ The easiest way of fulfilling the requirements is to call
+ operator new
each time a container needs
+ memory, and to call operator delete
each time
+ the container releases memory. This method may be slower
+ than caching the allocations and re-using previously-allocated
+ memory, but has the advantage of working correctly across a wide
+ variety of hardware and operating systems, including large
+ clusters. The __gnu_cxx::new_allocator
+ implements the simple operator new and operator delete semantics,
+ while __gnu_cxx::malloc_allocator
+ implements much the same thing, only with the C language functions
+ std::malloc
and free
.
+
+ Another approach is to use intelligence within the allocator
+ class to cache allocations. This extra machinery can take a variety
+ of forms: a bitmap index, an index into an exponentially increasing
+ power-of-two-sized buckets, or simpler fixed-size pooling cache.
+ The cache is shared among all the containers in the program: when
+ your program's std::vector<int>
gets
+ cut in half and frees a bunch of its storage, that memory can be
+ reused by the private
+ std::list<WonkyWidget>
brought in from
+ a KDE library that you linked against. And operators
+ new
and delete
are not
+ always called to pass the memory on, either, which is a speed
+ bonus. Examples of allocators that use these techniques are
+ __gnu_cxx::bitmap_allocator
,
+ __gnu_cxx::pool_allocator
, and
+ __gnu_cxx::__mt_alloc
.
+
+ Depending on the implementation techniques used, the underlying
+ operating system, and compilation environment, scaling caching
+ allocators can be tricky. In particular, order-of-destruction and
+ order-of-creation for memory pools may be difficult to pin down
+ with certainty, which may create problems when used with plugins
+ or loading and unloading shared objects in memory. As such, using
+ caching allocators on systems that do not support
+ abi::__cxa_atexit
is not recommended.
+
+ The only allocator interface that + is support is the standard C++ interface. As such, all STL + containers have been adjusted, and all external allocators have + been modified to support this change. +
+ The class allocator
just has typedef,
+ constructor, and rebind members. It inherits from one of the
+ high-speed extension allocators, covered below. Thus, all
+ allocation and deallocation depends on the base class.
+
+ The base class that allocator
is derived from
+ may not be user-configurable.
+
+ It's difficult to pick an allocation strategy that will provide + maximum utility, without excessively penalizing some behavior. In + fact, it's difficult just deciding which typical actions to measure + for speed. +
+ Three synthetic benchmarks have been created that provide data + that is used to compare different C++ allocators. These tests are: +
+ Insertion. +
+ Over multiple iterations, various STL container + objects have elements inserted to some maximum amount. A variety + of allocators are tested. + Test source for sequence + and associative + containers. +
+ Insertion and erasure in a multi-threaded environment. +
+ This test shows the ability of the allocator to reclaim memory + on a pre-thread basis, as well as measuring thread contention + for memory resources. + Test source + here. +
+ A threaded producer/consumer model. +
+ Test source for + sequence + and + associative + containers. +
+ The current default choice for
+ allocator
is
+ __gnu_cxx::new_allocator
.
+
+ In use, allocator
may allocate and
+ deallocate using implementation-specified strategies and
+ heuristics. Because of this, every call to an allocator object's
+ allocate
member function may not actually
+ call the global operator new. This situation is also duplicated
+ for calls to the deallocate
member
+ function.
+
+ This can be confusing. +
+ In particular, this can make debugging memory errors more
+ difficult, especially when using third party tools like valgrind or
+ debug versions of new
.
+
+ There are various ways to solve this problem. One would be to use
+ a custom allocator that just called operators
+ new
and delete
+ directly, for every allocation. (See
+ include/ext/new_allocator.h
, for instance.)
+ However, that option would involve changing source code to use
+ a non-default allocator. Another option is to force the
+ default allocator to remove caching and pools, and to directly
+ allocate with every call of allocate
and
+ directly deallocate with every call of
+ deallocate
, regardless of efficiency. As it
+ turns out, this last option is also available.
+
+ To globally disable memory caching within the library for the
+ default allocator, merely set
+ GLIBCXX_FORCE_NEW
(with any value) in the
+ system's environment before running the program. If your program
+ crashes with GLIBCXX_FORCE_NEW
in the
+ environment, it likely means that you linked against objects
+ built against the older library (objects which might still using the
+ cached allocations...).
+
+ You can specify different memory management schemes on a
+ per-container basis, by overriding the default
+ Allocator template parameter. For example, an easy
+ (but non-portable) method of specifying that only malloc
or free
+ should be used instead of the default node allocator is:
+
+ std::list <int, __gnu_cxx::malloc_allocator<int> > malloc_list;
+ Likewise, a debugging form of whichever allocator is currently in use: +
+ std::deque <int, __gnu_cxx::debug_allocator<std::allocator<int> > > debug_deque; +
+ Writing a portable C++ allocator would dictate that the interface
+ would look much like the one specified for
+ allocator
. Additional member functions, but
+ not subtractions, would be permissible.
+
+ Probably the best place to start would be to copy one of the
+ extension allocators: say a simple one like
+ new_allocator
.
+
+ Several other allocators are provided as part of this + implementation. The location of the extension allocators and their + names have changed, but in all cases, functionality is + equivalent. Starting with gcc-3.4, all extension allocators are + standard style. Before this point, SGI style was the norm. Because of + this, the number of template arguments also changed. Here's a simple + chart to track the changes. +
+ More details on each of these extension allocators follows. +
+ new_allocator
+
+ Simply wraps ::operator new
+ and ::operator delete
.
+
+ malloc_allocator
+
+ Simply wraps malloc
and
+ free
. There is also a hook for an
+ out-of-memory handler (for
+ new
/delete
this is
+ taken care of elsewhere).
+
+ array_allocator
+
+ Allows allocations of known and fixed sizes using existing
+ global or external storage allocated via construction of
+ std::tr1::array
objects. By using this
+ allocator, fixed size containers (including
+ std::string
) can be used without
+ instances calling ::operator new
and
+ ::operator delete
. This capability
+ allows the use of STL abstractions without runtime
+ complications or overhead, even in situations such as program
+ startup. For usage examples, please consult the testsuite.
+
+ debug_allocator
+
+ A wrapper around an arbitrary allocator A. It passes on
+ slightly increased size requests to A, and uses the extra
+ memory to store size information. When a pointer is passed
+ to deallocate()
, the stored size is
+ checked, and assert()
is used to
+ guarantee they match.
+
+ throw_allocator
+
+ Includes memory tracking and marking abilities as well as hooks for + throwing exceptions at configurable intervals (including random, + all, none). +
+ __pool_alloc
+
+ A high-performance, single pool allocator. The reusable
+ memory is shared among identical instantiations of this type.
+ It calls through ::operator new
to
+ obtain new memory when its lists run out. If a client
+ container requests a block larger than a certain threshold
+ size, then the pool is bypassed, and the allocate/deallocate
+ request is passed to ::operator new
+ directly.
+
+ Older versions of this class take a boolean template
+ parameter, called thr
, and an integer template
+ parameter, called inst
.
+
+ The inst
number is used to track additional memory
+ pools. The point of the number is to allow multiple
+ instantiations of the classes without changing the semantics at
+ all. All three of
+
+ typedef __pool_alloc<true,0> normal; + typedef __pool_alloc<true,1> private; + typedef __pool_alloc<true,42> also_private; +
+ behave exactly the same way. However, the memory pool for each type + (and remember that different instantiations result in different types) + remains separate. +
+ The library uses 0 in all its instantiations. If you + wish to keep separate free lists for a particular purpose, use a + different number. +
The thr
boolean determines whether the
+ pool should be manipulated atomically or not. When
+ thr
= true
, the allocator
+ is is thread-safe, while thr
=
+ false
, and is slightly faster but unsafe for
+ multiple threads.
+
+ For thread-enabled configurations, the pool is locked with a + single big lock. In some situations, this implementation detail + may result in severe performance degradation. +
+ (Note that the GCC thread abstraction layer allows us to provide + safe zero-overhead stubs for the threading routines, if threads + were disabled at configuration time.) +
+ __mt_alloc
+
+ A high-performance fixed-size allocator with + exponentially-increasing allocations. It has its own + documentation, found here. +
+ bitmap_allocator
+
+ A high-performance allocator that uses a bit-map to keep track + of the used and unused memory locations. It has its own + documentation, found here. +
The Standard Librarian: What Are Allocators Good + . + austernm + + C/C++ Users Journal + . + + + .
The Hoard Memory Allocator. + emeryb + + + + .
Reconsidering Custom Memory Allocation. + bergerzorn + Copyright © 2002 OOPSLA. + + + .
Allocator Types. + kreftlanger + + C/C++ Users Journal + . + + + .
Yalloc: A Recycling C++ Allocator. + yenf + Copyright © . + + + .
+
The std::messages facet implements message retrieval functionality equivalent to Java's java.text.MessageFormat .using either GNU gettext or IEEE 1003.1-200 functions. @@ -241,41 +241,44 @@ void test01() model. As of this writing, it is unknown how to query to see if a specified message catalog exists using the gettext package. -
The GNU C Library . Copyright © 2007 FSF. Chapters 6 Character Set Handling, and 7 Locales and Internationalization - .
System Interface Definitions, Issue 6 (IEEE Std. 1003.1-200x) . Copyright © 1999 The Open Group/The Institute of Electrical and Electronics Engineers, Inc.. - .
The C++ Programming Language, Special Edition . Copyright © 2000 Addison Wesley, Inc.. Appendix D. Addison Wesley - .
Standard C++ IOStreams and Locales . Advanced Programmer's Guide and Reference . Copyright © 2000 Addison Wesley Longman, Inc.. Addison Wesley Longman - .
Table of Contents
One of the major reasons why FORTRAN can chew through numbers so well
+ is that it is defined to be free of pointer aliasing, an assumption
+ that C89 is not allowed to make, and neither is C++98. C99 adds a new
+ keyword, restrict
, to apply to individual pointers. The
+ C++ solution is contained in the library rather than the language
+ (although many vendors can be expected to add this to their compilers
+ as an extension).
+
That library solution is a set of two classes, five template classes,
+ and "a whole bunch" of functions. The classes are required
+ to be free of pointer aliasing, so compilers can optimize the
+ daylights out of them the same way that they have been for FORTRAN.
+ They are collectively called valarray
, although strictly
+ speaking this is only one of the five template classes, and they are
+ designed to be familiar to people who have worked with the BLAS
+ libraries before.
+
The pair<T1,T2>
is a simple and handy way to
+ carry around a pair of objects. One is of type T1, and another of
+ type T2; they may be the same type, but you don't get anything
+ extra if they are. The two members can be accessed directly, as
+ .first
and .second
.
+
Construction is simple. The default ctor initializes each member + with its respective default ctor. The other simple ctor, +
+ pair (const T1& x, const T2& y); +
does what you think it does, first
getting x
+ and second
getting y
.
+
There is a copy constructor, but it requires that your compiler + handle member function templates: +
+ template <class U, class V> pair (const pair<U,V>& p); +
The compiler will convert as necessary from U to T1 and from + V to T2 in order to perform the respective initializations. +
The comparison operators are done for you. Equality
+ of two pair<T1,T2>
s is defined as both first
+ members comparing equal and both second
members comparing
+ equal; this simply delegates responsibility to the respective
+ operator==
functions (for types like MyClass) or builtin
+ comparisons (for types like int, char, etc).
+
+ The less-than operator is a bit odd the first time you see it. It + is defined as evaluating to: +
+ x.first < y.first || + ( !(y.first < x.first) && x.second < y.second ) +
The other operators are not defined using the rel_ops
+ functions above, but their semantics are the same.
+
Finally, there is a template function called make_pair
+ that takes two references-to-const objects and returns an
+ instance of a pair instantiated on their respective types:
+
+ pair<int,MyClass> p = make_pair(4,myobject); +
Table of Contents
The libstdc++ parallel mode is an experimental parallel +
Table of Contents
The libstdc++ parallel mode is an experimental parallel implementation of many algorithms the C++ Standard Library.
Several of the standard algorithms, for instance @@ -10,11 +13,11 @@ explicit source declaration or by compiling existing sources with a specific compiler flag.
The following library components in the include
numeric
are included in the parallel mode:
std::accumulate
std::adjacent_difference
std::inner_product
std::partial_sum
The following library components in the include
-algorithm
are included in the parallel mode:
std::adjacent_find
std::count
std::count_if
std::equal
std::find
std::find_if
std::find_first_of
std::for_each
std::generate
std::generate_n
std::lexicographical_compare
std::mismatch
std::search
std::search_n
std::transform
std::replace
std::replace_if
std::max_element
std::merge
std::min_element
std::nth_element
std::partial_sort
std::partition
std::random_shuffle
std::set_union
std::set_intersection
std::set_symmetric_difference
std::set_difference
std::sort
std::stable_sort
std::unique_copy
+algorithm
are included in the parallel mode:
std::adjacent_find
std::count
std::count_if
std::equal
std::find
std::find_if
std::find_first_of
std::for_each
std::generate
std::generate_n
std::lexicographical_compare
std::mismatch
std::search
std::search_n
std::transform
std::replace
std::replace_if
std::max_element
std::merge
std::min_element
std::nth_element
std::partial_sort
std::partition
std::random_shuffle
std::set_union
std::set_intersection
std::set_symmetric_difference
std::set_difference
std::sort
std::stable_sort
std::unique_copy
Parallelization of Bulk Operations for STL Dictionaries . Copyright © 2007 . Workshop on Highly Parallel Processing on a Chip (HPPC) 2007. (LNCS) - .
The Multi-Core Standard Template Library
. Copyright © 2007 .
Euro-Par 2007: Parallel Processing. (LNCS 4641)
diff --git a/libstdc++-v3/doc/html/manual/sequences.html b/libstdc++-v3/doc/html/manual/sequences.html
new file mode 100644
index 00000000000..00d5255d5dc
--- /dev/null
+++ b/libstdc++-v3/doc/html/manual/sequences.html
@@ -0,0 +1,43 @@
+
+
+ Table of Contents
+ Yes it is, and that's okay. This is a decision that we preserved
+ when we imported SGI's STL implementation. The following is
+ quoted from their FAQ:
+
+ The size() member function, for list and slist, takes time
+ proportional to the number of elements in the list. This was a
+ deliberate tradeoff. The only way to get a constant-time
+ size() for linked lists would be to maintain an extra member
+ variable containing the list's size. This would require taking
+ extra time to update that variable (it would make splice() a
+ linear time operation, for example), and it would also make the
+ list larger. Many list algorithms don't require that extra
+ word (algorithms that do require it might do better with
+ vectors than with lists), and, when it is necessary to maintain
+ an explicit size count, it's something that users can do
+ themselves.
+
+ This choice is permitted by the C++ standard. The standard says
+ that size() “should” be constant time, and
+ “should” does not mean the same thing as
+ “shall”. This is the officially recommended ISO
+ wording for saying that an implementation is supposed to do
+ something unless there is a good reason not to.
+
+ One implication of linear time size(): you should never write
+
+ Instead, you should write
+ Table of Contents To transform libstdc++ sources into installed include files
+ and properly built binaries useful for linking to other software is
+ a multi-step process. Steps include getting the sources,
+ configuring and building the sources, testing, and installation.
+ The general outline of commands is something like:
+
+ Each step is described in more detail in the following sections.
+
+ Because libstdc++ is part of GCC, the primary source for
+ installation instructions is
+ the GCC install page.
+ In particular, list of prerequisite software needed to build the library
+
+ starts with those requirements. The same pages also list
+ the tools you will need if you wish to modify the source.
+
+ Additional data is given here only where it applies to libstdc++.
+ As of GCC 4.0.1 the minimum version of binutils required to build
+ libstdc++ is
+ Finally, a few system-specific requirements:
+
+ If gcc 3.1.0 or later on is being used on linux, an attempt
+ will be made to use "C" library functionality necessary for
+ C++ named locale support. For gcc 3.2.1 and later, this
+ means that glibc 2.2.5 or later is required and the "C"
+ library de_DE locale information must be installed.
+
+ Note however that the sanity checks involving the de_DE
+ locale are skipped when an explicit --enable-clocale=gnu
+ configure option is used: only the basic checks are carried
+ out, defending against misconfigurations.
+
+ If the 'gnu' locale model is being used, the following
+ locales are used and tested in the libstdc++ testsuites.
+ The first column is the name of the locale, the second is
+ the character set it is expected to use.
+ Failure to have the underlying "C" library locale
+ information installed will mean that C++ named locales for the
+ above regions will not work: because of this, the libstdc++
+ testsuite will skip the named locale tests. If this isn't an
+ issue, don't worry about it. If named locales are needed, the
+ underlying locale information must be installed. Note that
+ rebuilding libstdc++ after the "C" locales are installed is not
+ necessary.
+
+ To install support for locales, do only one of the following:
+ install all locales with RedHat Linux:
+
+
+ Instructions for other operating systems solicited.
+ install just the necessary locales with Debian Linux: Add the above list, as shown, to the file
+ run on most Unix-like operating systems: (repeat for each entry in the above list)
+ Instructions for other operating systems solicited.
+
+
The shared_ptr class template stores a pointer, usually obtained via new,
and implements shared ownership semantics.
@@ -29,7 +29,7 @@ drops to zero.
Derived classes override those functions to destroy resources in a context
where the correct dynamic type is known. This is an application of the
technique known as type erasure.
-
A
The interface of
There is a single
The classes derived from
As noted in N2351, these functions can be implemented non-intrusively using
the alias constructor. However the aliasing constructor is only available
@@ -214,10 +214,10 @@ is called. Users should not try to use this.
As well as the extra constructors, this implementation also needs some
members of _Sp_counted_deleter to be protected where they could otherwise
be private.
-
Examples of use can be found in the testsuite, under
The resolution to C++ Standard Library issue 674,
"shared_ptr interface changes for consistency with N1856" will
need to be implemented after it is accepted into the working
@@ -265,7 +265,7 @@ be private.
code to work with, Peter Dimov in particular for his help and
invaluable advice on thread safety. Phillip Jordan and Paolo
Carlini for the lock policy implementation.
- [
n2456
]
C++ Standard Library Active Issues List (Revision R52)
@@ -283,7 +283,7 @@ be private.
.
- . [
n2461
]
Working Draft, Standard for Programming Language C++
@@ -292,7 +292,7 @@ be private.
.
- . [
boostshared_ptr
]
Boost C++ Libraries documentation - shared_ptr class template
@@ -301,4 +301,4 @@ be private.
.
shared_ptr
- .
+ if (L.size() == 0)
+ ...
+
+ if (L.empty())
+ ...
+
+ get gcc sources
+ extract into gccsrcdir
+ mkdir gccbuilddir
+ cd gccbuilddir
+ gccsrcdir/configure --prefix=destdir --other-opts...
+ make
+ make check
+ make install
+
2.15.90.0.1.1
. You can get snapshots
+ (as well as releases) of binutils from
+
+ ftp://sources.redhat.com/pub/binutils.
+ Older releases of libstdc++ do not require such a recent version,
+ but to take full advantage of useful space-saving features and
+ bug-fixes you should use a recent binutils whenever possible.
+ The configure process will automatically detect and use these
+ features if the underlying support is present.
+
+de_DE ISO-8859-1
+de_DE@euro ISO-8859-15
+en_HK ISO-8859-1
+en_PH ISO-8859-1
+en_US ISO-8859-1
+en_US.ISO-8859-1 ISO-8859-1
+en_US.ISO-8859-15 ISO-8859-15
+en_US.UTF-8 UTF-8
+es_ES ISO-8859-1
+es_MX ISO-8859-1
+fr_FR ISO-8859-1
+fr_FR@euro ISO-8859-15
+is_IS UTF-8
+it_IT ISO-8859-1
+ja_JP.eucjp EUC-JP
+se_NO.UTF-8 UTF-8
+ta_IN UTF-8
+zh_TW BIG5
+
export LC_ALL=C
+ rpm -e glibc-common --nodeps
+ rpm -i --define "_install_langs all"
+ glibc-common-2.2.5-34.i386.rpm
+
+ /etc/locale.gen
/usr/sbin/locale-gen
localedef -i de_DE -f ISO-8859-1 de_DE
shared_ptr<T>
contains a pointer of
type T* and an object of type
__shared_count
. The shared_count contains a
@@ -71,7 +71,7 @@ be forwarded to Tp's constructor.
Unlike the other _Sp_counted_*
classes, this one is parameterized on the
type of object, not the type of pointer; this is purely a convenience
that simplifies the implementation slightly.
- tr1::shared_ptr
was extended for C++0x
with support for rvalue-references and the other features from
N2351. As with other libstdc++ headers shared by TR1 and C++0x,
@@ -129,7 +129,7 @@ compiler, standard library, platform etc. For the version of
shared_ptr in libstdc++ the compiler and library are fixed, which
makes things much simpler: we have an atomic CAS or we don't, see Lock
Policy below for details.
-_Sp_counted_base
class,
which is a template parameterized on the enum
@@ -170,7 +170,7 @@ used when libstdc++ is built without --enable-threadsext/atomicity.h
, which detect if the program
is multi-threaded. If only one thread of execution exists in
the program then less expensive non-atomic operations are used.
- _Sp_counted_base
(see Class Hierarchy
below) and __shared_count
are implemented separately for C++0x
and TR1, in bits/boost_sp_shared_count.h
and
@@ -181,7 +181,7 @@ The TR1 implementation is considered relatively stable, so is unlikely to
change unless bug fixes require it. If the code that is common to both
C++0x and TR1 modes needs to diverge further then it might be necessary to
duplicate additional classes and only make changes to the C++0x versions.
-dynamic_pointer_cast
, static_pointer_cast
,
+dynamic_pointer_cast
, static_pointer_cast
,
const_pointer_cast
testsuite/tr1/2_general_utilities/shared_ptr
.
-
+
+ Identifiers that conflict and should be avoided. +
+ This is the list of names “reserved to the
+ implementation” that have been claimed by certain
+ compilers and system headers of interest, and should not be used
+ in the library. It will grow, of course. We generally are
+ interested in names that are not all-caps, except for those like
+ "_T"
+
+ For Solaris:
+ _B
+ _C
+ _L
+ _N
+ _P
+ _S
+ _U
+ _X
+ _E1
+ ..
+ _E24
+
+ Irix adds:
+ _A
+ _G
+
+ MS adds:
+ _T
+
+ BSD adds:
+ __used
+ __unused
+ __inline
+ _Complex
+ __istype
+ __maskrune
+ __tolower
+ __toupper
+ __wchar_t
+ __wint_t
+ _res
+ _res_ext
+ __tg_*
+
+ SPU adds:
+ __ea
+
+ For GCC:
+
+ [Note that this list is out of date. It applies to the old
+ name-mangling; in G++ 3.0 and higher a different name-mangling is
+ used. In addition, many of the bugs relating to G++ interpreting
+ these names as operators have been fixed.]
+
+ The full set of __* identifiers (combined from gcc/cp/lex.c and
+ gcc/cplus-dem.c) that are either old or new, but are definitely
+ recognized by the demangler, is:
+
+ __aa
+ __aad
+ __ad
+ __addr
+ __adv
+ __aer
+ __als
+ __alshift
+ __amd
+ __ami
+ __aml
+ __amu
+ __aor
+ __apl
+ __array
+ __ars
+ __arshift
+ __as
+ __bit_and
+ __bit_ior
+ __bit_not
+ __bit_xor
+ __call
+ __cl
+ __cm
+ __cn
+ __co
+ __component
+ __compound
+ __cond
+ __convert
+ __delete
+ __dl
+ __dv
+ __eq
+ __er
+ __ge
+ __gt
+ __indirect
+ __le
+ __ls
+ __lt
+ __max
+ __md
+ __method_call
+ __mi
+ __min
+ __minus
+ __ml
+ __mm
+ __mn
+ __mult
+ __mx
+ __ne
+ __negate
+ __new
+ __nop
+ __nt
+ __nw
+ __oo
+ __op
+ __or
+ __pl
+ __plus
+ __postdecrement
+ __postincrement
+ __pp
+ __pt
+ __rf
+ __rm
+ __rs
+ __sz
+ __trunc_div
+ __trunc_mod
+ __truth_andif
+ __truth_not
+ __truth_orif
+ __vc
+ __vd
+ __vn
+
+ SGI badnames:
+ __builtin_alloca
+ __builtin_fsqrt
+ __builtin_sqrt
+ __builtin_fabs
+ __builtin_dabs
+ __builtin_cast_f2i
+ __builtin_cast_i2f
+ __builtin_cast_d2ll
+ __builtin_cast_ll2d
+ __builtin_copy_dhi2i
+ __builtin_copy_i2dhi
+ __builtin_copy_dlo2i
+ __builtin_copy_i2dlo
+ __add_and_fetch
+ __sub_and_fetch
+ __or_and_fetch
+ __xor_and_fetch
+ __and_and_fetch
+ __nand_and_fetch
+ __mpy_and_fetch
+ __min_and_fetch
+ __max_and_fetch
+ __fetch_and_add
+ __fetch_and_sub
+ __fetch_and_or
+ __fetch_and_xor
+ __fetch_and_and
+ __fetch_and_nand
+ __fetch_and_mpy
+ __fetch_and_min
+ __fetch_and_max
+ __lock_test_and_set
+ __lock_release
+ __lock_acquire
+ __compare_and_swap
+ __synchronize
+ __high_multiply
+ __unix
+ __sgi
+ __linux__
+ __i386__
+ __i486__
+ __cplusplus
+ __embedded_cplusplus
+ // long double conversion members mangled as __opr
+ // http://gcc.gnu.org/ml/libstdc++/1999-q4/msg00060.html
+ _opr
+
+ This library is written to appropriate C++ coding standards. As such,
+ it is intended to precede the recommendations of the GNU Coding
+ Standard, which can be referenced in full here:
+
+ http://www.gnu.org/prep/standards/standards.html#Formatting
+
+ The rest of this is also interesting reading, but skip the "Design
+ Advice" part.
+
+ The GCC coding conventions are here, and are also useful:
+ http://gcc.gnu.org/codingconventions.html
+
+ In addition, because it doesn't seem to be stated explicitly anywhere
+ else, there is an 80 column source limit.
+
+ ChangeLog entries for member functions should use the
+ classname::member function name syntax as follows:
+
+ 1999-04-15 Dennis Ritchie <dr@att.com>
+
+ * src/basic_file.cc (__basic_file::open): Fix thinko in
+ _G_HAVE_IO_FILE_OPEN bits.
+
+ Notable areas of divergence from what may be previous local practice
+ (particularly for GNU C) include:
+
+ 01. Pointers and references
+ char* p = "flop";
+ char& c = *p;
+ -NOT-
+ char *p = "flop"; // wrong
+ char &c = *p; // wrong
+
+ Reason: In C++, definitions are mixed with executable code. Here,
+ p is being initialized, not *p. This is near-universal
+ practice among C++ programmers; it is normal for C hackers
+ to switch spontaneously as they gain experience.
+
+ 02. Operator names and parentheses
+ operator==(type)
+ -NOT-
+ operator == (type) // wrong
+
+ Reason: The == is part of the function name. Separating
+ it makes the declaration look like an expression.
+
+ 03. Function names and parentheses
+ void mangle()
+ -NOT-
+ void mangle () // wrong
+
+ Reason: no space before parentheses (except after a control-flow
+ keyword) is near-universal practice for C++. It identifies the
+ parentheses as the function-call operator or declarator, as
+ opposed to an expression or other overloaded use of parentheses.
+
+ 04. Template function indentation
+ template<typename T>
+ void
+ template_function(args)
+ { }
+ -NOT-
+ template<class T>
+ void template_function(args) {};
+
+ Reason: In class definitions, without indentation whitespace is
+ needed both above and below the declaration to distinguish
+ it visually from other members. (Also, re: "typename"
+ rather than "class".) T often could be int, which is
+ not a class. ("class", here, is an anachronism.)
+
+ 05. Template class indentation
+ template<typename _CharT, typename _Traits>
+ class basic_ios : public ios_base
+ {
+ public:
+ // Types:
+ };
+ -NOT-
+ template<class _CharT, class _Traits>
+ class basic_ios : public ios_base
+ {
+ public:
+ // Types:
+ };
+ -NOT-
+ template<class _CharT, class _Traits>
+ class basic_ios : public ios_base
+ {
+ public:
+ // Types:
+ };
+
+ 06. Enumerators
+ enum
+ {
+ space = _ISspace,
+ print = _ISprint,
+ cntrl = _IScntrl
+ };
+ -NOT-
+ enum { space = _ISspace, print = _ISprint, cntrl = _IScntrl };
+
+ 07. Member initialization lists
+ All one line, separate from class name.
+
+ gribble::gribble()
+ : _M_private_data(0), _M_more_stuff(0), _M_helper(0);
+ { }
+ -NOT-
+ gribble::gribble() : _M_private_data(0), _M_more_stuff(0), _M_helper(0);
+ { }
+
+ 08. Try/Catch blocks
+ try
+ {
+ //
+ }
+ catch (...)
+ {
+ //
+ }
+ -NOT-
+ try {
+ //
+ } catch(...) {
+ //
+ }
+
+ 09. Member functions declarations and definitions
+ Keywords such as extern, static, export, explicit, inline, etc
+ go on the line above the function name. Thus
+
+ virtual int
+ foo()
+ -NOT-
+ virtual int foo()
+
+ Reason: GNU coding conventions dictate return types for functions
+ are on a separate line than the function name and parameter list
+ for definitions. For C++, where we have member functions that can
+ be either inline definitions or declarations, keeping to this
+ standard allows all member function names for a given class to be
+ aligned to the same margin, increasing readability.
+
+
+ 10. Invocation of member functions with "this->"
+ For non-uglified names, use this->name to call the function.
+
+ this->sync()
+ -NOT-
+ sync()
+
+ Reason: Koenig lookup.
+
+ 11. Namespaces
+ namespace std
+ {
+ blah blah blah;
+ } // namespace std
+
+ -NOT-
+
+ namespace std {
+ blah blah blah;
+ } // namespace std
+
+ 12. Spacing under protected and private in class declarations:
+ space above, none below
+ i.e.
+
+ public:
+ int foo;
+
+ -NOT-
+ public:
+
+ int foo;
+
+ 13. Spacing WRT return statements.
+ no extra spacing before returns, no parenthesis
+ i.e.
+
+ }
+ return __ret;
+
+ -NOT-
+ }
+
+ return __ret;
+
+ -NOT-
+
+ }
+ return (__ret);
+
+
+ 14. Location of global variables.
+ All global variables of class type, whether in the "user visible"
+ space (e.g., cin) or the implementation namespace, must be defined
+ as a character array with the appropriate alignment and then later
+ re-initialized to the correct value.
+
+ This is due to startup issues on certain platforms, such as AIX.
+ For more explanation and examples, see src/globals.cc. All such
+ variables should be contained in that file, for simplicity.
+
+ 15. Exception abstractions
+ Use the exception abstractions found in functexcept.h, which allow
+ C++ programmers to use this library with -fno-exceptions. (Even if
+ that is rarely advisable, it's a necessary evil for backwards
+ compatibility.)
+
+ 16. Exception error messages
+ All start with the name of the function where the exception is
+ thrown, and then (optional) descriptive text is added. Example:
+
+ __throw_logic_error(__N("basic_string::_S_construct NULL not valid"));
+
+ Reason: The verbose terminate handler prints out exception::what(),
+ as well as the typeinfo for the thrown exception. As this is the
+ default terminate handler, by putting location info into the
+ exception string, a very useful error message is printed out for
+ uncaught exceptions. So useful, in fact, that non-programmers can
+ give useful error messages, and programmers can intelligently
+ speculate what went wrong without even using a debugger.
+
+ 17. The doxygen style guide to comments is a separate document,
+ see index.
+
+ The library currently has a mixture of GNU-C and modern C++ coding
+ styles. The GNU C usages will be combed out gradually.
+
+ Name patterns:
+
+ For nonstandard names appearing in Standard headers, we are constrained
+ to use names that begin with underscores. This is called "uglification".
+ The convention is:
+
+ Local and argument names: __[a-z].*
+
+ Examples: __count __ix __s1
+
+ Type names and template formal-argument names: _[A-Z][^_].*
+
+ Examples: _Helper _CharT _N
+
+ Member data and function names: _M_.*
+
+ Examples: _M_num_elements _M_initialize ()
+
+ Static data members, constants, and enumerations: _S_.*
+
+ Examples: _S_max_elements _S_default_value
+
+ Don't use names in the same scope that differ only in the prefix,
+ e.g. _S_top and _M_top. See BADNAMES for a list of forbidden names.
+ (The most tempting of these seem to be and "_T" and "__sz".)
+
+ Names must never have "__" internally; it would confuse name
+ unmanglers on some targets. Also, never use "__[0-9]", same reason.
+
+ --------------------------
+
+ [BY EXAMPLE]
+
+ #ifndef _HEADER_
+ #define _HEADER_ 1
+
+ namespace std
+ {
+ class gribble
+ {
+ public:
+ gribble() throw();
+
+ gribble(const gribble&);
+
+ explicit
+ gribble(int __howmany);
+
+ gribble&
+ operator=(const gribble&);
+
+ virtual
+ ~gribble() throw ();
+
+ // Start with a capital letter, end with a period.
+ inline void
+ public_member(const char* __arg) const;
+
+ // In-class function definitions should be restricted to one-liners.
+ int
+ one_line() { return 0 }
+
+ int
+ two_lines(const char* arg)
+ { return strchr(arg, 'a'); }
+
+ inline int
+ three_lines(); // inline, but defined below.
+
+ // Note indentation.
+ template<typename _Formal_argument>
+ void
+ public_template() const throw();
+
+ template<typename _Iterator>
+ void
+ other_template();
+
+ private:
+ class _Helper;
+
+ int _M_private_data;
+ int _M_more_stuff;
+ _Helper* _M_helper;
+ int _M_private_function();
+
+ enum _Enum
+ {
+ _S_one,
+ _S_two
+ };
+
+ static void
+ _S_initialize_library();
+ };
+
+ // More-or-less-standard language features described by lack, not presence.
+ # ifndef _G_NO_LONGLONG
+ extern long long _G_global_with_a_good_long_name; // avoid globals!
+ # endif
+
+ // Avoid in-class inline definitions, define separately;
+ // likewise for member class definitions:
+ inline int
+ gribble::public_member() const
+ { int __local = 0; return __local; }
+
+ class gribble::_Helper
+ {
+ int _M_stuff;
+
+ friend class gribble;
+ };
+ }
+
+ // Names beginning with "__": only for arguments and
+ // local variables; never use "__" in a type name, or
+ // within any name; never use "__[0-9]".
+
+ #endif /* _HEADER_ */
+
+
+ namespace std
+ {
+ template<typename T> // notice: "typename", not "class", no space
+ long_return_value_type<with_many, args>
+ function_name(char* pointer, // "char *pointer" is wrong.
+ char* argument,
+ const Reference& ref)
+ {
+ // int a_local; /* wrong; see below. */
+ if (test)
+ {
+ nested code
+ }
+
+ int a_local = 0; // declare variable at first use.
+
+ // char a, b, *p; /* wrong */
+ char a = 'a';
+ char b = a + 1;
+ char* c = "abc"; // each variable goes on its own line, always.
+
+ // except maybe here...
+ for (unsigned i = 0, mask = 1; mask; ++i, mask <<= 1) {
+ // ...
+ }
+ }
+
+ gribble::gribble()
+ : _M_private_data(0), _M_more_stuff(0), _M_helper(0);
+ { }
+
+ inline int
+ gribble::three_lines()
+ {
+ // doesn't fit in one line.
+ }
+ } // namespace std
+
+
+
+ The Library
+ -----------
+
+ This paper is covers two major areas:
+
+ - Features and policies not mentioned in the standard that
+ the quality of the library implementation depends on, including
+ extensions and "implementation-defined" features;
+
+ - Plans for required but unimplemented library features and
+ optimizations to them.
+
+ Overhead
+ --------
+
+ The standard defines a large library, much larger than the standard
+ C library. A naive implementation would suffer substantial overhead
+ in compile time, executable size, and speed, rendering it unusable
+ in many (particularly embedded) applications. The alternative demands
+ care in construction, and some compiler support, but there is no
+ need for library subsets.
+
+ What are the sources of this overhead? There are four main causes:
+
+ - The library is specified almost entirely as templates, which
+ with current compilers must be included in-line, resulting in
+ very slow builds as tens or hundreds of thousands of lines
+ of function definitions are read for each user source file.
+ Indeed, the entire SGI STL, as well as the dos Reis valarray,
+ are provided purely as header files, largely for simplicity in
+ porting. Iostream/locale is (or will be) as large again.
+
+ - The library is very flexible, specifying a multitude of hooks
+ where users can insert their own code in place of defaults.
+ When these hooks are not used, any time and code expended to
+ support that flexibility is wasted.
+
+ - Templates are often described as causing to "code bloat". In
+ practice, this refers (when it refers to anything real) to several
+ independent processes. First, when a class template is manually
+ instantiated in its entirely, current compilers place the definitions
+ for all members in a single object file, so that a program linking
+ to one member gets definitions of all. Second, template functions
+ which do not actually depend on the template argument are, under
+ current compilers, generated anew for each instantiation, rather
+ than being shared with other instantiations. Third, some of the
+ flexibility mentioned above comes from virtual functions (both in
+ regular classes and template classes) which current linkers add
+ to the executable file even when they manifestly cannot be called.
+
+ - The library is specified to use a language feature, exceptions,
+ which in the current gcc compiler ABI imposes a run time and
+ code space cost to handle the possibility of exceptions even when
+ they are not used. Under the new ABI (accessed with -fnew-abi),
+ there is a space overhead and a small reduction in code efficiency
+ resulting from lost optimization opportunities associated with
+ non-local branches associated with exceptions.
+
+ What can be done to eliminate this overhead? A variety of coding
+ techniques, and compiler, linker and library improvements and
+ extensions may be used, as covered below. Most are not difficult,
+ and some are already implemented in varying degrees.
+
+ Overhead: Compilation Time
+ --------------------------
+
+ Providing "ready-instantiated" template code in object code archives
+ allows us to avoid generating and optimizing template instantiations
+ in each compilation unit which uses them. However, the number of such
+ instantiations that are useful to provide is limited, and anyway this
+ is not enough, by itself, to minimize compilation time. In particular,
+ it does not reduce time spent parsing conforming headers.
+
+ Quicker header parsing will depend on library extensions and compiler
+ improvements. One approach is some variation on the techniques
+ previously marketed as "pre-compiled headers", now standardized as
+ support for the "export" keyword. "Exported" template definitions
+ can be placed (once) in a "repository" -- really just a library, but
+ of template definitions rather than object code -- to be drawn upon
+ at link time when an instantiation is needed, rather than placed in
+ header files to be parsed along with every compilation unit.
+
+ Until "export" is implemented we can put some of the lengthy template
+ definitions in #if guards or alternative headers so that users can skip
+ over the full definitions when they need only the ready-instantiated
+ specializations.
+
+ To be precise, this means that certain headers which define
+ templates which users normally use only for certain arguments
+ can be instrumented to avoid exposing the template definitions
+ to the compiler unless a macro is defined. For example, in
+ <string>, we might have:
+
+ template <class _CharT, ... > class basic_string {
+ ... // member declarations
+ };
+ ... // operator declarations
+
+ #ifdef _STRICT_ISO_
+ # if _G_NO_TEMPLATE_EXPORT
+ # include <bits/std_locale.h> // headers needed by definitions
+ # ...
+ # include <bits/string.tcc> // member and global template definitions.
+ # endif
+ #endif
+
+ Users who compile without specifying a strict-ISO-conforming flag
+ would not see many of the template definitions they now see, and rely
+ instead on ready-instantiated specializations in the library. This
+ technique would be useful for the following substantial components:
+ string, locale/iostreams, valarray. It would *not* be useful or
+ usable with the following: containers, algorithms, iterators,
+ allocator. Since these constitute a large (though decreasing)
+ fraction of the library, the benefit the technique offers is
+ limited.
+
+ The language specifies the semantics of the "export" keyword, but
+ the gcc compiler does not yet support it. When it does, problems
+ with large template inclusions can largely disappear, given some
+ minor library reorganization, along with the need for the apparatus
+ described above.
+
+ Overhead: Flexibility Cost
+ --------------------------
+
+ The library offers many places where users can specify operations
+ to be performed by the library in place of defaults. Sometimes
+ this seems to require that the library use a more-roundabout, and
+ possibly slower, way to accomplish the default requirements than
+ would be used otherwise.
+
+ The primary protection against this overhead is thorough compiler
+ optimization, to crush out layers of inline function interfaces.
+ Kuck & Associates has demonstrated the practicality of this kind
+ of optimization.
+
+ The second line of defense against this overhead is explicit
+ specialization. By defining helper function templates, and writing
+ specialized code for the default case, overhead can be eliminated
+ for that case without sacrificing flexibility. This takes full
+ advantage of any ability of the optimizer to crush out degenerate
+ code.
+
+ The library specifies many virtual functions which current linkers
+ load even when they cannot be called. Some minor improvements to the
+ compiler and to ld would eliminate any such overhead by simply
+ omitting virtual functions that the complete program does not call.
+ A prototype of this work has already been done. For targets where
+ GNU ld is not used, a "pre-linker" could do the same job.
+
+ The main areas in the standard interface where user flexibility
+ can result in overhead are:
+
+ - Allocators: Containers are specified to use user-definable
+ allocator types and objects, making tuning for the container
+ characteristics tricky.
+
+ - Locales: the standard specifies locale objects used to implement
+ iostream operations, involving many virtual functions which use
+ streambuf iterators.
+
+ - Algorithms and containers: these may be instantiated on any type,
+ frequently duplicating code for identical operations.
+
+ - Iostreams and strings: users are permitted to use these on their
+ own types, and specify the operations the stream must use on these
+ types.
+
+ Note that these sources of overhead are _avoidable_. The techniques
+ to avoid them are covered below.
+
+ Code Bloat
+ ----------
+
+ In the SGI STL, and in some other headers, many of the templates
+ are defined "inline" -- either explicitly or by their placement
+ in class definitions -- which should not be inline. This is a
+ source of code bloat. Matt had remarked that he was relying on
+ the compiler to recognize what was too big to benefit from inlining,
+ and generate it out-of-line automatically. However, this also can
+ result in code bloat except where the linker can eliminate the extra
+ copies.
+
+ Fixing these cases will require an audit of all inline functions
+ defined in the library to determine which merit inlining, and moving
+ the rest out of line. This is an issue mainly in chapters 23, 25, and
+ 27. Of course it can be done incrementally, and we should generally
+ accept patches that move large functions out of line and into ".tcc"
+ files, which can later be pulled into a repository. Compiler/linker
+ improvements to recognize very large inline functions and move them
+ out-of-line, but shared among compilation units, could make this
+ work unnecessary.
+
+ Pre-instantiating template specializations currently produces large
+ amounts of dead code which bloats statically linked programs. The
+ current state of the static library, libstdc++.a, is intolerable on
+ this account, and will fuel further confused speculation about a need
+ for a library "subset". A compiler improvement that treats each
+ instantiated function as a separate object file, for linking purposes,
+ would be one solution to this problem. An alternative would be to
+ split up the manual instantiation files into dozens upon dozens of
+ little files, each compiled separately, but an abortive attempt at
+ this was done for <string> and, though it is far from complete, it
+ is already a nuisance. A better interim solution (just until we have
+ "export") is badly needed.
+
+ When building a shared library, the current compiler/linker cannot
+ automatically generate the instantiations needed. This creates a
+ miserable situation; it means any time something is changed in the
+ library, before a shared library can be built someone must manually
+ copy the declarations of all templates that are needed by other parts
+ of the library to an "instantiation" file, and add it to the build
+ system to be compiled and linked to the library. This process is
+ readily automated, and should be automated as soon as possible.
+ Users building their own shared libraries experience identical
+ frustrations.
+
+ Sharing common aspects of template definitions among instantiations
+ can radically reduce code bloat. The compiler could help a great
+ deal here by recognizing when a function depends on nothing about
+ a template parameter, or only on its size, and giving the resulting
+ function a link-name "equate" that allows it to be shared with other
+ instantiations. Implementation code could take advantage of the
+ capability by factoring out code that does not depend on the template
+ argument into separate functions to be merged by the compiler.
+
+ Until such a compiler optimization is implemented, much can be done
+ manually (if tediously) in this direction. One such optimization is
+ to derive class templates from non-template classes, and move as much
+ implementation as possible into the base class. Another is to partial-
+ specialize certain common instantiations, such as vector<T*>, to share
+ code for instantiations on all types T. While these techniques work,
+ they are far from the complete solution that a compiler improvement
+ would afford.
+
+ Overhead: Expensive Language Features
+ -------------------------------------
+
+ The main "expensive" language feature used in the standard library
+ is exception support, which requires compiling in cleanup code with
+ static table data to locate it, and linking in library code to use
+ the table. For small embedded programs the amount of such library
+ code and table data is assumed by some to be excessive. Under the
+ "new" ABI this perception is generally exaggerated, although in some
+ cases it may actually be excessive.
+
+ To implement a library which does not use exceptions directly is
+ not difficult given minor compiler support (to "turn off" exceptions
+ and ignore exception constructs), and results in no great library
+ maintenance difficulties. To be precise, given "-fno-exceptions",
+ the compiler should treat "try" blocks as ordinary blocks, and
+ "catch" blocks as dead code to ignore or eliminate. Compiler
+ support is not strictly necessary, except in the case of "function
+ try blocks"; otherwise the following macros almost suffice:
+
+ #define throw(X)
+ #define try if (true)
+ #define catch(X) else if (false)
+
+ However, there may be a need to use function try blocks in the
+ library implementation, and use of macros in this way can make
+ correct diagnostics impossible. Furthermore, use of this scheme
+ would require the library to call a function to re-throw exceptions
+ from a try block. Implementing the above semantics in the compiler
+ is preferable.
+
+ Given the support above (however implemented) it only remains to
+ replace code that "throws" with a call to a well-documented "handler"
+ function in a separate compilation unit which may be replaced by
+ the user. The main source of exceptions that would be difficult
+ for users to avoid is memory allocation failures, but users can
+ define their own memory allocation primitives that never throw.
+ Otherwise, the complete list of such handlers, and which library
+ functions may call them, would be needed for users to be able to
+ implement the necessary substitutes. (Fortunately, they have the
+ source code.)
+
+ Opportunities
+ -------------
+
+ The template capabilities of C++ offer enormous opportunities for
+ optimizing common library operations, well beyond what would be
+ considered "eliminating overhead". In particular, many operations
+ done in Glibc with macros that depend on proprietary language
+ extensions can be implemented in pristine Standard C++. For example,
+ the chapter 25 algorithms, and even C library functions such as strchr,
+ can be specialized for the case of static arrays of known (small) size.
+
+ Detailed optimization opportunities are identified below where
+ the component where they would appear is discussed. Of course new
+ opportunities will be identified during implementation.
+
+ Unimplemented Required Library Features
+ ---------------------------------------
+
+ The standard specifies hundreds of components, grouped broadly by
+ chapter. These are listed in excruciating detail in the CHECKLIST
+ file.
+
+ 17 general
+ 18 support
+ 19 diagnostics
+ 20 utilities
+ 21 string
+ 22 locale
+ 23 containers
+ 24 iterators
+ 25 algorithms
+ 26 numerics
+ 27 iostreams
+ Annex D backward compatibility
+
+ Anyone participating in implementation of the library should obtain
+ a copy of the standard, ISO 14882. People in the U.S. can obtain an
+ electronic copy for US$18 from ANSI's web site. Those from other
+ countries should visit http://www.iso.ch/ to find out the location
+ of their country's representation in ISO, in order to know who can
+ sell them a copy.
+
+ The emphasis in the following sections is on unimplemented features
+ and optimization opportunities.
+
+ Chapter 17 General
+ -------------------
+
+ Chapter 17 concerns overall library requirements.
+
+ The standard doesn't mention threads. A multi-thread (MT) extension
+ primarily affects operators new and delete (18), allocator (20),
+ string (21), locale (22), and iostreams (27). The common underlying
+ support needed for this is discussed under chapter 20.
+
+ The standard requirements on names from the C headers create a
+ lot of work, mostly done. Names in the C headers must be visible
+ in the std:: and sometimes the global namespace; the names in the
+ two scopes must refer to the same object. More stringent is that
+ Koenig lookup implies that any types specified as defined in std::
+ really are defined in std::. Names optionally implemented as
+ macros in C cannot be macros in C++. (An overview may be read at
+ <http://www.cantrip.org/cheaders.html>). The scripts "inclosure"
+ and "mkcshadow", and the directories shadow/ and cshadow/, are the
+ beginning of an effort to conform in this area.
+
+ A correct conforming definition of C header names based on underlying
+ C library headers, and practical linking of conforming namespaced
+ customer code with third-party C libraries depends ultimately on
+ an ABI change, allowing namespaced C type names to be mangled into
+ type names as if they were global, somewhat as C function names in a
+ namespace, or C++ global variable names, are left unmangled. Perhaps
+ another "extern" mode, such as 'extern "C-global"' would be an
+ appropriate place for such type definitions. Such a type would
+ affect mangling as follows:
+
+ namespace A {
+ struct X {};
+ extern "C-global" { // or maybe just 'extern "C"'
+ struct Y {};
+ };
+ }
+ void f(A::X*); // mangles to f__FPQ21A1X
+ void f(A::Y*); // mangles to f__FP1Y
+
+ (It may be that this is really the appropriate semantics for regular
+ 'extern "C"', and 'extern "C-global"', as an extension, would not be
+ necessary.) This would allow functions declared in non-standard C headers
+ (and thus fixable by neither us nor users) to link properly with functions
+ declared using C types defined in properly-namespaced headers. The
+ problem this solves is that C headers (which C++ programmers do persist
+ in using) frequently forward-declare C struct tags without including
+ the header where the type is defined, as in
+
+ struct tm;
+ void munge(tm*);
+
+ Without some compiler accommodation, munge cannot be called by correct
+ C++ code using a pointer to a correctly-scoped tm* value.
+
+ The current C headers use the preprocessor extension "#include_next",
+ which the compiler complains about when run "-pedantic".
+ (Incidentally, it appears that "-fpedantic" is currently ignored,
+ probably a bug.) The solution in the C compiler is to use
+ "-isystem" rather than "-I", but unfortunately in g++ this seems
+ also to wrap the whole header in an 'extern "C"' block, so it's
+ unusable for C++ headers. The correct solution appears to be to
+ allow the various special include-directory options, if not given
+ an argument, to affect subsequent include-directory options additively,
+ so that if one said
+
+ -pedantic -iprefix $(prefix) \
+ -idirafter -ino-pedantic -ino-extern-c -iwithprefix -I g++-v3 \
+ -iwithprefix -I g++-v3/ext
+
+ the compiler would search $(prefix)/g++-v3 and not report
+ pedantic warnings for files found there, but treat files in
+ $(prefix)/g++-v3/ext pedantically. (The undocumented semantics
+ of "-isystem" in g++ stink. Can they be rescinded? If not it
+ must be replaced with something more rationally behaved.)
+
+ All the C headers need the treatment above; in the standard these
+ headers are mentioned in various chapters. Below, I have only
+ mentioned those that present interesting implementation issues.
+
+ The components identified as "mostly complete", below, have not been
+ audited for conformance. In many cases where the library passes
+ conformance tests we have non-conforming extensions that must be
+ wrapped in #if guards for "pedantic" use, and in some cases renamed
+ in a conforming way for continued use in the implementation regardless
+ of conformance flags.
+
+ The STL portion of the library still depends on a header
+ stl/bits/stl_config.h full of #ifdef clauses. This apparatus
+ should be replaced with autoconf/automake machinery.
+
+ The SGI STL defines a type_traits<> template, specialized for
+ many types in their code including the built-in numeric and
+ pointer types and some library types, to direct optimizations of
+ standard functions. The SGI compiler has been extended to generate
+ specializations of this template automatically for user types,
+ so that use of STL templates on user types can take advantage of
+ these optimizations. Specializations for other, non-STL, types
+ would make more optimizations possible, but extending the gcc
+ compiler in the same way would be much better. Probably the next
+ round of standardization will ratify this, but probably with
+ changes, so it probably should be renamed to place it in the
+ implementation namespace.
+
+ The SGI STL also defines a large number of extensions visible in
+ standard headers. (Other extensions that appear in separate headers
+ have been sequestered in subdirectories ext/ and backward/.) All
+ these extensions should be moved to other headers where possible,
+ and in any case wrapped in a namespace (not std!), and (where kept
+ in a standard header) girded about with macro guards. Some cannot be
+ moved out of standard headers because they are used to implement
+ standard features. The canonical method for accommodating these
+ is to use a protected name, aliased in macro guards to a user-space
+ name. Unfortunately C++ offers no satisfactory template typedef
+ mechanism, so very ad-hoc and unsatisfactory aliasing must be used
+ instead.
+
+ Implementation of a template typedef mechanism should have the highest
+ priority among possible extensions, on the same level as implementation
+ of the template "export" feature.
+
+ Chapter 18 Language support
+ ----------------------------
+
+ Headers: <limits> <new> <typeinfo> <exception>
+ C headers: <cstddef> <climits> <cfloat> <cstdarg> <csetjmp>
+ <ctime> <csignal> <cstdlib> (also 21, 25, 26)
+
+ This defines the built-in exceptions, rtti, numeric_limits<>,
+ operator new and delete. Much of this is provided by the
+ compiler in its static runtime library.
+
+ Work to do includes defining numeric_limits<> specializations in
+ separate files for all target architectures. Values for integer types
+ except for bool and wchar_t are readily obtained from the C header
+ <limits.h>, but values for the remaining numeric types (bool, wchar_t,
+ float, double, long double) must be entered manually. This is
+ largely dog work except for those members whose values are not
+ easily deduced from available documentation. Also, this involves
+ some work in target configuration to identify the correct choice of
+ file to build against and to install.
+
+ The definitions of the various operators new and delete must be
+ made thread-safe, which depends on a portable exclusion mechanism,
+ discussed under chapter 20. Of course there is always plenty of
+ room for improvements to the speed of operators new and delete.
+
+ <cstdarg>, in Glibc, defines some macros that gcc does not allow to
+ be wrapped into an inline function. Probably this header will demand
+ attention whenever a new target is chosen. The functions atexit(),
+ exit(), and abort() in cstdlib have different semantics in C++, so
+ must be re-implemented for C++.
+
+ Chapter 19 Diagnostics
+ -----------------------
+
+ Headers: <stdexcept>
+ C headers: <cassert> <cerrno>
+
+ This defines the standard exception objects, which are "mostly complete".
+ Cygnus has a version, and now SGI provides a slightly different one.
+ It makes little difference which we use.
+
+ The C global name "errno", which C allows to be a variable or a macro,
+ is required in C++ to be a macro. For MT it must typically result in
+ a function call.
+
+ Chapter 20 Utilities
+ ---------------------
+ Headers: <utility> <functional> <memory>
+ C header: <ctime> (also in 18)
+
+ SGI STL provides "mostly complete" versions of all the components
+ defined in this chapter. However, the auto_ptr<> implementation
+ is known to be wrong. Furthermore, the standard definition of it
+ is known to be unimplementable as written. A minor change to the
+ standard would fix it, and auto_ptr<> should be adjusted to match.
+
+ Multi-threading affects the allocator implementation, and there must
+ be configuration/installation choices for different users' MT
+ requirements. Anyway, users will want to tune allocator options
+ to support different target conditions, MT or no.
+
+ The primitives used for MT implementation should be exposed, as an
+ extension, for users' own work. We need cross-CPU "mutex" support,
+ multi-processor shared-memory atomic integer operations, and single-
+ processor uninterruptible integer operations, and all three configurable
+ to be stubbed out for non-MT use, or to use an appropriately-loaded
+ dynamic library for the actual runtime environment, or statically
+ compiled in for cases where the target architecture is known.
+
+ Chapter 21 String
+ ------------------
+ Headers: <string>
+ C headers: <cctype> <cwctype> <cstring> <cwchar> (also in 27)
+ <cstdlib> (also in 18, 25, 26)
+
+ We have "mostly-complete" char_traits<> implementations. Many of the
+ char_traits<char> operations might be optimized further using existing
+ proprietary language extensions.
+
+ We have a "mostly-complete" basic_string<> implementation. The work
+ to manually instantiate char and wchar_t specializations in object
+ files to improve link-time behavior is extremely unsatisfactory,
+ literally tripling library-build time with no commensurate improvement
+ in static program link sizes. It must be redone. (Similar work is
+ needed for some components in chapters 22 and 27.)
+
+ Other work needed for strings is MT-safety, as discussed under the
+ chapter 20 heading.
+
+ The standard C type mbstate_t from <cwchar> and used in char_traits<>
+ must be different in C++ than in C, because in C++ the default constructor
+ value mbstate_t() must be the "base" or "ground" sequence state.
+ (According to the likely resolution of a recently raised Core issue,
+ this may become unnecessary. However, there are other reasons to
+ use a state type not as limited as whatever the C library provides.)
+ If we might want to provide conversions from (e.g.) internally-
+ represented EUC-wide to externally-represented Unicode, or vice-
+ versa, the mbstate_t we choose will need to be more accommodating
+ than what might be provided by an underlying C library.
+
+ There remain some basic_string template-member functions which do
+ not overload properly with their non-template brethren. The infamous
+ hack akin to what was done in vector<> is needed, to conform to
+ 23.1.1 para 10. The CHECKLIST items for basic_string marked 'X',
+ or incomplete, are so marked for this reason.
+
+ Replacing the string iterators, which currently are simple character
+ pointers, with class objects would greatly increase the safety of the
+ client interface, and also permit a "debug" mode in which range,
+ ownership, and validity are rigorously checked. The current use of
+ raw pointers as string iterators is evil. vector<> iterators need the
+ same treatment. Note that the current implementation freely mixes
+ pointers and iterators, and that must be fixed before safer iterators
+ can be introduced.
+
+ Some of the functions in <cstring> are different from the C version.
+ generally overloaded on const and non-const argument pointers. For
+ example, in <cstring> strchr is overloaded. The functions isupper
+ etc. in <cctype> typically implemented as macros in C are functions
+ in C++, because they are overloaded with others of the same name
+ defined in <locale>.
+
+ Many of the functions required in <cwctype> and <cwchar> cannot be
+ implemented using underlying C facilities on intended targets because
+ such facilities only partly exist.
+
+ Chapter 22 Locale
+ ------------------
+ Headers: <locale>
+ C headers: <clocale>
+
+ We have a "mostly complete" class locale, with the exception of
+ code for constructing, and handling the names of, named locales.
+ The ways that locales are named (particularly when categories
+ (e.g. LC_TIME, LC_COLLATE) are different) varies among all target
+ environments. This code must be written in various versions and
+ chosen by configuration parameters.
+
+ Members of many of the facets defined in <locale> are stubs. Generally,
+ there are two sets of facets: the base class facets (which are supposed
+ to implement the "C" locale) and the "byname" facets, which are supposed
+ to read files to determine their behavior. The base ctype<>, collate<>,
+ and numpunct<> facets are "mostly complete", except that the table of
+ bitmask values used for "is" operations, and corresponding mask values,
+ are still defined in libio and just included/linked. (We will need to
+ implement these tables independently, soon, but should take advantage
+ of libio where possible.) The num_put<>::put members for integer types
+ are "mostly complete".
+
+ A complete list of what has and has not been implemented may be
+ found in CHECKLIST. However, note that the current definition of
+ codecvt<wchar_t,char,mbstate_t> is wrong. It should simply write
+ out the raw bytes representing the wide characters, rather than
+ trying to convert each to a corresponding single "char" value.
+
+ Some of the facets are more important than others. Specifically,
+ the members of ctype<>, numpunct<>, num_put<>, and num_get<> facets
+ are used by other library facilities defined in <string>, <istream>,
+ and <ostream>, and the codecvt<> facet is used by basic_filebuf<>
+ in <fstream>, so a conforming iostream implementation depends on
+ these.
+
+ The "long long" type eventually must be supported, but code mentioning
+ it should be wrapped in #if guards to allow pedantic-mode compiling.
+
+ Performance of num_put<> and num_get<> depend critically on
+ caching computed values in ios_base objects, and on extensions
+ to the interface with streambufs.
+
+ Specifically: retrieving a copy of the locale object, extracting
+ the needed facets, and gathering data from them, for each call to
+ (e.g.) operator<< would be prohibitively slow. To cache format
+ data for use by num_put<> and num_get<> we have a _Format_cache<>
+ object stored in the ios_base::pword() array. This is constructed
+ and initialized lazily, and is organized purely for utility. It
+ is discarded when a new locale with different facets is imbued.
+
+ Using only the public interfaces of the iterator arguments to the
+ facet functions would limit performance by forbidding "vector-style"
+ character operations. The streambuf iterator optimizations are
+ described under chapter 24, but facets can also bypass the streambuf
+ iterators via explicit specializations and operate directly on the
+ streambufs, and use extended interfaces to get direct access to the
+ streambuf internal buffer arrays. These extensions are mentioned
+ under chapter 27. These optimizations are particularly important
+ for input parsing.
+
+ Unused virtual members of locale facets can be omitted, as mentioned
+ above, by a smart linker.
+
+ Chapter 23 Containers
+ ----------------------
+ Headers: <deque> <list> <queue> <stack> <vector> <map> <set> <bitset>
+
+ All the components in chapter 23 are implemented in the SGI STL.
+ They are "mostly complete"; they include a large number of
+ nonconforming extensions which must be wrapped. Some of these
+ are used internally and must be renamed or duplicated.
+
+ The SGI components are optimized for large-memory environments. For
+ embedded targets, different criteria might be more appropriate. Users
+ will want to be able to tune this behavior. We should provide
+ ways for users to compile the library with different memory usage
+ characteristics.
+
+ A lot more work is needed on factoring out common code from different
+ specializations to reduce code size here and in chapter 25. The
+ easiest fix for this would be a compiler/ABI improvement that allows
+ the compiler to recognize when a specialization depends only on the
+ size (or other gross quality) of a template argument, and allow the
+ linker to share the code with similar specializations. In its
+ absence, many of the algorithms and containers can be partial-
+ specialized, at least for the case of pointers, but this only solves
+ a small part of the problem. Use of a type_traits-style template
+ allows a few more optimization opportunities, more if the compiler
+ can generate the specializations automatically.
+
+ As an optimization, containers can specialize on the default allocator
+ and bypass it, or take advantage of details of its implementation
+ after it has been improved upon.
+
+ Replacing the vector iterators, which currently are simple element
+ pointers, with class objects would greatly increase the safety of the
+ client interface, and also permit a "debug" mode in which range,
+ ownership, and validity are rigorously checked. The current use of
+ pointers for iterators is evil.
+
+ As mentioned for chapter 24, the deque iterator is a good example of
+ an opportunity to implement a "staged" iterator that would benefit
+ from specializations of some algorithms.
+
+ Chapter 24 Iterators
+ ---------------------
+ Headers: <iterator>
+
+ Standard iterators are "mostly complete", with the exception of
+ the stream iterators, which are not yet templatized on the
+ stream type. Also, the base class template iterator<> appears
+ to be wrong, so everything derived from it must also be wrong,
+ currently.
+
+ The streambuf iterators (currently located in stl/bits/std_iterator.h,
+ but should be under bits/) can be rewritten to take advantage of
+ friendship with the streambuf implementation.
+
+ Matt Austern has identified opportunities where certain iterator
+ types, particularly including streambuf iterators and deque
+ iterators, have a "two-stage" quality, such that an intermediate
+ limit can be checked much more quickly than the true limit on
+ range operations. If identified with a member of iterator_traits,
+ algorithms may be specialized for this case. Of course the
+ iterators that have this quality can be identified by specializing
+ a traits class.
+
+ Many of the algorithms must be specialized for the streambuf
+ iterators, to take advantage of block-mode operations, in order
+ to allow iostream/locale operations' performance not to suffer.
+ It may be that they could be treated as staged iterators and
+ take advantage of those optimizations.
+
+ Chapter 25 Algorithms
+ ----------------------
+ Headers: <algorithm>
+ C headers: <cstdlib> (also in 18, 21, 26))
+
+ The algorithms are "mostly complete". As mentioned above, they
+ are optimized for speed at the expense of code and data size.
+
+ Specializations of many of the algorithms for non-STL types would
+ give performance improvements, but we must use great care not to
+ interfere with fragile template overloading semantics for the
+ standard interfaces. Conventionally the standard function template
+ interface is an inline which delegates to a non-standard function
+ which is then overloaded (this is already done in many places in
+ the library). Particularly appealing opportunities for the sake of
+ iostream performance are for copy and find applied to streambuf
+ iterators or (as noted elsewhere) for staged iterators, of which
+ the streambuf iterators are a good example.
+
+ The bsearch and qsort functions cannot be overloaded properly as
+ required by the standard because gcc does not yet allow overloading
+ on the extern-"C"-ness of a function pointer.
+
+ Chapter 26 Numerics
+ --------------------
+ Headers: <complex> <valarray> <numeric>
+ C headers: <cmath>, <cstdlib> (also 18, 21, 25)
+
+ Numeric components: Gabriel dos Reis's valarray, Drepper's complex,
+ and the few algorithms from the STL are "mostly done". Of course
+ optimization opportunities abound for the numerically literate. It
+ is not clear whether the valarray implementation really conforms
+ fully, in the assumptions it makes about aliasing (and lack thereof)
+ in its arguments.
+
+ The C div() and ldiv() functions are interesting, because they are the
+ only case where a C library function returns a class object by value.
+ Since the C++ type div_t must be different from the underlying C type
+ (which is in the wrong namespace) the underlying functions div() and
+ ldiv() cannot be re-used efficiently. Fortunately they are trivial to
+ re-implement.
+
+ Chapter 27 Iostreams
+ ---------------------
+ Headers: <iosfwd> <streambuf> <ios> <ostream> <istream> <iostream>
+ <iomanip> <sstream> <fstream>
+ C headers: <cstdio> <cwchar> (also in 21)
+
+ Iostream is currently in a very incomplete state. <iosfwd>, <iomanip>,
+ ios_base, and basic_ios<> are "mostly complete". basic_streambuf<> and
+ basic_ostream<> are well along, but basic_istream<> has had little work
+ done. The standard stream objects, <sstream> and <fstream> have been
+ started; basic_filebuf<> "write" functions have been implemented just
+ enough to do "hello, world".
+
+ Most of the istream and ostream operators << and >> (with the exception
+ of the op<<(integer) ones) have not been changed to use locale primitives,
+ sentry objects, or char_traits members.
+
+ All these templates should be manually instantiated for char and
+ wchar_t in a way that links only used members into user programs.
+
+ Streambuf is fertile ground for optimization extensions. An extended
+ interface giving iterator access to its internal buffer would be very
+ useful for other library components.
+
+ Iostream operations (primarily operators << and >>) can take advantage
+ of the case where user code has not specified a locale, and bypass locale
+ operations entirely. The current implementation of op<</num_put<>::put,
+ for the integer types, demonstrates how they can cache encoding details
+ from the locale on each operation. There is lots more room for
+ optimization in this area.
+
+ The definition of the relationship between the standard streams
+ cout et al. and stdout et al. requires something like a "stdiobuf".
+ The SGI solution of using double-indirection to actually use a
+ stdio FILE object for buffering is unsatisfactory, because it
+ interferes with peephole loop optimizations.
+
+ The <sstream> header work has begun. stringbuf can benefit from
+ friendship with basic_string<> and basic_string<>::_Rep to use
+ those objects directly as buffers, and avoid allocating and making
+ copies.
+
+ The basic_filebuf<> template is a complex beast. It is specified to
+ use the locale facet codecvt<> to translate characters between native
+ files and the locale character encoding. In general this involves
+ two buffers, one of "char" representing the file and another of
+ "char_type", for the stream, with codecvt<> translating. The process
+ is complicated by the variable-length nature of the translation, and
+ the need to seek to corresponding places in the two representations.
+ For the case of basic_filebuf<char>, when no translation is needed,
+ a single buffer suffices. A specialized filebuf can be used to reduce
+ code space overhead when no locale has been imbued. Matt Austern's
+ work at SGI will be useful, perhaps directly as a source of code, or
+ at least as an example to draw on.
+
+ Filebuf, almost uniquely (cf. operator new), depends heavily on
+ underlying environmental facilities. In current releases iostream
+ depends fairly heavily on libio constant definitions, but it should
+ be made independent. It also depends on operating system primitives
+ for file operations. There is immense room for optimizations using
+ (e.g.) mmap for reading. The shadow/ directory wraps, besides the
+ standard C headers, the libio.h and unistd.h headers, for use mainly
+ by filebuf. These wrappings have not been completed, though there
+ is scaffolding in place.
+
+ The encapsulation of certain C header <cstdio> names presents an
+ interesting problem. It is possible to define an inline std::fprintf()
+ implemented in terms of the 'extern "C"' vfprintf(), but there is no
+ standard vfscanf() to use to implement std::fscanf(). It appears that
+ vfscanf but be re-implemented in C++ for targets where no vfscanf
+ extension has been defined. This is interesting in that it seems
+ to be the only significant case in the C library where this kind of
+ rewriting is necessary. (Of course Glibc provides the vfscanf()
+ extension.) (The functions related to exit() must be rewritten
+ for other reasons.)
+
+
+ Annex D
+ -------
+ Headers: <strstream>
+
+ Annex D defines many non-library features, and many minor
+ modifications to various headers, and a complete header.
+ It is "mostly done", except that the libstdc++-2 <strstream>
+ header has not been adopted into the library, or checked to
+ verify that it matches the draft in those details that were
+ clarified by the committee. Certainly it must at least be
+ moved into the std namespace.
+
+ We still need to wrap all the deprecated features in #if guards
+ so that pedantic compile modes can detect their use.
+
+ Nonstandard Extensions
+ ----------------------
+ Headers: <iostream.h> <strstream.h> <hash> <rbtree>
+ <pthread_alloc> <stdiobuf> (etc.)
+
+ User code has come to depend on a variety of nonstandard components
+ that we must not omit. Much of this code can be adopted from
+ libstdc++-v2 or from the SGI STL. This particularly includes
+ <iostream.h>, <strstream.h>, and various SGI extensions such
+ as <hash_map.h>. Many of these are already placed in the
+ subdirectories ext/ and backward/. (Note that it is better to
+ include them via "<backward/hash_map.h>" or "<ext/hash_map>" than
+ to search the subdirectory itself via a "-I" directive.
+
+ The unpacked source directory of libstdc++ contains the files + needed to create the GNU C++ Library. +
+It has subdirectories:
+
+ doc
+ Files in HTML and text format that document usage, quirks of the
+ implementation, and contributor checklists.
+
+ include
+ All header files for the C++ library are within this directory,
+ modulo specific runtime-related files that are in the libsupc++
+ directory.
+
+ include/std
+ Files meant to be found by #include <name> directives in
+ standard-conforming user programs.
+
+ include/c
+ Headers intended to directly include standard C headers.
+ [NB: this can be enabled via --enable-cheaders=c]
+
+ include/c_global
+ Headers intended to include standard C headers in
+ the global namespace, and put select names into the std::
+ namespace. [NB: this is the default, and is the same as
+ --enable-cheaders=c_global]
+
+ include/c_std
+ Headers intended to include standard C headers
+ already in namespace std, and put select names into the std::
+ namespace. [NB: this is the same as --enable-cheaders=c_std]
+
+ include/bits
+ Files included by standard headers and by other files in
+ the bits directory.
+
+ include/backward
+ Headers provided for backward compatibility, such as <iostream.h>.
+ They are not used in this library.
+
+ include/ext
+ Headers that define extensions to the standard library. No
+ standard header refers to any of them.
+
+ scripts
+ Scripts that are used during the configure, build, make, or test
+ process.
+
+ src
+ Files that are used in constructing the library, but are not
+ installed.
+
+ testsuites/[backward, demangle, ext, performance, thread, 17_* to 27_*]
+ Test programs are here, and may be used to begin to exercise the
+ library. Support for "make check" and "make check-install" is
+ complete, and runs through all the subdirectories here when this
+ command is issued from the build directory. Please note that
+ "make check" requires DejaGNU 1.4 or later to be installed. Please
+ note that "make check-script" calls the script mkcheck, which
+ requires bash, and which may need the paths to bash adjusted to
+ work properly, as /bin/bash is assumed.
+
+Other subdirectories contain variant versions of certain files
+that are meant to be copied or linked by the configure script.
+Currently these are:
+
+ config/abi
+ config/cpu
+ config/io
+ config/locale
+ config/os
+
+In addition, a subdirectory holds the convenience library libsupc++.
+
+ libsupc++
+ Contains the runtime library for C++, including exception
+ handling and memory allocation and deallocation, RTTI, terminate
+ handlers, etc.
+
+Note that glibc also has a bits/ subdirectory. We will either
+need to be careful not to collide with names in its bits/
+directory; or rename bits to (e.g.) cppbits/.
+
+In files throughout the system, lines marked with an "XXX" indicate
+a bug or incompletely-implemented feature. Lines marked "XXX MT"
+indicate a place that may require attention for multi-thread safety.
+
Copyright © 2008 +
Table of Contents
List of Tables
+ License +
Table of Contents
List of Tables
Table of Contents
+This status table is based on the table of contents of ISO/IEC 14882:2003. +
+This page describes the C++0x support in mainline GCC SVN, not in any +particular release. +
Table 1.1. C++ 1998/2003 Implementation Status
Section | Description | Status | Comments |
---|---|---|---|
+ 18 + | + Language support + | ||
18.1 | Types | Y | |
18.2 | Implementation properties | Y | |
18.2.1 | Numeric Limits | ||
18.2.1.1 | Class template numeric_limits | Y | |
18.2.1.2 | numeric_limits members | Y | |
18.2.1.3 | float_round_style | Y | |
18.2.1.4 | float_denorm_style | Y | |
18.2.1.5 | numeric_limits specializations | Y | |
18.2.2 | C Library | Y | |
18.3 | Start and termination | Y | |
18.4 | Dynamic memory management | Y | |
18.5 | Type identification | ||
18.5.1 | Class type_info | Y | |
18.5.2 | Class bad_cast | Y | |
18.5.3 | Class bad_typeid | Y | |
18.6 | Exception handling | ||
18.6.1 | Class exception | Y | |
18.6.2 | Violation exception-specifications | Y | |
18.6.3 | Abnormal termination | Y | |
18.6.4 | uncaught_exception | Y | |
18.7 | Other runtime support | Y | |
+ 19 + | + Diagnostics + | ||
19.1 | Exception classes | Y | |
19.2 | Assertions | Y | |
19.3 | Error numbers | Y | |
+ 20 + | + General utilities + | ||
20.1 | Requirements | Y | |
20.2 | Utility components | ||
20.2.1 | Operators | Y | |
20.2.2 | pair | Y | |
20.3 | Function objects | ||
20.3.1 | Base | Y | |
20.3.2 | Arithmetic operation | Y | |
20.3.3 | Comparisons | Y | |
20.3.4 | Logical operations | Y | |
20.3.5 | Negators | Y | |
20.3.6 | Binders | Y | |
20.3.7 | Adaptors for pointers to functions | Y | |
20.3.8 | Adaptors for pointers to members | Y | |
20.4 | Memory | ||
20.4.1 | The default allocator | Y | |
20.4.2 | Raw storage iterator | Y | |
20.4.3 | Temporary buffers | Y | |
20.4.4 | Specialized algorithms | Y | |
20.4.4.1 | uninitialized_copy | Y | |
20.4.4.2 | uninitialized_fill | Y | |
20.4.4.3 | uninitialized_fill_n | Y | |
20.4.5 | Class template auto_ptr | Y | |
20.4.6 | C library | Y | |
+ 21 + | + Strings + | ||
21.1 | Character traits | ||
21.1.1 | Character traits requirements | Y | |
21.1.2 | traits typedef | Y | |
21.1.3 | char_traits specializations | ||
21.1.3.1 | struct char_traits<char> | Y | |
21.1.3.2 | struct char_traits<wchar_t> | Y | |
21.2 | String classes | Y | |
21.3 | Class template basic_string | Y | |
21.4 | Null-terminated sequence utilities | Y | C library dependency |
+ 22 + | + Localization + | ||
22.1 | Locales | ||
22.1.1 | Class locale | Y | |
22.1.2 | locale globals | Y | |
22.1.3 | Convenience interfaces | ||
22.1.3.1 | Character classification | Y | |
22.1.3.2 | Character conversions | Y | |
22.2 | Standard locale categories | ||
22.2.1 | ctype | Y | |
22.2.2 | Numeric | ||
22.2.2.1 | num_get | Y | |
22.2.2.2 | num_put | Y | |
22.2.3 | num_punct | Y | |
22.2.4 | collate | Y | |
22.2.5 | Time | ||
22.2.5.1 | time_get | Y | |
22.2.5.2 | time_get_byname | Y | |
22.2.5.3 | time_put | Y | |
22.2.5.3 | time_put_byname | Y | |
22.2.6 | Monetary | ||
22.2.6.1 | money_get | Y | |
22.2.6.2 | money_put | Y | |
22.2.6.3 | money_punct | Y | |
22.2.6.4 | money_punct_byname | Y | |
22.2.7 | messages | Y | |
22.2.8 | Program-defined facets | Y | |
22.3 | C Library Locales | Y | |
+ 23 + | + Containers + | ||
23.1 | Container requirements | Y | |
23.2 | Sequence containers | ||
23.2.1 | Class template deque | Y | |
23.2.2 | Class template list | Y | |
23.2.3 | Adaptors | ||
23.2.3.1 | Class template queue | Y | |
23.2.3.2 | Class template priority_queue | Y | |
23.2.3.3 | Class template stack | Y | |
23.2.4 | Class template vector | Y | |
23.2.5 | Class vector<bool> | Y | |
23.3 | Associative containers | ||
23.3.1 | Class template map | Y | |
23.3.2 | Class template multimap | Y | |
23.3.3 | Class template set | Y | |
23.3.4 | Class template multiset | Y | |
+ 24 + | + Iterators + | ||
24.1 | Requirements | Y | |
24.2 | Header <iterator> synopsis | Y | |
24.3 | Iterator primitives | Y | |
24.4 | Predefined iterators and Iterator adaptors | ||
24.4.1 | Reverse iterators | Y | |
24.4.2 | Insert iterators | Y | |
24.5 | Stream iterators | ||
24.5.1 | Class template istream_iterator | Y | |
24.5.2 | Class template ostream_iterator | Y | |
24.5.3 | Class template istreambuf_iterator | Y | |
24.5.4 | Class template ostreambuf_iterator | Y | |
+ 25 + | + Algorithms + | ||
25.1 | Non-modifying sequence operations | Y | |
25.2 | Mutating sequence operations | Y | |
25.3 | Sorting and related operations | Y | |
25.4 | C library algorithms | Y | |
+ 26 + | + Numerics + | ||
26.1 | Numeric type requirements | Y | |
26.2 | Complex numbers | Y | |
26.3 | Numeric arrays | ||
26.3.1 | Header <valarray> synopsis | Y | |
26.3.2 | Class template valarray | Y | |
26.3.3 | valarray non-member operations | Y | |
26.3.4 | Class slice | Y | |
26.3.5 | Class template slice_array | Y | |
26.3.6 | Class gslice | Y | |
26.3.7 | Class template gslice_array | Y | |
26.3.8 | Class template mask_array | Y | |
26.3.9 | Class template indirect_array | Y | |
26.4 | Generalized numeric operations | ||
26.4.1 | accumulate | Y | |
26.4.2 | inner_product | Y | |
26.4.3 | partial_sum | Y | |
26.4.4 | adjacent_difference | Y | |
26.4.5 | iota | Y | |
26.5 | C Library | Y | |
+ 27 + | + Input/output + | ||
27.1 | Requirements | Y | |
27.2 | Forward declarations | Y | |
27.3 | Standard iostream objects | Y | |
27.3.1 | Narrow stream objects | Y | |
27.3.2 | Wide stream objects | Y | |
27.4 | Iostreams base classes | Y | |
27.5 | Stream buffers | Y | |
27.6 | Formatting and manipulators | Y | |
27.7 | String-based streams | Y | |
27.8 | File-based streams | Y | |
+ Appendix D + | + Compatibility features + | ||
D.1 | Increment operator with bool operand | ||
D.2 | static keyword | ||
D.3 | Access declarations | ||
D.4 | Implicit conversion from const strings | ||
D.5 | C standard library headers | ||
D.6 | Old iostreams members | ||
D.7 | char* streams |
+ The ISO standard defines the following phrase: +
- +
[1.3.5] implementation-defined behavior
++ Behavior, for a well-formed program construct and correct data, that + depends on the implementation and that each implementation + shall document. +
+ We do so here, for the C++ library only. Behavior of the + compiler, linker, runtime loader, and other elements of "the + implementation" are documented elsewhere. Everything listed + in Annex B, Implementation Qualities, are also part of the + compiler, not the library. +
+ For each entry, we give the section number of the standard, when + applicable. This list is probably incomplet and inkorrekt. +
+ [1.9]/11 #3 If isatty(3)
is true, then
+ interactive stream support is implied.
+
+ [17.4.4.5] Non-reentrant functions are probably best + discussed in the various sections on multithreading (see above). +
[18.1]/4 The type of NULL
is described
+ here.
+
[18.3]/8 Even though it's listed in the library + sections, libstdc++ has zero control over what the cleanup code hands + back to the runtime loader. Talk to the compiler people. :-) +
[18.4.2.1]/5 (bad_alloc),
+ [18.5.2]/5 (bad_cast),
+ [18.5.3]/5 (bad_typeid),
+ [18.6.1]/8 (exception),
+ [18.6.2.1]/5 (bad_exception): The what()
+ member function of class std::exception
, and these other
+ classes publicly derived from it, simply returns the name of the
+ class. But they are the mangled names; you will need to call
+ c++filt
and pass the names as command-line parameters to
+ demangle them, or call a
+ runtime demangler function.
+ (The classes in <stdexcept>
have constructors which
+ require an argument to use later for what()
calls, so the
+ problem of what()
's value does not arise in most
+ user-defined exceptions.)
+
[18.5.1]/7 The return value of
+ std::type_info::name()
is the mangled type name (see the
+ previous entry for more).
+
[20.1.5]/5 "Implementors are encouraged to + supply libraries that can accept allocators that encapsulate more + general memory models and that support non-equal instances. In such + implementations, any requirements imposed on allocators by containers + beyond those requirements that appear in Table 32, and the semantics + of containers and algorithms when allocator instances compare + non-equal, are implementation-defined." As yet we don't + have any allocators which compare non-equal, so we can't describe how + they behave. +
[21.1.3.1]/3,4, + [21.1.3.2]/2, + [23.*]'s foo::iterator, + [27.*]'s foo::*_type, + others... + Nope, these types are called implementation-defined because you + shouldn't be taking advantage of their underlying types. Listing them + here would defeat the purpose. :-) +
[21.1.3.1]/5 I don't really know about the mbstate_t + stuff... see the chapter 22 notes + for what does exist. +
[22.*] Anything and everything we have on locale + implementation will be described + over here. +
[26.2.8]/9 I have no idea what
+ complex<T>
's pow(0,0) returns.
+
[27.4.2.4]/2 Calling
+ std::ios_base::sync_with_stdio
after I/O has already been
+ performed on the standard stream objects will
+ flush the buffers, and
+ destroy and recreate the underlying buffer instances. Whether or not
+ the previously-written I/O is destroyed in this process depends mostly
+ on the --enable-libio choice: for stdio, if the written data is
+ already in the stdio buffer, the data may be completely safe!
+
[27.6.1.1.2], + [27.6.2.3] The I/O sentry ctor and dtor can perform + additional work than the minimum required. We are not currently taking + advantage of this yet. +
[27.7.1.3]/16,
+ [27.8.1.4]/10
+ The effects of pubsetbuf/setbuf
are described
+ in this chapter.
+
[27.8.1.4]/16 Calling fstream::sync
when
+ a get area exists will... whatever fflush()
does, I think.
+
+This table is based on the table of contents of ISO/IEC DTR 19768 +Doc No: N1836=05-0096 Date: 2005-06-24 +Draft Technical Report on C++ Library Extensions +
+In this implementation the header names are prefixed by
+tr1/
, for instance <tr1/functional>
,
+<tr1/memory>
, and so on.
+
+This page describes the TR1 support in mainline GCC SVN, not in any particular +release. +
Table 1.2. C++ TR1 Implementation Status
Section | Description | Status | Comments |
---|---|---|---|
2 | General Utilities | ||
2.1 | Reference wrappers | ||
2.1.1 | Additions to header <functional> synopsis | Y | |
2.1.2 | Class template reference_wrapper | ||
2.1.2.1 | reference_wrapper construct/copy/destroy | Y | |
2.1.2.2 | reference_wrapper assignment | Y | |
2.1.2.3 | reference_wrapper access | Y | |
2.1.2.4 | reference_wrapper invocation | Y | |
2.1.2.5 | reference_wrapper helper functions | Y | |
2.2 | Smart pointers | ||
2.2.1 | Additions to header <memory> synopsis | Y | |
2.2.2 | Class bad_weak_ptr | Y | |
2.2.3 | Class template shared_ptr |
+ + Uses code from + boost::shared_ptr. + + | |
2.2.3.1 | shared_ptr constructors | Y | |
2.2.3.2 | shared_ptr destructor | Y | |
2.2.3.3 | shared_ptr assignment | Y | |
2.2.3.4 | shared_ptr modifiers | Y | |
2.2.3.5 | shared_ptr observers | Y | |
2.2.3.6 | shared_ptr comparison | Y | |
2.2.3.7 | shared_ptr I/O | Y | |
2.2.3.8 | shared_ptr specialized algorithms | Y | |
2.2.3.9 | shared_ptr casts | Y | |
2.2.3.10 | get_deleter | Y | |
2.2.4 | Class template weak_ptr | ||
2.2.4.1 | weak_ptr constructors | Y | |
2.2.4.2 | weak_ptr destructor | Y | |
2.2.4.3 | weak_ptr assignment | Y | |
2.2.4.4 | weak_ptr modifiers | Y | |
2.2.4.5 | weak_ptr observers | Y | |
2.2.4.6 | weak_ptr comparison | Y | |
2.2.4.7 | weak_ptr specialized algorithms | Y | |
2.2.5 | Class template enable_shared_from_this | Y | |
3 | Function Objects | ||
3.1 | Definitions | Y | |
3.2 | Additions to <functional> synopsis | Y | |
3.3 | Requirements | Y | |
3.4 | Function return types | Y | |
3.5 | Function template mem_fn | Y | |
3.6 | Function object binders | ||
3.6.1 | Class template is_bind_expression | Y | |
3.6.2 | Class template is_placeholder | Y | |
3.6.3 | Function template bind | Y | |
3.6.4 | Placeholders | Y | |
3.7 | Polymorphic function wrappers | ||
3.7.1 | Class bad_function_call | Y | |
3.7.1.1 | bad_function_call constructor | Y | |
3.7.2 | Class template function | ||
3.7.2.1 | function construct/copy/destroy | Y | |
3.7.2.2 | function modifiers | Y | |
3.7.2.3 | function capacity | Y | |
3.7.2.4 | function invocation | Y | |
3.7.2.5 | function target access | Y | |
3.7.2.6 | undefined operators | Y | |
3.7.2.7 | null pointer comparison operators | Y | |
3.7.2.8 | specialized algorithms | Y | |
4 | Metaprogramming and type traits | ||
4.1 | Requirements | Y | |
4.2 | Header <type_traits> synopsis | Y | |
4.3 | Helper classes | Y | |
4.4 | General Requirements | Y | |
4.5 | Unary Type Traits | ||
4.5.1 | Primary Type Categories | Y | |
4.5.2 | Composite type traits | Y | |
4.5.3 | Type properties | Y | |
4.6 | Relationships between types | Y | |
4.7 | Transformations between types | ||
4.7.1 | Const-volatile modifications | Y | |
4.7.2 | Reference modifications | Y | |
4.7.3 | Array modifications | Y | |
4.7.4 | Pointer modifications | Y | |
4.8 | Other transformations | Y | |
4.9 | Implementation requirements | Y | |
5 | Numerical Facilities | ||
5.1 | Random number generation | ||
5.1.1 | Requirements | Y | |
5.1.2 | Header <random> synopsis | Y | |
5.1.3 | Class template variate_generator | Y | |
5.1.4 | Random number engine class templates | Y | |
5.1.4.1 | Class template linear_congruential | Y | |
5.1.4.2 | Class template mersenne_twister | Y | |
5.1.4.3 | Class template subtract_with_carry | Y | |
5.1.4.4 | Class template subtract_with_carry_01 | Y | |
5.1.4.5 | Class template discard_block | Y | |
5.1.4.6 | Class template xor_combine | Y | operator()() per N2079 |
5.1.5 | Engines with predefined parameters | Y | |
5.1.6 | Class random_device | Y | |
5.1.7 | Random distribution class templates | Y | |
5.1.7.1 | Class template uniform_int | Y | |
5.1.7.2 | Class bernoulli_distribution | Y | |
5.1.7.3 | Class template geometric_distribution | Y | |
5.1.7.4 | Class template poisson_distribution | Y | |
5.1.7.5 | Class template binomial_distribution | Y | |
5.1.7.6 | Class template uniform_real | Y | |
5.1.7.7 | Class template exponential_distribution | Y | |
5.1.7.8 | Class template normal_distribution | Y | |
5.1.7.9 | Class template gamma_distribution | Y | |
5.2 | Mathematical special functions | Y | |
5.2.1 | Additions to header <cmath> synopsis | Y | |
5.2.1.1 | associated Laguerre polynomials | Y | |
5.2.1.2 | associated Legendre functions | Y | |
5.2.1.3 | beta function | Y | |
5.2.1.4 | (complete) elliptic integral of the first kind | Y | |
5.2.1.5 | (complete) elliptic integral of the second kind | Y | |
5.2.1.6 | (complete) elliptic integral of the third kind | Y | |
5.2.1.7 | confluent hypergeometric functions | Y | |
5.2.1.8 | regular modified cylindrical Bessel functions | Y | |
5.2.1.9 | cylindrical Bessel functions (of the first kind) | Y | |
5.2.1.10 | irregular modified cylindrical Bessel functions | Y | |
5.2.1.11 | cylindrical Neumann functions | Y | |
5.2.1.12 | (incomplete) elliptic integral of the first kind | Y | |
5.2.1.13 | (incomplete) elliptic integral of the second kind | Y | |
5.2.1.14 | (incomplete) elliptic integral of the third kind | Y | |
5.2.1.15 | exponential integral | Y | |
5.2.1.16 | Hermite polynomials | Y | |
5.2.1.17 | hypergeometric functions | Y | |
5.2.1.18 | Laguerre polynomials | Y | |
5.2.1.19 | Legendre polynomials | Y | |
5.2.1.20 | Riemann zeta function | Y | |
5.2.1.21 | spherical Bessel functions (of the first kind) | Y | |
5.2.1.22 | spherical associated Legendre functions | Y | |
5.2.1.23 | spherical Neumann functions | Y | |
5.2.2 | Additions to header <math.h> synopsis | Y | |
6 | Containers | ||
6.1 | Tuple types | Y | |
6.1.1 | Header <tuple> synopsis | Y | |
6.1.2 | Additions to header <utility> synopsis | Y | |
6.1.3 | Class template tuple | Y | |
6.1.3.1 | Construction | Y | |
6.1.3.2 | Tuple creation functions | Y | |
6.1.3.3 | Tuple helper classes | Y | |
6.1.3.4 | Element access | Y | |
6.1.3.5 | Relational operators | Y | |
6.1.4 | Pairs | Y | |
6.2 | Fixed size array | Y | |
6.2.1 | Header <array> synopsis | Y | |
6.2.2 | Class template array | Y | |
6.2.2.1 | array constructors, copy, and assignment | Y | |
6.2.2.2 | array specialized algorithms | Y | |
6.2.2.3 | array size | Y | |
6.2.2.4 | Zero sized array s | Y | |
6.2.2.5 | Tuple interface to class template array | Y | |
6.3 | Unordered associative containers | Y | |
6.3.1 | Unordered associative container requirements | Y | |
6.3.1.1 | Exception safety guarantees | Y | |
6.3.2 | Additions to header <functional> synopsis | Y | |
6.3.3 | Class template hash | Y | |
6.3.4 | Unordered associative container classes | Y | |
6.3.4.1 | Header <unordered_set> synopsis | Y | |
6.3.4.2 | Header <unordered_map> synopsis | Y | |
6.3.4.3 | Class template unordered_set | Y | |
6.3.4.3.1 | unordered_set constructors | Y | |
6.3.4.3.2 | unordered_set swap | Y | |
6.3.4.4 | Class template unordered_map | Y | |
6.3.4.4.1 | unordered_map constructors | Y | |
6.3.4.4.2 | unordered_map element access | Y | |
6.3.4.4.3 | unordered_map swap | Y | |
6.3.4.5 | Class template unordered_multiset | Y | |
6.3.4.5.1 | unordered_multiset constructors | Y | |
6.3.4.5.2 | unordered_multiset swap | Y | |
6.3.4.6 | Class template unordered_multimap | Y | |
6.3.4.6.1 | unordered_multimap constructors | Y | |
6.3.4.6.2 | unordered_multimap swap | Y | |
7 | Regular Expressions | ||
7.1 | Definitions | N | |
7.2 | Requirements | N | |
7.3 | Regular expressions summary | N | |
7.4 | Header <regex> synopsis | N | |
7.5 | Namespace tr1::regex_constants | N | |
7.5.1 | Bitmask Type syntax_option_type | N | |
7.5.2 | Bitmask Type regex_constants::match_flag_type | N | |
7.5.3 | Implementation defined error_type | N | |
7.6 | Class regex_error | N | |
7.7 | Class template regex_traits | N | |
7.8 | Class template basic_regex | N | |
7.8.1 | basic_regex constants | N | |
7.8.2 | basic_regex constructors | N | |
7.8.3 | basic_regex assign | N | |
7.8.4 | basic_regex constant operations | N | |
7.8.5 | basic_regex locale | N | |
7.8.6 | basic_regex swap | N | |
7.8.7 | basic_regex non-member functions | N | |
7.8.7.1 | basic_regex non-member swap | N | |
7.9 | Class template sub_match | N | |
7.9.1 | sub_match members | N | |
7.9.2 | sub_match non-member operators | N | |
7.10 | Class template match_results | N | |
7.10.1 | match_results constructors | N | |
7.10.2 | match_results size | N | |
7.10.3 | match_results element access | N | |
7.10.4 | match_results formatting | N | |
7.10.5 | match_results allocator | N | |
7.10.6 | match_results swap | N | |
7.11 | Regular expression algorithms | N | |
7.11.1 | exceptions | N | |
7.11.2 | regex_match | N | |
7.11.3 | regex_search | N | |
7.11.4 | regex_replace | N | |
7.12 | Regular expression Iterators | N | |
7.12.1 | Class template regex_iterator | N | |
7.12.1.1 | regex_iterator constructors | N | |
7.12.1.2 | regex_iterator comparisons | N | |
7.12.1.3 | regex_iterator dereference | N | |
7.12.1.4 | regex_iterator increment | N | |
7.12.2 | Class template regex_token_iterator | N | |
7.12.2.1 | regex_token_iterator constructors | N | |
7.12.2.2 | regex_token_iterator comparisons | N | |
7.12.2.3 | regex_token_iterator dereference | N | |
7.12.2.4 | regex_token_iterator increment | N | |
7.13 | Modified ECMAScript regular expression grammar | N | |
8 | C Compatibility | ||
8.1 | Additions to header <complex> | Y | |
8.1.1 | Synopsis | Y | |
8.1.2 | Function acos | Y | |
8.1.3 | Function asin | Y | |
8.1.4 | Function atan | Y | |
8.1.5 | Function acosh | Y | |
8.1.6 | Function asinh | Y | |
8.1.7 | Function atanh | Y | |
8.1.8 | Function fabs | Y | |
8.1.9 | Additional Overloads | Y | |
8.2 | Header <ccomplex> | N | DR 551 |
8.3 | Header <complex.h> | N | DR 551 |
8.4 | Additions to header <cctype> | Y | |
8.4.1 | Synopsis | Y | |
8.4.2 | Function isblank | Y | |
8.5 | Additions to header <ctype.h> | Y | |
8.6 | Header <cfenv> | Y | |
8.6.1 | Synopsis | Y | |
8.6.2 | Definitions | Y | |
8.7 | Header <fenv.h> | Y | |
8.8 | Additions to header <cfloat> | Y | |
8.9 | Additions to header <float.h> | Y | |
8.10 | Additions to header <ios> | N | |
8.10.1 | Synopsis | N | |
8.10.2 | Function hexfloat | N | |
8.11 | Header <cinttypes> | Y | |
8.11.1 | Synopsis | Y | DR 557 |
8.11.2 | Definitions | Y | |
8.12 | Header <inttypes.h> | Y | |
8.13 | Additions to header <climits> | Y | |
8.14 | Additions to header <limits.h> | Y | |
8.15 | Additions to header <locale> | N | |
8.16 | Additions to header <cmath> | Y | |
8.16.1 | Synopsis | Y | |
8.16.2 | Definitions | Y | |
8.16.3 | Function template definitions | Y | |
8.16.4 | Additional overloads | Y | DR 568; DR 550 |
8.17 | Additions to header <math.h> | Y | |
8.18 | Additions to header <cstdarg> | Y | |
8.19 | Additions to header <stdarg.h> | Y | |
8.20 | The header <cstdbool> | Y | |
8.21 | The header <stdbool.h> | Y | |
8.22 | The header <cstdint> | Y | |
8.22.1 | Synopsis | Y | |
8.22.2 | Definitions | Y | |
8.23 | The header <stdint.h> | Y | |
8.24 | Additions to header <cstdio> | Y | |
8.24.1 | Synopsis | Y | |
8.24.2 | Definitions | Y | |
8.24.3 | Additional format specifiers | Y | C library dependency |
8.24.4 | Additions to header <stdio.h> | Y | |
8.25 | Additions to header <cstdlib> | Y | |
8.25.1 | Synopsis | Y | |
8.25.2 | Definitions | Y | |
8.25.3 | Function abs | Y | |
8.25.4 | Function div | Y | |
8.26 | Additions to header <stdlib.h> | Y | |
8.27 | Header <ctgmath> | Y | DR 551 |
8.28 | Header <tgmath.h> | Y | DR 551 |
8.29 | Additions to header <ctime> | Y | C library dependency |
8.30 | Additions to header <cwchar> | Y | |
8.30.1 | Synopsis | Y | |
8.30.2 | Definitions | Y | |
8.30.3 | Additional wide format specifiers | Y | C library dependency |
8.31 | Additions to header <wchar.h> | Y | |
8.32 | Additions to header <cwctype> | Y | |
8.32.1 | Synopsis | Y | |
8.32.2 | Function iswblank | Y | |
8.33 | Additions to header <wctype.h> | Y |
+This table is based on the table of contents of ISO/IEC +Doc No: N2857=09-0047 Date: 2009-03-23 +Working Draft, Standard for Programming Language C++ +
+In this implementation -std=gnu++0x
or
+-std=c++0x
flags must be used to enable language and
+library features. The pre-defined symbol
+__GXX_EXPERIMENTAL_CXX0X__
is used to check for the
+presence of the required flag.
+
+This page describes the C++0x support in mainline GCC SVN, not in any +particular release. +
Table 1.3. C++ 200x Implementation Status
Section | Description | Status | Comments |
---|---|---|---|
+ 18 + | + Language support + | ||
18.1 | General | Y | |
18.2 | Types | Partial | Missing offsetof, max_align_t, nullptr_t |
18.3 | Implementation properties | ||
18.3.1 | Numeric Limits | ||
18.3.1.1 | Class template numeric_limits | Y | |
18.3.1.2 | numeric_limits members | Partial | Missing constexpr |
18.3.1.3 | float_round_style | N | |
18.3.1.4 | float_denorm_style | N | |
18.3.1.5 | numeric_limits specializations | Y | |
18.3.2 | C Library | Y | |
18.4 | Integer types | ||
18.4.1 | Header <cstdint> synopsis | Y | |
18.4.2 | The header <stdint.h> | Partial | May use configure-generated stdint.h via GCC_HEADER_STDINT |
18.5 | Start and termination | Partial | Missing quick_exit, at_quick_exit |
18.6 | Dynamic memory management | Y | |
18.7 | Type identification | ||
18.7.1 | Class type_info | Y | |
18.7.2 | Class type_index | N | |
18.7.3 | Class bad_cast | Y | |
18.7.4 | Class bad_typeid | Y | |
18.8 | Exception handling | ||
18.8.1 | Class exception | Y | |
18.8.2 | Violation exception-specifications | Y | |
18.8.3 | Abnormal termination | Y | |
18.8.4 | uncaught_exception | Y | |
18.8.5 | Propagation | Y | |
18.8.6 | Class nested_exception | N | |
18.9 | Initializer lists | ||
18.9.1 | Initializer list constructors | Y | |
18.9.2 | Initializer list access | Y | |
18.9.3 | Initializer list concept maps | N | |
18.10 | Other runtime support | Y | |
+ 19 + | + Diagnostics + | ||
19.1 | General | Y | |
19.2 | Exception classes | Y | |
19.3 | Assertions | Y | |
19.4 | Error numbers | Y | |
19.5 | System error support | ||
19.5.1 | Class error_category | Y | |
19.5.2 | Class error_code | Partial | Missing concept ErrorCodeEnum |
19.5.3 | Class error_condition | Partial | Missing concept ErrorConditionEnum |
19.5.4 | Comparison operators | Y | |
19.5.5 | Class system_error | Y | |
+ 20 + | + General utilities + | ||
20.1 | General | Partial | Missing all concepts |
20.2 | Concepts | N | |
20.3 | Utility components | ||
20.3.1 | Operators | Y | |
20.3.2 | forward and move helpers | Y | |
20.3.3 | pair | Y | |
20.3.4 | tuple-like access to pair | Y | |
20.3.5 | Range concept maps for pair | N | |
20.3.6 | Class template bitset | Y | |
20.4 | Compile-time rational arithmetic | ||
20.4.1 | Class template ratio | Y | |
20.4.2 | Arithmetic on ratio types | Y | |
20.4.3 | Comparison of ratio types | Y | |
20.4.4 | SI types | Y | |
20.5 | Tuples | ||
20.5.1 | General | Y | |
20.5.2 | Class template tuple | Partial | Missing range concept maps |
20.6 | Metaprogramming and type traits | ||
20.6.1 | Requirements | Y | |
20.6.2 | Header <type_traits> synopsis | ||
20.6.3 | Helper classes | Y | |
20.6.4 | Unary Type Traits | ||
20.6.4.1 | Primary type categories | Y | |
20.6.4.2 | Composite type traits | Y | |
20.6.4.3 | Type properties | Partial | Missing is_system_layout |
20.6.5 | Relationships between types | Y | |
20.6.6 | Transformations between types | ||
20.6.6.1 | Const-volatile modifications | Y | |
20.6.6.2 | Reference modifications | Y | |
20.6.6.3 | Sign modifications | Y | |
20.6.6.4 | Array modifications | Y | |
20.6.6.5 | Pointer modifications | Y | |
20.6.7 | Other transformations | Partial | Missing decay |
20.7 | Function objects | ||
20.7.1 | Definitions | Y | |
20.7.3 | Base | Y | |
20.7.4 | Function object return types | Y | |
20.7.5 | Class template reference_wrapper | Y | |
20.7.6 | Identity operation | N | |
20.7.7 | Arithmetic operation | Y | |
20.7.8 | Comparisons | Y | |
20.7.9 | Logical operations | Y | |
20.7.10 | Bitwise operations | Y | |
20.7.11 | Negators | Y | |
20.7.12 | Template function and function template bind | Y | |
20.7.13 | Adaptors for pointers to functions | Y | |
20.7.14 | Adaptors for pointers to members | Y | |
20.7.15 | Function template mem_fn | Y | |
20.7.16 | Polymorphic function wrappers | ||
20.7.16.1 | Class bad_function_call | Y | |
20.7.16.2 | Class template function | Y | |
20.7.17 | Class template hash | Y | |
20.7.18 | Class template reference_closure | N | |
20.8 | Memory | ||
20.8.01 | Allocator argument tag | N | |
20.8.02 | Allocators | ||
20.8.02.1 | General | Y | |
20.8.02.2 | Allocator concept | N | |
20.8.02.3 | Support for legacy allocators | N | |
20.8.02.4 | Allocator and Legacy Allocator members | N | |
20.8.03 | Allocator-related element concepts | N | |
20.8.04 | Allocator propagation traits | N | |
20.8.05 | Allocator propagation map | N | |
20.8.06 | The default allocator | Y | |
20.8.07 | Scoped allocator adaptor | ||
20.8.07.1 | scoped_allocator_adaptor_base | N | |
20.8.07.2 | scoped_allocator_adaptor constructors | N | |
20.8.07.3 | scoped_allocator_adaptor2 | N | |
20.8.07.3 | scoped_allocator_adaptor members | N | |
20.8.07.4 | scoped_allocator_adaptor globals | N | |
20.8.08 | Raw storage iterator | Y | |
20.8.09 | Temporary buffers | Y | |
20.8.10 | construct_element | N | |
20.8.11 | Specialized algorithms | ||
20.8.11.1 | addressof | N | |
20.8.11.2 | uninitialized_copy | Y | |
20.8.11.3 | uninitialized_fill | Y | |
20.8.11.4 | uninitialized_fill_n | Y | |
20.8.12 | Class template unique_ptr | Y | |
20.8.13 | Smart pointers | ||
20.8.13.1 | Class bad_weak_ptr | Y | |
20.8.13.2 | Class template shared_ptr | Y |
+ + Uses code from + boost::shared_ptr. + + |
20.8.13.3 | Class template weak_ptr | Y | |
20.8.13.4 | Class template owner_less | Y | |
20.8.13.5 | Class template emable_shared_from_this | Y | |
20.8.13.6 | shared_ptr atomic access | Partial | |
20.8.13.7 | Pointer safety | Partial | |
20.8.14 | Align | N | |
20.8.15 | C library | Y | |
20.9 | Time utilities | ||
20.9.1 | Clock requirements | Y | |
20.9.2 | Time-related traits | ||
20.9.2.1 | treat_as_floating_point | Y | |
20.9.2.2 | duration_values | Y | |
20.9.2.3 | Specializations of common_type | Y | |
20.9.3 | Class template duration | Y | |
20.9.4 | Class template time_point | Y | |
20.9.5 | Clocks | ||
20.9.5.1 | Class system_clock | Y | |
20.9.5.2 | Class monotonic_clock | Y | |
20.9.5.3 | Class high_resolution_clock | Y | |
20.10 | Date and time functions | Y | |
+ 21 + | + Strings + | ||
21.1 | General | Y | |
21.2 | Character traits | ||
21.2.1 | Character traits requirements | Y | |
21.2.2 | traits typedef | Y | |
21.2.3 | char_traits specializations | ||
21.2.3.1 | struct char_traits<char> | Y | |
21.2.3.2 | struct char_traits<char16_t> | Y | |
21.2.3.3 | struct char_traits<char32_t> | Y | |
21.2.3.4 | struct char_traits<wchar_t> | Y | |
21.3 | String classes | Y | |
21.4 | Class template basic_string | Y | |
21.5 | Numeric Conversions | Y | |
21.6 | Null-terminated sequence utilities | Y | C library dependency |
+ 22 + | + Localization + | ||
22.1 | General | Y | |
22.2 | Header <locale> synopsis | Y | |
22.3 | Locales | ||
22.3.1 | Class locale | Y | |
22.3.2 | locale globals | Y | |
22.3.3 | Convenience interfaces | ||
22.3.3.1 | Character classification | Y | |
22.3.3.2 | Conversions | ||
22.3.3.2.1 | Character | Y | |
22.3.3.2.2 | String | N | |
22.3.3.2.3 | Buffer | N | |
22.4 | Standard locale categories | ||
22.4.1 | ctype | Y | |
22.4.2 | Numeric | ||
22.4.2.1 | num_get | Y | |
22.4.2.2 | num_put | Y | |
22.4.3 | num_punct | Y | |
22.4.4 | collate | Y | |
22.4.5 | Time | ||
22.4.5.1 | time_get | Y | |
22.4.5.2 | time_get_byname | Y | |
22.4.5.3 | time_put | Y | |
22.4.5.3 | time_put_byname | Y | |
22.4.6 | Monetary | ||
22.4.6.1 | money_get | Y | |
22.4.6.2 | money_put | Y | |
22.4.6.3 | money_punct | Y | |
22.4.6.4 | money_punct_byname | Y | |
22.4.7 | messages | Y | |
22.4.8 | Program-defined facets | Y | |
22.5 | Standard code conversion facets | N | |
22.6 | C Library Locales | Y | |
+ 23 + | + Containers + | ||
23.1 | General | Partial | Missing concepts |
23.2 | Container requirements | ||
23.2.1 | General requirements | Partial | Missing construct_element |
23.2.2 | Data races | Y | |
23.3 | Sequence containers | ||
23.3.1 | Class template array | Y | |
23.3.2 | Class template deque | Y | |
23.3.3 | Class template forward_list | Y | |
23.3.4 | Class template list | Y | |
23.3.5 | Adaptors | ||
23.3.5.1 | Class template queue | Y | |
23.3.5.2 | Class template priority_queue | Y | |
23.3.5.3 | Class template stack | Y | |
23.3.6 | Class template vector | Y | |
23.3.7 | Class vector<bool> | Y | |
23.4 | Associative containers | ||
23.4.1 | Class template map | Y | |
23.4.2 | Class template multimap | Y | |
23.4.3 | Class template set | Y | |
23.4.4 | Class template multiset | Y | |
23.5 | Unordered associative containers | ||
23.5.1 | Class template unordered_map | Y | |
23.5.2 | Class template unordered_multimap | Y | |
23.5.3 | Class template unordered_set | Y | |
23.5.4 | Class template unordered_multiset | Y | |
+ 24 + | + Iterators + | ||
24.1 | General | Partial | Missing concepts |
24.2 | Iterator concepts | N | |
24.3 | Header <iterator> synopsis | Partial | Missing concepts |
24.4 | Iterator operations | Y | |
24.5 | Predefined iterators and Iterator adaptors | ||
24.5.1 | Reverse iterators | Y | |
24.5.2 | Insert iterators | Y | |
24.5.3 | Move iterators | Y | |
24.6 | Stream iterators | ||
24.6.1 | Class template istream_iterator | Y | |
24.6.2 | Class template ostream_iterator | Y | |
24.6.3 | Class template istreambuf_iterator | Y | |
24.6.4 | Class template ostreambuf_iterator | Y | |
24.7 | Insert iterators | ||
24.7.1 | Class template back_insert_iterator | Y | |
24.7.3 | Class template front_insert_iterator | Y | |
24.7.5 | Class template insert_iterator | Y | |
+ 25 + | + Algorithms + | ||
25.1 | General | Partial | Missing concepts |
25.2 | Header <algorithm> synopsis | Y | |
25.3 | Non-modifying sequence operations | Y | |
25.4 | Mutating sequence operations | Y | |
25.5 | Sorting and related operations | Y | |
25.6 | C library algorithms | Y | |
+ 26 + | + Numerics + | ||
26.1 | General | Y | |
26.2 | Numeric type requirements | Y | |
26.3 | The floating-point environment | Y | |
26.4 | Complex numbers | Y | |
26.5 | Random number generation | ||
26.5.1 | Header <random> synopsis | Partial | Missing concepts |
26.5.2 | Concepts and related requirements | N | |
26.5.3 | Random number engines | ||
26.5.3.1 | Class template linear_congruential_engine | Y | |
26.5.3.2 | Class template mersenne_twister_engine | Y | |
26.5.3.3 | Class template subtract_with_carry_engine | Y | |
26.5.4 | Random number engine adaptors | ||
26.5.4.1 | Class template discard_block_engine | Y | |
26.5.4.2 | Class template independent_bits_engine | Y | |
26.5.4.3 | Class template shuffle_order_engine | Y | |
26.5.5 | Engines and engine adaptors with predefined parameters | Y | |
26.5.6 | Class random_device | Y | |
26.5.7 | Utilities | ||
26.5.7.1 | Class seed_seq | Y | |
26.5.7.2 | Function template generate_canonical | Y | |
26.5.8 | Random number distributions | ||
26.5.8.1 | Uniform distributions | ||
26.5.8.1.1 | Class template uniform_int_distribution | Y | |
26.5.8.1.2 | Class template uniform_real_distribution | Y | |
26.5.8.2 | Bernoulli distributions | ||
26.5.8.2.1 | Class bernoulli_distribution | Y | |
26.5.8.2.2 | Class template binomial_distribution | Y | |
26.5.8.2.3 | Class template geometric_distribution | Y | |
26.5.8.2.4 | Class template negative_binomial_distribution | Y | |
26.5.8.3 | Poisson distributions | ||
26.5.8.3.1 | Class template poisson_distribution | Y | |
26.5.8.3.2 | Class template exponential_distribution | Y | |
26.5.8.3.3 | Class template gamma_distribution | Y | |
26.5.8.3.4 | Class template weibull_distribution | Y | |
26.5.8.3.5 | Class template extreme_value_distribution | Y | |
26.5.8.4 | Normal distributions | ||
26.5.8.4.1 | Class template normal_distribution | Y | |
26.5.8.4.2 | Class template lognormal_distribution | Y | |
26.5.8.4.3 | Class template chi_squared_distribution | Y | |
26.5.8.4.4 | Class template cauchy_distribution | Y | |
26.5.8.4.5 | Class template fisher_f_distribution | Y | |
26.5.8.4.6 | Class template student_t_distribution | Y | |
26.5.8.5 | Sampling distributions | ||
26.5.8.5.1 | Class template discrete_distribution | Y | |
26.5.8.5.2 | Class template piecewise_constant_distribution | Y | |
26.5.8.5.3 | Class template piecewise_linear_distribution | Y | |
26.6 | Numeric arrays | ||
26.6.1 | Header <valarray> synopsis | Y | |
26.6.2 | Class template valarray | Y | |
26.6.3 | valarray non-member operations | Y | |
26.6.4 | Class slice | Y | |
26.6.5 | Class template slice_array | Y | |
26.6.6 | Class gslice | Y | |
26.6.7 | Class template gslice_array | Y | |
26.6.8 | Class template mask_array | Y | |
26.6.9 | Class template indirect_array | Y | |
26.7 | Generalized numeric operations | ||
26.7.1 | accumulate | Y | |
26.7.2 | inner_product | Y | |
26.7.3 | partial_sum | Y | |
26.7.4 | adjacent_difference | Y | |
26.7.5 | iota | Y | |
26.8 | C Library | Y | |
+ 27 + | + Input/output + | ||
27.1 | General | Y | |
27.2 | Requirements | Y | |
27.2.1 | Imbue limitations | Y | |
27.2.2 | Positioning type limitations | Y | |
27.2.3 | Thread safety | Partial | |
27.3 | Forward declarations | Y | |
27.4 | Standard iostream objects | Y | |
27.4.1 | Narrow stream objects | Y | |
27.4.2 | Wide stream objects | Y | |
27.5 | Iostreams base classes | Y | |
27.6 | Stream buffers | Y | |
27.7 | Formatting and manipulators | Y | |
27.8 | String-based streams | Y | |
27.9 | File-based streams | Y | |
+ 28 + | + Regular expressions + | ||
28.01 | General | N | |
28.02 | Definitions | N | |
28.03 | Requirements | N | |
28.04 | Regular expressions summary | N | |
28.05 | Header <regex> synopsis | N | |
28.06 | Namespace std::regex_constants | Y | |
28.07 | Class regex_error | Y | |
28.08 | Class template regex_traits | Partial | |
28.09 | Class template basic_regex | Partial | |
28.10 | Class template sub_match | Partial | |
28.11 | Class template match_results | Partial | |
28.12 | Regular expression algorithms | N | |
28.13 | Regular expression Iterators | N | |
28.14 | Modified ECMAScript regular expression grammar | N | |
+ 29 + | + Atomic operations + | ||
29.1 | General | Y | |
29.2 | Header <cstdatomic> synopsis | Y | |
29.3 | Order and consistency | N | |
29.4 | Lock-free property | Y | Based on _GLIBCXX_ATOMIC_PROPERTY |
29.5 | Atomic types | ||
29.5.1 | Integral types | Y | Missing constexpr |
29.5.2 | Address types | Y | Missing constexpr |
29.5.3 | Generic types | Y | Missing constexpr |
29.6 | Operations on atomic types | Y | |
29.7 | Flag Type and operations | Y | |
29.8 | Fences | N | |
+ 30 + | + Thread support + | ||
30.1 | General | Y | |
30.2 | Requirements | Y | |
30.3 | Threads | ||
30.3.1 | Class thread | Partial | Missing futures |
30.3.2 | Namespace this_thread | Y | |
30.4 | Mutual exclusion | ||
30.4.1 | Mutex requirements | ||
30.4.1.1 | Class mutex | Y | |
30.4.1.2 | Class recursive_mutex | Y | |
30.4.2 | Timed mutex requirements | ||
30.4.2.1 | Class timed_mutex | Y | |
30.4.2.2 | Class recursive_timed_mutex | Y | |
30.4.3 | Locks | ||
30.4.3.1 | Class template lock_guard | Y | |
30.4.3.2 | Class template unique_lock | Y | |
30.4.4 | Generic locking algorithms | Y | |
30.4.5 | Call once | ||
30.4.5.1 | once_flag | Y | |
30.4.5.2 | call_once | Y | |
30.5 | Condition variables | ||
30.5.1 | Class condition_variable | Y | |
30.5.2 | Class condition_variable_any | Partial | |
30.6 | Futures | ||
30.6.1 | Overview | N | |
30.6.2 | Error handling | N | |
30.6.3 | Class future_error | N | |
30.6.4 | Class template unique_future | N | |
30.6.5 | Class template shared_future | N | |
30.6.6 | Class template promise | N | |
30.6.7 | Allocator templates | N | |
30.6.8 | Class template packaged_task | N | |
+ Appendix D + | + Compatibility features + | ||
D.1 | Increment operator with bool operand | ||
D.2 | static keyword | ||
D.3 | Access declarations | ||
D.4 | Implicit conversion from const strings | ||
D.5 | C standard library headers | ||
D.6 | Old iostreams members | ||
D.7 | char* streams | ||
D.8 | Binders | ||
D.9 | auto_ptr | ||
D.10 | Iterator primitives |
Table of Contents
+
Creating your own stream buffers for I/O can be remarkably easy. + If you are interested in doing so, we highly recommend two very + excellent books: + Standard C++ + IOStreams and Locales by Langer and Kreft, ISBN 0-201-18395-1, and + The C++ Standard Library + by Nicolai Josuttis, ISBN 0-201-37926-0. Both are published by + Addison-Wesley, who isn't paying us a cent for saying that, honest. +
Here is a simple example, io/outbuf1, from the Josuttis text. It + transforms everything sent through it to uppercase. This version + assumes many things about the nature of the character type being + used (for more information, read the books or the newsgroups): +
+ #include <iostream> + #include <streambuf> + #include <locale> + #include <cstdio> + + class outbuf : public std::streambuf + { + protected: + /* central output function + * - print characters in uppercase mode + */ + virtual int_type overflow (int_type c) { + if (c != EOF) { + // convert lowercase to uppercase + c = std::toupper(static_cast<char>(c),getloc()); + + // and write the character to the standard output + if (putchar(c) == EOF) { + return EOF; + } + } + return c; + } + }; + + int main() + { + // create special output buffer + outbuf ob; + // initialize output stream with that output buffer + std::ostream out(&ob); + + out << "31 hexadecimal: " + << std::hex << 31 << std::endl; + return 0; + } +
Try it yourself! More examples can be found in 3.1.x code, in
+ include/ext/*_filebuf.h
, and on
+ Dietmar
+ Kühl's IOStreams page.
+
Table of Contents
+
Stringstreams (defined in the header <sstream>
)
+ are in this author's opinion one of the coolest things since
+ sliced time. An example of their use is in the Received Wisdom
+ section for Chapter 21 (Strings),
+ describing how to
+ format strings.
+
The quick definition is: they are siblings of ifstream and ofstream,
+ and they do for std::string
what their siblings do for
+ files. All that work you put into writing <<
and
+ >>
functions for your classes now pays off
+ again! Need to format a string before passing the string
+ to a function? Send your stuff via <<
to an
+ ostringstream. You've read a string as input and need to parse it?
+ Initialize an istringstream with that string, and then pull pieces
+ out of it with >>
. Have a stringstream and need to
+ get a copy of the string inside? Just call the str()
+ member function.
+
This only works if you've written your
+ <<
/>>
functions correctly, though,
+ and correctly means that they take istreams and ostreams as
+ parameters, not ifstreams and ofstreams. If they
+ take the latter, then your I/O operators will work fine with
+ file streams, but with nothing else -- including stringstreams.
+
If you are a user of the strstream classes, you need to update
+ your code. You don't have to explicitly append ends
to
+ terminate the C-style character array, you don't have to mess with
+ "freezing" functions, and you don't have to manage the
+ memory yourself. The strstreams have been officially deprecated,
+ which means that 1) future revisions of the C++ Standard won't
+ support them, and 2) if you use them, people will laugh at you.
+
Table of Contents
+ Not many changes here to cstdlib
. You should note that the
+ abort()
function does not call the
+ destructors of automatic nor static objects, so if you're
+ depending on those to do cleanup, it isn't going to happen.
+ (The functions registered with atexit()
+ don't get called either, so you can forget about that
+ possibility, too.)
+
+ The good old exit()
function can be a bit
+ funky, too, until you look closer. Basically, three points to
+ remember are:
+
+ Static objects are destroyed in reverse order of their creation. +
+ Functions registered with atexit()
are called in
+ reverse order of registration, once per registration call.
+ (This isn't actually new.)
+
+ The previous two actions are “interleaved,” that is, + given this pseudocode: +
+ extern "C or C++" void f1 (void); + extern "C or C++" void f2 (void); + + static Thing obj1; + atexit(f1); + static Thing obj2; + atexit(f2); +
+ then at a call of exit()
,
+ f2
will be called, then
+ obj2
will be destroyed, then
+ f1
will be called, and finally
+ obj1
will be destroyed. If
+ f1
or f2
allow an
+ exception to propagate out of them, Bad Things happen.
+
+ Note also that atexit()
is only required to store 32
+ functions, and the compiler/library might already be using some of
+ those slots. If you think you may run out, we recommend using
+ the xatexit
/xexit
combination from libiberty
, which has no such limit.
+
+
The libstdc++ testsuite includes testing for standard conformance, regressions, ABI, and performance.
time_counter
resource_counter
report_performance
Table of Contents
+
Table of Contents
If you only built a static library (libstdc++.a), or if you specified static linking, you don't have to worry about this. But if you built a shared library (libstdc++.so) and linked @@ -38,4 +41,4 @@ A libstdc++.la file is also installed, for use with Libtool. If you use Libtool to create your executables, these details are taken care of for you. -
This section discusses issues surrounding the proper compilation + of multithreaded applications which use the Standard C++ + library. This information is GCC-specific since the C++ + standard does not address matters of multithreaded applications. +
All normal disclaimers aside, multithreaded C++ application are
+ only supported when libstdc++ and all user code was built with
+ compilers which report (via gcc/g++ -v
) the same thread
+ model and that model is not single. As long as your
+ final application is actually single-threaded, then it should be
+ safe to mix user code built with a thread model of
+ single with a libstdc++ and other C++ libraries built
+ with another thread model useful on the platform. Other mixes
+ may or may not work but are not considered supported. (Thus, if
+ you distribute a shared C++ library in binary form only, it may
+ be best to compile it with a GCC configured with
+ --enable-threads for maximal interchangeability and usefulness
+ with a user population that may have built GCC with either
+ --enable-threads or --disable-threads.)
+
When you link a multithreaded application, you will probably + need to add a library or flag to g++. This is a very + non-standardized area of GCC across ports. Some ports support a + special flag (the spelling isn't even standardized yet) to add + all required macros to a compilation (if any such flags are + required then you must provide the flag for all compilations not + just linking) and link-library additions and/or replacements at + link time. The documentation is weak. Here is a quick summary + to display how ad hoc this is: On Solaris, both -pthreads and + -threads (with subtly different meanings) are honored. On OSF, + -pthread and -threads (with subtly different meanings) are + honored. On Linux/i386, -pthread is honored. On FreeBSD, + -pthread is honored. Some other ports use other switches. + AFAIK, none of this is properly documented anywhere other than + in ``gcc -dumpspecs'' (look at lib and cpp entries). +
+We currently use the SGI STL definition of thread safety. +
The library strives to be thread-safe when all of the following + conditions are met: +
The system's libc is itself thread-safe, +
+ The compiler in use reports a thread model other than
+ 'single'. This can be tested via output from gcc
+ -v
. Multi-thread capable versions of gcc output
+ something like this:
+
+%gcc -v +Using built-in specs. +... +Thread model: posix +gcc version 4.1.2 20070925 (Red Hat 4.1.2-33) +
Look for "Thread model" lines that aren't equal to "single."
+ Requisite command-line flags are used for atomic operations
+ and threading. Examples of this include -pthread
+ and -march=native
, although specifics vary
+ depending on the host environment. See Machine
+ Dependent Options.
+
+ An implementation of atomicity.h functions + exists for the architecture in question. See the internals documentation for more details. +
The user-code must guard against concurrent method calls which may + access any particular library object's state. Typically, the + application programmer may infer what object locks must be held + based on the objects referenced in a method call. Without getting + into great detail, here is an example which requires user-level + locks: +
+ library_class_a shared_object_a; + + thread_main () { + library_class_b *object_b = new library_class_b; + shared_object_a.add_b (object_b); // must hold lock for shared_object_a + shared_object_a.mutate (); // must hold lock for shared_object_a + } + + // Multiple copies of thread_main() are started in independent threads.
Under the assumption that object_a and object_b are never exposed to + another thread, here is an example that should not require any + user-level locks: +
+ thread_main () { + library_class_a object_a; + library_class_b *object_b = new library_class_b; + object_a.add_b (object_b); + object_a.mutate (); + }
All library objects are safe to use in a multithreaded program as + long as each thread carefully locks out access by any other + thread while it uses any object visible to another thread, i.e., + treat library objects like any other shared resource. In general, + this requirement includes both read and write access to objects; + unless otherwise documented as safe, do not assume that two threads + may access a shared standard library object at the same time. +
See chapters 17 (library + introduction), 23 + (containers), and 27 (I/O) for + more information. +
I'll assume that you have already read the + general notes on library threads, + and the + notes on threaded container + access (you might not think of an I/O stream as a container, but + the points made there also hold here). If you have not read them, + please do so first. +
This gets a bit tricky. Please read carefully, and bear with me. +
A wrapper
+ type called __basic_file
provides our abstraction layer
+ for the std::filebuf
classes. Nearly all decisions dealing
+ with actual input and output must be made in __basic_file
.
+
A generic locking mechanism is somewhat in place at the filebuf layer, + but is not used in the current code. Providing locking at any higher + level is akin to providing locking within containers, and is not done + for the same reasons (see the links above). +
The __basic_file type is simply a collection of small wrappers around
+ the C stdio layer (again, see the link under Structure). We do no
+ locking ourselves, but simply pass through to calls to fopen
,
+ fwrite
, and so forth.
+
So, for 3.0, the question of "is multithreading safe for I/O" + must be answered with, "is your platform's C library threadsafe + for I/O?" Some are by default, some are not; many offer multiple + implementations of the C library with varying tradeoffs of threadsafety + and efficiency. You, the programmer, are always required to take care + with multiple threads. +
(As an example, the POSIX standard requires that C stdio FILE*
+ operations are atomic. POSIX-conforming C libraries (e.g, on Solaris
+ and GNU/Linux) have an internal mutex to serialize operations on
+ FILE*s. However, you still need to not do stupid things like calling
+ fclose(fs)
in one thread followed by an access of
+ fs
in another.)
+
So, if your platform's C library is threadsafe, then your
+ fstream
I/O operations will be threadsafe at the lowest
+ level. For higher-level operations, such as manipulating the data
+ contained in the stream formatting classes (e.g., setting up callbacks
+ inside an std::ofstream
), you need to guard such accesses
+ like any other critical shared resource.
+
A + second choice may be available for I/O implementations: libio. This is + disabled by default, and in fact will not currently work due to other + issues. It will be revisited, however. +
The libio code is a subset of the guts of the GNU libc (glibc) I/O
+ implementation. When libio is in use, the __basic_file
+ type is basically derived from FILE. (The real situation is more
+ complex than that... it's derived from an internal type used to
+ implement FILE. See libio/libioP.h to see scary things done with
+ vtbls.) The result is that there is no "layer" of C stdio
+ to go through; the filebuf makes calls directly into the same
+ functions used to implement fread
, fwrite
,
+ and so forth, using internal data structures. (And when I say
+ "makes calls directly," I mean the function is literally
+ replaced by a jump into an internal function. Fast but frightening.
+ *grin*)
+
Also, the libio internal locks are used. This requires pulling in + large chunks of glibc, such as a pthreads implementation, and is one + of the issues preventing widespread use of libio as the libstdc++ + cstdio implementation. +
But we plan to make this work, at least as an option if not a future + default. Platforms running a copy of glibc with a recent-enough + version will see calls from libstdc++ directly into the glibc already + installed. For other platforms, a copy of the libio subsection will + be built and included in libstdc++. +
This section discusses issues surrounding the design of + multithreaded applications which use Standard C++ containers. + All information in this section is current as of the gcc 3.0 + release and all later point releases. Although earlier gcc + releases had a different approach to threading configuration and + proper compilation, the basic code design rules presented here + were similar. For information on all other aspects of + multithreading as it relates to libstdc++, including details on + the proper compilation of threaded code (and compatibility between + threaded and non-threaded code), see Chapter 17. +
Two excellent pages to read when working with the Standard C++ + containers and threads are + SGI's + http://www.sgi.com/tech/stl/thread_safety.html and + SGI's + http://www.sgi.com/tech/stl/Allocators.html. +
However, please ignore all discussions about the user-level + configuration of the lock implementation inside the STL + container-memory allocator on those pages. For the sake of this + discussion, libstdc++ configures the SGI STL implementation, + not you. This is quite different from how gcc pre-3.0 worked. + In particular, past advice was for people using g++ to + explicitly define _PTHREADS or other macros or port-specific + compilation options on the command line to get a thread-safe + STL. This is no longer required for any port and should no + longer be done unless you really know what you are doing and + assume all responsibility. +
Since the container implementation of libstdc++ uses the SGI + code, we use the same definition of thread safety as SGI when + discussing design. A key point that beginners may miss is the + fourth major paragraph of the first page mentioned above + ("For most clients,"...), which points out that + locking must nearly always be done outside the container, by + client code (that'd be you, not us). There is a notable + exceptions to this rule. Allocators called while a container or + element is constructed uses an internal lock obtained and + released solely within libstdc++ code (in fact, this is the + reason STL requires any knowledge of the thread configuration). +
For implementing a container which does its own locking, it is + trivial to provide a wrapper class which obtains the lock (as + SGI suggests), performs the container operation, and then + releases the lock. This could be templatized to a certain + extent, on the underlying container and/or a locking + mechanism. Trying to provide a catch-all general template + solution would probably be more trouble than it's worth. +
The STL implementation is currently configured to use the + high-speed caching memory allocator. Some people like to + test and/or normally run threaded programs with a different + default. For all details about how to globally override this + at application run-time see here. +
There is a better way (not standardized yet): It is possible to + force the malloc-based allocator on a per-case-basis for some + application code. The library team generally believes that this + is a better way to tune an application for high-speed using this + implementation of the STL. There is + more information on allocators here. +
+ The C++ standard specifies the entire set of header files that
+ must be available to all hosted implementations. Actually, the
+ word "files" is a misnomer, since the contents of the
+ headers don't necessarily have to be in any kind of external
+ file. The only rule is that when one #include
's a
+ header, the contents of that header become available, no matter
+ how.
+
+ That said, in practice files are used. +
+ There are two main types of include files: header files related + to a specific version of the ISO C++ standard (called Standard + Headers), and all others (TR1, C++ ABI, and Extensions). +
+ Two dialects of standard headers are supported, corresponding to + the 1998 standard as updated for 2003, and the draft of the + upcoming 200x standard. +
+ C++98/03 include files. These are available in the default compilation mode, i.e. -std=c++98
or -std=gnu++98
.
+
Table 3.1. C++ 1998 Library Headers
algorithm | bitset | complex | deque | exception |
fstream | functional | iomanip | ios | iosfwd |
iostream | istream | iterator | limits | list |
locale | map | memory | new | numeric |
ostream | queue | set | sstream | stack |
stdexcept | streambuf | string | utility | typeinfo |
valarray | vector |
Table 3.2. C++ 1998 Library Headers for C Library Facilities
cassert | cerrno | cctype | cfloat | ciso646 |
climits | clocale | cmath | csetjmp | csignal |
cstdarg | cstddef | cstdio | cstdlib | cstring |
ctime | cwchar | cwctype |
+C++0x include files. These are only available in C++0x compilation
+mode, i.e. -std=c++0x
or -std=gnu++0x
.
+
Table 3.3. C++ 200x Library Headers
algorithm | array | bitset | chrono | complex |
condition_variable | deque | exception | forward_list | fstream |
functional | initalizer_list | iomanip | ios | iosfwd |
iostream | istream | iterator | limits | list |
locale | map | memory | mutex | new |
numeric | ostream | queue | random | ratio |
regex | set | sstream | stack | stdexcept |
streambuf | string | system_error | thread | tuple |
type_traits | typeinfo | unordered_map | unordered_set | utility |
valarray | vector |
Table 3.4. C++ 200x Library Headers for C Library Facilities
cassert | ccomplex | cctype | cerrno | cfenv |
cfloat | cinttypes | ciso646 | climits | clocale |
cmath | csetjmp | csignal | cstdarg | cstdatomic |
cstdbool | cstddef | cstdint | cstdlib | cstdio |
cstring | ctgmath | ctime | cuchar | cwchar |
cwctype | stdatomic.h |
+ In addition, TR1 includes as: +
Table 3.5. C++ TR1 Library Headers
tr1/array | tr1/complex | tr1/memory | tr1/functional | tr1/random |
tr1/regex | tr1/tuple | tr1/type_traits | tr1/unordered_map | tr1/unordered_set |
tr1/utility |
Table 3.6. C++ TR1 Library Headers for C Library Facilities
tr1/ccomplex | tr1/cfenv | tr1/cfloat | tr1/cmath | tr1/cinttypes |
tr1/climits | tr1/cstdarg | tr1/cstdbool | tr1/cstdint | tr1/cstdio |
tr1/cstdlib | tr1/ctgmath | tr1/ctime | tr1/cwchar | tr1/cwctype |
+ Also included are files for the C++ ABI interface: +
+ And a large variety of extensions. +
Table 3.8. Extension Headers
ext/algorithm | ext/atomicity.h | ext/array_allocator.h | ext/bitmap_allocator.h | ext/cast.h |
ext/codecvt_specializations.h | ext/concurrence.h | ext/debug_allocator.h | ext/enc_filebuf.h | ext/extptr_allocator.h |
ext/functional | ext/iterator | ext/malloc_allocator.h | ext/memory | ext/mt_allocator.h |
ext/new_allocator.h | ext/numeric | ext/numeric_traits.h | ext/pb_ds/assoc_container.h | ext/pb_ds/priority_queue.h |
ext/pod_char_traits.h | ext/pool_allocator.h | ext/rb_tree | ext/rope | ext/slist |
ext/stdio_filebuf.h | ext/stdio_sync_filebuf.h | ext/throw_allocator.h | ext/typelist.h | ext/type_traits.h |
ext/vstring.h |
Table 3.9. Extension Debug Headers
debug/bitset | debug/deque | debug/list | debug/map | debug/set |
debug/string | debug/unordered_map | debug/unordered_set | debug/vector |
A few simple rules. +
First, mixing different dialects of the standard headers is not +possible. It's an all-or-nothing affair. Thus, code like +
+#include <array> +#include <functional> +
Implies C++0x mode. To use the entities in <array>, the C++0x +compilation mode must be used, which implies the C++0x functionality +(and deprecations) in <functional> will be present. +
Second, the other headers can be included with either dialect of
+the standard headers, although features and types specific to C++0x
+are still only enabled when in C++0x compilation mode. So, to use
+rvalue references with __gnu_cxx::vstring
, or to use the
+debug-mode versions of std::unordered_map
, one must use
+the std=gnu++0x
compiler flag. (Or std=c++0x
, of course.)
+
A special case of the second rule is the mixing of TR1 and C++0x +facilities. It is possible (although not especially prudent) to +include both the TR1 version and the C++0x version of header in the +same translation unit: +
+#include <tr1/type_traits> +#include <type_traits> +
Several parts of C++0x diverge quite substantially from TR1 predecessors. +
+ The standard specifies that if one includes the C-style header
+ (<math.h> in this case), the symbols will be available
+ in the global namespace and perhaps in
+ namespace std::
(but this is no longer a firm
+ requirement.) One the other hand, including the C++-style
+ header (<cmath>) guarantees that the entities will be
+ found in namespace std and perhaps in the global namespace.
+
+Usage of C++-style headers is recommended, as then
+C-linkage names can be disambiguated by explicit qualification, such
+as by std::abort
. In addition, the C++-style headers can
+use function overloading to provide a simpler interface to certain
+families of C-functions. For instance in <cmath>, the
+function std::sin
has overloads for all the builtin
+floating-point types. This means that std::sin
can be
+used uniformly, instead of a combination
+of std::sinf
, std::sin
,
+and std::sinl
.
+
There are three base header files that are provided. They can be +used to precompile the standard headers and extensions into binary +files that may the be used to speed compiles that use these headers. +
stdc++.h
Includes all standard headers. Actual content varies depending on +language dialect. +
stdtr1c++.h
Includes all of <stdc++.h>, and adds all the TR1 headers. +
extc++.h
Includes all of <stdtr1c++.h>, and adds all the Extension headers. +
How to construct a .gch file from one of these base header files.
First, find the include directory for the compiler. One way to do +this is:
+g++ -v hello.cc + +#include <...> search starts here: + /mnt/share/bld/H-x86-gcc.20071201/include/c++/4.3.0 +... +End of search list. +
Then, create a precompiled header file with the same flags that +will be used to compile other projects.
+g++ -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 +
The resulting file will be quite large: the current size is around +thirty megabytes.
How to use the resulting file.
+g++ -I. -include stdc++.h -H -g -O2 hello.cc +
Verification that the PCH file is being used is easy:
+g++ -Winvalid-pch -I. -include stdc++.h -H -g -O2 hello.cc -o test.exe +! ./stdc++.h.gch +. /mnt/share/bld/H-x86-gcc.20071201/include/c++/4.3.0/iostream +. /mnt/share/bld/H-x86-gcc.20071201include/c++/4.3.0/string +
The exclamation point to the left of the stdc++.h.gch
listing means that the generated PCH file was used, and thus the
Detailed information about creating precompiled header files can be found in the GCC documentation. +
All pre-processor switches and configurations are all gathered
+ in the file c++config.h
, which is generated during
+ the libstdc++ configuration and build process, and included by
+ files part of the public libstdc++ API. Most of these macros
+ should not be used by consumers of libstdc++, and are reserved
+ for internal implementation use. These macros cannot be
+ redefined. However, a select handful of these macro
+ control libstdc++ extensions and extra features, or provide
+ versioning information for the API, and are able to be used.
+
All library macros begin with _GLIBCXX_
(except for
+ versions 3.1.x to 3.3.x, which use _GLIBCPP_
).
+
Below is the macro which users may check for library version + information.
__GLIBCXX__
The current version of + libstdc++ in compressed ISO date format, form of an unsigned + long. For details on the value of this particular macro for a + particular release, please consult this + document. +
Below are the macros which users may change with #define/#undef or + with -D/-U compiler flags. The default state of the symbol is + listed.
“Configurable” (or “Not configurable”) means + that the symbol is initially chosen (or not) based on + --enable/--disable options at library build and configure time + (documented here), with the + various --enable/--disable choices being translated to + #define/#undef). +
ABI means that changing from the default value may + mean changing the ABI of compiled code. In other words, these + choices control code which has already been compiled (i.e., in a + binary such as libstdc++.a/.so). If you explicitly #define or + #undef these macros, the headers may see different code + paths, but the libraries which you link against will not. + Experimenting with different values with the expectation of + consistent linkage requires changing the config headers before + building/installing the library. +
_GLIBCXX_DEPRECATED
+ Defined by default. Not configurable. ABI-changing. Turning this off
+ removes older ARM-style iostreams code, and other anachronisms
+ from the API. This macro is dependent on the version of the
+ standard being tracked, and as a result may give different results for
+ -std=c++98
and -std=c++0x
. This may
+ be useful in updating old C++ code which no longer meet the
+ requirements of the language, or for checking current code
+ against new language standards.
+
_GLIBCXX_FORCE_NEW
+ Undefined by default. When defined, memory allocation and
+ allocators controlled by libstdc++ call operator new/delete
+ without caching and pooling. Configurable via
+ --enable-libstdcxx-allocator
. ABI-changing.
+
_GLIBCXX_CONCEPT_CHECKS
+ Undefined by default. Configurable via
+ --enable-concept-checks
. When defined, performs
+ compile-time checking on certain template instantiations to
+ detect violations of the requirements of the standard. This
+ is described in more detail here.
+
_GLIBCXX_DEBUG
+ Undefined by default. When defined, compiles + user code using the libstdc++ debug + mode. +
_GLIBCXX_DEBUG_PEDANTIC
+ Undefined by default. When defined while + compiling with the libstdc++ debug + mode, makes the debug mode extremely picky by making the use + of libstdc++ extensions and libstdc++-specific behavior into + errors. +
_GLIBCXX_PARALLEL
Undefined by default. When defined, compiles + user code using the libstdc++ parallel + mode. +
There are three main namespaces. +
std
The ISO C++ standards specify that "all library entities are defined
+within namespace std." This includes namespaces nested
+within namespace std
, such as namespace
+std::tr1
.
+
abi
Specified by the C++ ABI. This ABI specifies a number of type and +function APIs supplemental to those required by the ISO C++ Standard, +but necessary for interoperability. +
__gnu_
Indicating one of several GNU extensions. Choices
+include __gnu_cxx
, __gnu_debug
, __gnu_parallel
,
+and __gnu_pbds
.
+
A complete list of implementation namespaces (including namespace contents) is available in the generated source documentation. +
+ One standard requirement is that the library components are defined
+ in namespace std::
. Thus, in order to use these types or
+ functions, one must do one of two things:
+
put a kind of using-declaration in your source
+(either using namespace std;
or i.e. using
+std::string;
) This approach works well for individual source files, but
+should not be used in a global context, like header files.
+
use a fully
+qualified namefor each library symbol
+(i.e. std::string
, std::cout
) Always can be
+used, and usually enhanced, by strategic use of typedefs. (In the
+cases where the qualified verbiage becomes unwieldy.)
+
+Best practice in programming suggests sequestering new data or +functionality in a sanely-named, unique namespace whenever +possible. This is considered an advantage over dumping everything in +the global namespace, as then name look-up can be explicitly enabled or +disabled as above, symbols are consistently mangled without repetitive +naming prefixes or macros, etc. +
For instance, consider a project that defines most of its classes in namespace gtk
. It is possible to
+ adapt namespace gtk
to namespace std
by using a C++-feature called
+ namespace composition. This is what happens if
+ a using-declaration is put into a
+ namespace-definition: the imported symbol(s) gets imported into the
+ currently active namespace(s). For example:
+
+namespace gtk +{ + using std::string; + using std::tr1::array; + + class Window { ... }; +} +
+ In this example, std::string
gets imported into
+ namespace gtk
. The result is that use of
+ std::string
inside namespace gtk can just use string
, without the explicit qualification.
+ As an added bonus,
+ std::string
does not get imported into
+ the global namespace. Additionally, a more elaborate arrangement can be made for backwards compatibility and portability, whereby the
+ using
-declarations can wrapped in macros that
+ are set based on autoconf-tests to either "" or i.e. using
+ std::string;
(depending on whether the system has
+ libstdc++ in std::
or not). (ideas from
+ <llewelly@dbritsch.dsl.xmission.com>
, Karl Nelson <kenelson@ece.ucdavis.edu>
)
+
+
+ In this
+ message to the list, Daniel Kostecky announced work on an
+ alternate form of std::vector
that would support
+ hints on the number of elements to be over-allocated. The design
+ was also described, along with possible implementation choices.
+
+ The first two alpha releases were announced here + and here. + The releases themselves are available at + + http://www.kotelna.sk/dk/sw/caphint/. +
+ If you are having difficulty with uncaught exceptions and want a + little bit of help debugging the causes of the core dumps, you can + make use of a GNU extension, the verbose terminate handler. +
+#include <exception>
+
+int main()
+{
+ std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
+ ...
+
+ throw anything
;
+}
+
+ The __verbose_terminate_handler
function
+ obtains the name of the current exception, attempts to demangle
+ it, and prints it to stderr. If the exception is derived from
+ exception
then the output from
+ what()
will be included.
+
+ Any replacement termination function is required to kill the + program without returning; this one calls abort. +
+ For example: +
+#include <exception>
+#include <stdexcept>
+
+struct argument_error : public std::runtime_error
+{
+ argument_error(const std::string& s): std::runtime_error(s) { }
+};
+
+int main(int argc)
+{
+ std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
+ if (argc > 5)
+ throw argument_error(“argc is greater than 5!”);
+ else
+ throw argc;
+}
+
+ With the verbose terminate handler active, this gives: +
+
+ % ./a.out
+ terminate called after throwing a `int'
+ Aborted
+ % ./a.out f f f f f f f f f f f
+ terminate called after throwing an instance of `argument_error'
+ what(): argc is greater than 5!
+ Aborted
+
+
+ The 'Aborted' line comes from the call to
+ abort()
, of course.
+
+ This is the default termination handler; nothing need be done to
+ use it. To go back to the previous “silent death”
+ method, simply include exception
and
+ cstdlib
, and call
+
+ std::set_terminate(std::abort); +
+ After this, all calls to terminate
will use
+ abort
as the terminate handler.
+
+ Note: the verbose terminate handler will attempt to write to
+ stderr. If your application closes stderr or redirects it to an
+ inappropriate location,
+ __verbose_terminate_handler
will behave in
+ an unspecified manner.
+
Copyright © 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 +
Copyright © 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 FSF -
Table of Contents
Table of Contents