From c3d8729e5fd7bb66c398fd2512211e49f7ececbc Mon Sep 17 00:00:00 2001 From: bkoz Date: Mon, 10 Dec 2007 00:38:36 +0000 Subject: [PATCH] 2007-12-09 Benjamin Kosnik * docs/html/ext/howto.html: Update. * docs/html/ext/sgiexts.html: Same. * docs/html/ext/concurrence.html: New. Document extensions. * docs/html/17_intro/api.html: Move some bits... * docs/html/17_intro/backwards_compatibility.html: here. New. Add compatibility suggestions, move existing ones. * docs/html/17_intro/howto.html: Update info. * docs/html/18_support/howto.html: Tweak. * docs/html/faq/index.html: Update thread info. * docs/html/documentation.html: Add links. * docs/html/20_util/allocator.html: Update info. * include/precompiled/stdc++.h: Add C++0x includes if appropriate. * testsuite/17_intro/headers/c++200x/all.cc: Same. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@130732 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 16 + libstdc++-v3/docs/html/17_intro/api.html | 623 +++--------- .../html/17_intro/backwards_compatibility.html | 1073 ++++++++++++++++++++ libstdc++-v3/docs/html/17_intro/howto.html | 599 +++++++---- libstdc++-v3/docs/html/18_support/howto.html | 8 +- libstdc++-v3/docs/html/20_util/allocator.html | 78 +- libstdc++-v3/docs/html/documentation.html | 35 +- libstdc++-v3/docs/html/ext/concurrence.html | 342 +++++++ libstdc++-v3/docs/html/ext/howto.html | 17 +- libstdc++-v3/docs/html/ext/sgiexts.html | 38 +- libstdc++-v3/docs/html/faq/index.html | 20 +- libstdc++-v3/include/precompiled/stdc++.h | 24 +- .../testsuite/17_intro/headers/c++200x/all.cc | 1 + 13 files changed, 2128 insertions(+), 746 deletions(-) create mode 100644 libstdc++-v3/docs/html/17_intro/backwards_compatibility.html create mode 100644 libstdc++-v3/docs/html/ext/concurrence.html diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f4b5f0e..730cf4f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,19 @@ +2007-12-09 Benjamin Kosnik + + * docs/html/ext/howto.html: Update. + * docs/html/ext/sgiexts.html: Same. + * docs/html/ext/concurrence.html: New. Document extensions. + * docs/html/17_intro/api.html: Move some bits... + * docs/html/17_intro/backwards_compatibility.html: here. New. Add + compatibility suggestions, move existing ones. + * docs/html/17_intro/howto.html: Update info. + * docs/html/18_support/howto.html: Tweak. + * docs/html/faq/index.html: Update thread info. + * docs/html/documentation.html: Add links. + * docs/html/20_util/allocator.html: Update info. + * include/precompiled/stdc++.h: Add C++0x includes if appropriate. + * testsuite/17_intro/headers/c++200x/all.cc: Same. + 2007-12-09 Jonathan Wakely * testsuite/util/testsuite_allocator.h, diff --git a/libstdc++-v3/docs/html/17_intro/api.html b/libstdc++-v3/docs/html/17_intro/api.html index bfe7b20..983d044 100644 --- a/libstdc++-v3/docs/html/17_intro/api.html +++ b/libstdc++-v3/docs/html/17_intro/api.html @@ -5,8 +5,8 @@ - - + + API Evolution and Deprecation History @@ -22,7 +22,7 @@

The latest version of this document is always available at - http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/abi.html. + http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/api.html.

@@ -30,565 +30,260 @@

+

- First. + API Evolution, Deprecation, and History of User Visible Changes

-

2.72

-

The first generation GNU C++ library was called libg++. It had a -working relationship with at least two kinds of dinosaur. Sadly, the -details were not pried away from the estate. +

A list of user-visible changes, by release version.

-

+

+ 3.0 +

+

+Extensions moved to include/ext.

-

Known Issues include many of the limitations of its immediate ancestor.

- -
No ios_base
- -

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. +

+Include files from the SGI/HP sources that pre-date the ISO standard +are added. These files are placed into +the include/backward directory and a deprecated warning +is added that notifies on inclusion (-Wno-deprecated +deactivates the warning.)

-
No cout in ostream.h, no cin in istream.h
- -

- In earlier versions of the standard, - <fstream.h>, - <ostream.h> - and <istream.h> - used to define - cout, cin and so on. ISO C++ specifies that one needs to include - <iostream> - explicitly to get the required definitions. -

-

Some include adjustment may be required.

+

Deprecated include <backward/strstream> added.

+

Removal of include <builtinbuf.h>, <indstream.h>, <parsestream.h>, <PlotFile.h>, <SFile.h>, <stdiostream.h>, and <stream.h>.

-

This project is no longer maintained or supported, and the sources -archived. The code is considered replaced and rewritten. -

-

- Second. + 3.1

-

The second generation GNU C++ library was called libstdc++, or -libstdc++-v2. It was a separate GNU project, although reliably paired -with GCC. It spans the time between libg++ and pre-ISO C++. -

- -

egcs 1.x

-

2.95

-

2.96

-

Portability Notes

-

Implementation Limitations

- -
Namespace std:: not supported.
- -

- Some care is required to support C++ compiler and or library - implementation that do not have the standard library in - namespace std. -

-

- The following sections list some possible solutions to support compilers - that cannot ignore std::-qualified names. -

- -

First, see if the compiler has a flag for this. Namespace - back-portability-issues are generally not a problem for g++ - compilers that do not have libstdc++ in std::, as - the compilers use -fno-honor-std (ignore - std::, :: = std::) by default. That - is, the responsibility for enabling or disabling - std:: is on the user; the maintainer does not have - to care about it. This probably applies to some other compilers - as well. -

- -

Second, experiment with a variety of pre-processor tricks.

- -

By defining std as a macro, fully-qualified namespace calls become global. Volia. - -

-#ifdef WICKEDLY_OLD_COMPILER
-# define std
-#endif
-
-(thanks to Juergen Heinzl who posted this solution on gnu.gcc.help) - -

Define a macro NAMESPACE_STD, which is defined to -either "" or "std" based on a compile-type -test. On GNU systems, this can be done with autotools by means of an -autoconf test (see below) for HAVE_NAMESPACE_STD, then -using that to set a value for the NAMESPACE_STD macro. -At that point, one is able to use NAMESPACE_STD::string, -which will evaluate to std::string or -::string (ie, in the global namespace on systems that do -not put string in std::).

- -

-

-dnl @synopsis AC_CXX_HAVE_STD_NAMESPACE
-dnl
-dnl If the compiler supports the std namespace, define
-dnl HAVE_STD_NAMESPACE.
-dnl
-dnl @category Cxx
-dnl @author Todd Veldhuizen
-dnl @author Luc Maisonobe 
-dnl @version 2004-02-04
-dnl @license AllPermissive
-
-AC_DEFUN([AC_CXX_HAVE_STD_NAMESPACE],
-[AC_CACHE_CHECK(whether the compiler supports the std namespace,
-ac_cv_cxx_have_std_namespace,
-[AC_LANG_SAVE
- AC_LANG_CPLUSPLUS
- AC_TRY_COMPILE([#include 
-	std::istream& is = std::cin;
-	],[return 0;],
- ac_cv_cxx_have_std_namespace=yes, ac_cv_cxx_have_std_namespace=no)
- AC_LANG_RESTORE
-])
-if test "$ac_cv_cxx_have_std_namespace" = yes; then
-  AC_DEFINE(HAVE_STD_NAMESPACE,,[define if the compiler supports the std namespace])
-fi
-])
-
- -
Illegal iterator usage.

- The following illustrate implementation-allowed illegal iterator - use, and then correct use.

  • you cannot do - ostream::operator<<(iterator) to print the - address of the iterator => use operator<< - &*iterator instead ? -

  • -
  • you cannot clear an iterator's reference - (iterator = 0) => use - iterator = iterator_type(); ? -

  • -
  • -if (iterator) won't work any - more => use if (iterator != iterator_type()) - ?

  • -
+Extensions from SGI/HP moved from namespace std +to namespace __gnu_cxx. As part of this, the following +new includes are +added: <ext/algorithm>, <ext/functional>, <ext/iterator>, <ext/memory>, and <ext/numeric>. +

-
isspace from <cctype> is a macro -
+

+Extensions to basic_filebuf introduced: __gnu_cxx::enc_filebuf, and __gnu_cxx::stdio_filebuf. +

-

Glibc 2.0.x and 2.1.x define <ctype.h> -functionality as macros (isspace, isalpha etc.). +

+Extensions to tree data structures added in <ext/rb_tree>.

-This implementations of libstdc++, however, keep these functions as -macros, and so it is not back-portable to use fully qualified -names. For example: +Removal of <ext/tree>, moved to <backward/tree.h>.

-
 
-#include <cctype> 
-int main() { std::isspace('X'); } 
-
-

Results in something like this: -

+

+ 3.2 +

+

Symbol versioning introduced for shared library.

-
 
-std:: (__ctype_b[(int) ( ( 'X' ) )] & (unsigned short int) _ISspace ) ; 
-
+

Removal of include <backward/strstream.h>.

+

+ 3.3 +

+

Allocator changes. Change __malloc_alloc to malloc_allocator and __new_alloc to new_allocator.

-

A solution is to modify a header-file so that the compiler tells -<ctype.h> to define functions instead of macros: -

+

Error handling in iostreams cleaned up, made consistent.

-
-// This keeps isalnum, et al from being propagated as macros. 
-#if __linux__
-# define __NO_CTYPE 1
-#endif
-
-

Then, include <ctype.h> +

+ 3.4 +

+

+Large file support.

-

-Another problem arises if you put a using namespace std; -declaration at the top, and include <ctype.h>. This -will result in ambiguities between the definitions in the global -namespace (<ctype.h>) and the definitions in namespace -std:: (<cctype>). +

Extensions for generic characters and char_traits added in <ext/pod_char_traits.h>.

-
No vector::at, deque::at, string::at
+

+Support for wchar_t specializations of basic_filebuf enhanced to support UTF-8 and Unicode, depending on host. More hosts support basic wchar_t functionality. +

- One solution is to add an autoconf-test for this: -

-
-AC_MSG_CHECKING(for container::at)
-AC_TRY_COMPILE(
-[
-#include <vector>
-#include <deque>
-#include <string>
-	
-using namespace std;
-],
-[
-deque<int> test_deque(3);
-test_deque.at(2);
-vector<int> test_vector(2);
-test_vector.at(1);
-string test_string("test_string");
-test_string.at(3);
-],
-[AC_MSG_RESULT(yes)
-AC_DEFINE(HAVE_CONTAINER_AT)],
-[AC_MSG_RESULT(no)])
-
+Support for char_traits beyond builtin types. +

-If you are using other (non-GNU) compilers it might be a good idea -to check for string::at separately. +Conformant allocator class and usage in containers. As +part of this, the following extensions are +added: <ext/bitmap_allocator.h>, <ext/debug_allocator.h>, <ext/mt_allocator.h>, <ext/malloc_allocator.h>,<ext/new_allocator.h>, <ext/pool_allocator.h>.

-
No std::char_traits<char>::eof

-Use some kind of autoconf test, plus this: -

-
 
-#ifdef HAVE_CHAR_TRAITS
-#define CPP_EOF std::char_traits<char>::eof()
-#else
-#define CPP_EOF EOF
-#endif
-
- -
No string::clear
+Debug mode first appears. +

- There are two functions for deleting the contents of a string: - clear and erase (the latter - returns the string). -

-	void 
-	clear() { _M_mutate(0, this->size(), 0); }
-      
-
-	basic_string& 
-	erase(size_type __pos = 0, size_type __n = npos)
-	{ 
-	return this->replace(_M_check(__pos), _M_fold(__pos, __n),
-	_M_data(), _M_data()); 
-	}
-      
- Unfortunately, ut clear is not - implemented in this version, so you should use - erase (which is probably faster than - operator=(charT*)). -

- -
Removal of ostream::form and -istream::scan extensions.
- -

These are no longer supported. Please use - - stringstreams instead. -

- -
No basic_stringbuf, basic_stringstream
+PCH support. +

- Libstdc++ provides the new - i/ostringstream-classes, (<sstream>), but for compatibility - with older implementations you still have to use - i/ostrstream (<strstream>): -

-	#ifdef HAVE_SSTREAM
-	#include <sstream>
-	#else
-	#include <strstream>
-	#endif
-      
-
    -
  • strstream is considered to be - deprecated -

  • -
  • strstream is limited to - char -

  • -
  • with ostringstream you don't - have to take care of terminating the string or freeing its - memory -

  • -
  • istringstream can be re-filled - (clear(); str(input);) -

  • -
-

- You can then use output-stringstreams like this: -

-	#ifdef HAVE_SSTREAM
-	std::ostringstream oss;
-	#else
-	std::ostrstream oss;
-	#endif
-	oss << "Name=" << m_name << ", number=" << m_number << std::endl;
-	...
-	#ifndef HAVE_SSTREAM
-	oss << std::ends; // terminate the char*-string
-	#endif
-	// str() returns char* for ostrstream and a string for ostringstream
-	// this also causes ostrstream to think that the buffer's memory
-	// is yours
-	m_label.set_text(oss.str());
-	#ifndef HAVE_SSTREAM
-	// let the ostrstream take care of freeing the memory
-	oss.freeze(false);
-	#endif
-      
-

- Input-stringstreams can be used similarly: -

- -
 
-std::string input;
-...
-#ifdef HAVE_SSTREAM
-std::istringstream iss(input);
-#else
-std::istrstream iss(input.c_str());
-#endif
-
-int i;
-iss >> i; 
-
- -

One (the only?) restriction is that an istrstream cannot be re-filled: -

- -
-std::istringstream iss(numerator);
-iss >> m_num;
-// this is not possible with istrstream
-iss.clear();
-iss.str(denominator);
-iss >> m_den;
- 
- -

-If you don't care about speed, you can put these conversions in - a template-function: -

-
-template <class X>
-void fromString(const string& input, X& any)
-{
-#ifdef HAVE_SSTREAM
-std::istringstream iss(input);
-#else
-std::istrstream iss(input.c_str());
-#endif
-X temp;
-iss >> temp;
-if (iss.fail())
-throw runtime_error(..)
-any = temp;
-}
-
- -

Another example of using stringstreams is in this howto. +Macro guard for libstdc++ changed, from _GLIBCPP_ to _GLIBCXX_.

-

There is additional information in the libstdc++-v2 info files, in -particular "info iostream". +

+Extension <ext/stdio_sync_filebuf.h> added.

-
Little or no wide character support
- -
No templatized iostreams
- -
Thread safety issues.
- -

This project is no longer maintained or supported, and the sources -archived. The code is considered replaced and rewritten. +

+Extension <ext/demangle.h> added.

-

- Third. + 4.0

-

The third generation GNU C++ library is called libstdc++, or -libstdc++-v3. +

+TR1 features first appear.

-

The subset commonly known as the Standard Template Library - (chapters 23 through 25, mostly) is adapted from the final release - of the SGI STL, with extensive changes. -

- -

A more formal description of the V3 goals can be found in the - official design document. -

- - -

Portability Notes

- -
Pre-ISO headers moved to backwards
-

The pre-ISO C++ headers (iostream.h etc.) are available, but inclusion - generates a warning that you are using deprecated headers. +

+Extension allocator <ext/array_allocator.h> added.

-

This compatibility layer is constructed by including the - standard C++ headers, and injecting any items in - std:: into the global namespace. -

-

For those of you new to ISO C++ (welcome, time travelers!), no, - that isn't a typo. Yes, the headers really have new names. - Marshall Cline's C++ FAQ Lite has a good explanation in item - [27.4]. -

- -

Some include adjustment may be required.

- -
Extension headers hash_map, hash_set moved to ext
+

+Extension codecvt specializations moved to <ext/codecvt_specializations.h>. +

-

Header files hash_map and hash_set -moved to ext/hash_map and ext/hash_set, -respectively. At the same time, all types in these files are enclosed -in namespace __gnu_cxx. +

+Removal of <ext/demangle.h>.

-
-No ios::nocreate/ios::noreplace. -
+

+ 4.1 +

-

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 -it can be left out for input-streams. +

+Removal of <cassert> from all standard headers: now has to be explicitly included for std::assert calls.

-

For output streams, "nocreate" is probably the default, -unless you specify std::ios::trunc ? To be safe, you can -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 ?). +

Extensions for policy-based data structures first added. New includes, +types, namespace pb_assoc.

-
-No stream::attach(int fd). -
- -

- Phil Edwards writes: It was considered and rejected for the ISO - standard. Not all environments use file descriptors. Of those - that do, not all of them use integers to represent them. -

-

- For a portable solution (among systems which use - filedescriptors), you need to implement a subclass of - std::streambuf (or - std::basic_streambuf<..>) which opens a file - given a descriptor, and then pass an instance of this to the - stream-constructor. -

- -

- An extension is available that implements this. - <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. -

- -

- For another example of this, refer to - fdstream example - by Nicolai Josuttis. +

Extensions for typelists added in <ext/typelist.h>.

-

Known Issues

- -
-container iterator types are not necessarily container value_type* -
- -

API History, User Visible Changes

+

Extension for policy-based basic_string first added: __gnu_cxx::__versa_string in <ext/vstring.h>. +

-

3.0.0

+

+ 4.2 +

+

Default visibility attributes applied to namespace std. Support for -fvisibility. +

-

3.1.0

-

3.2.0

-

3.3.0

+

TR1 <random>, <complex>, and C compatibility headers added.

+

Extensions for concurrent programming consolidated +into <ext/concurrence.h> and <ext/atomicity.h>, +including change of namespace to __gnu_cxx in some +cases. Added types +include _Lock_policy, __concurrence_lock_error, __concurrence_unlock_error, __mutex, __scoped_lock.

-

3.4.0

+

Extensions for type traits consolidated +into <ext/type_traits.h>. Additional traits are added +(__conditional_type, __enable_if, others.) +

-Macro guard for libstdc++ changed, from _GLIBCPP_ to _GLIBCXX_, to -accomodate a request from the C Pre Processor maintainer. +

Extensions for policy-based data structures revised. New includes, +types, namespace moved to __pb_ds. +

-

4.0.0

-

4.1.0

+

Extensions for debug mode modified: now nested in namespace +std::__debug and extensions in namespace +__gnu_cxx::__debug.

- how has to be explicitly included for std::assert calls. +

Extensions added: <ext/typelist.h> +and <ext/throw_allocator.h>. +

-

4.2.0

+

+ 4.3 +

-

4.3.0

+

+C++0X features first appear. +

-Header streamlining. +

TR1 <regex> and <cmath>'s mathematical special function added.

+

Backward include edit. +

+
    +
  • Removed: <algobase.h> <algo.h> <alloc.h> <bvector.h> <complex.h> +defalloc.h> <deque.h> <fstream.h> <function.h> <hash_map.h> <hash_set.h> +hashtable.h> <heap.h> <iomanip.h> <iostream.h> <istream.h> <iterator.h> +list.h> <map.h> <multimap.h> <multiset.h> <new.h> <ostream.h> <pair.h> <queue.h> +rope.h> <set.h> <slist.h> <stack.h> <streambuf.h> <stream.h> <tempbuf.h> +<tree.h> <vector.h> +
  • +
  • Added: <hash_map> and <hash_set>
  • +
  • Added in C++0x: <auto_ptr.h> and <binders.h>
  • +
-PCH files built but not installed. - -Namespace pb_ds moved to __gnu_pb_ds. +

+Header dependency streamlining. +

-C++OX features appear. +
    +
  • <algorithm> no longer includes <climits>, <cstring>, or <iosfwd>
  • +
  • <bitset> no longer includes <istream> or <ostream>, adds <iosfwd>
  • +
  • <functional> no longer includes <cstddef>
  • +
  • <iomanip> no longer includes <istream>, <istream>, or <functional>, adds <ioswd>
  • +
  • <numeric> no longer includes <iterator>
  • +
  • <string> no longer includes <algorithm> or <memory>
  • + +
  • <valarray> no longer includes <numeric> or <cstdlib>
  • +
  • <tr1/hashtable> no longer includes <memory> or <functional>
  • +
  • <tr1/memory> no longer includes <algorithm>
  • +
  • <tr1/random> no longer includes <algorithm> or <fstream>
  • +
-
-

- Fourth, and future -

+

+Debug mode for <unordered_map> and <unordered_set>. +

-
-

- Deprecation and Backwards Compatibility -

+

+Parallel mode first appears. +

-
-

- Links -

+

Variadic template implementations of items in <tuple> and + <functional>. +

-

-Migrating to gcc-4.1, by Dan Kegel. +

Default what implementations give more elaborate + exception strings for bad_cast, + bad_typeid, bad_exception, and + bad_alloc.

-Building the whole Debian archive with GCC 4.1: a summary, by Martin Michlmayr +PCH binary files no longer installed. Instead, the source files are installed.

-Migration guide for GCC-3.2 +Namespace pb_ds moved to __gnu_pb_ds.

diff --git a/libstdc++-v3/docs/html/17_intro/backwards_compatibility.html b/libstdc++-v3/docs/html/17_intro/backwards_compatibility.html new file mode 100644 index 0000000..bc1497b --- /dev/null +++ b/libstdc++-v3/docs/html/17_intro/backwards_compatibility.html @@ -0,0 +1,1073 @@ + + + + + + + + + + Backwards Compatibility + + + + + + +

Backwards Compatibility

+ +

+ The latest version of this document is always available at + + http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/backwards_compatibility.html. +

+ +

+ To the libstdc++ homepage. +

+ + +
+

+ First. +

+ +

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. +

+ +

Known Issues include many of the limitations of its immediate ancestor.

+ +

Portability notes and known implementation limitations are as follows.

+ +
No ios_base
+ +

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. +

+ +
No cout in ostream.h, no cin in istream.h
+ +

+ In earlier versions of the standard, + <fstream.h>, + <ostream.h> + and <istream.h> + used to define + cout, cin and so on. ISO C++ specifies that one needs to include + <iostream> + explicitly to get the required definitions. +

+

Some include adjustment may be required.

+ + +

This project is no longer maintained or supported, and the sources +archived. The code is considered replaced and rewritten. +

+ +
+

+ Second. +

+

The second generation GNU C++ library was called libstdc++, or +libstdc++-v2. It spans the time between libg++ and pre-ISO C++ +standardization and is usually associated with the following GCC +releases: egcs 1.x, gcc 2.95, and gcc 2.96. +

+ +

The STL portions of this library are based on SGI/HP STL release 3.11. +

+ +

Portability notes and known implementation limitations are as follows.

+ +
Namespace std:: not supported
+ +

+ Some care is required to support C++ compiler and or library + implementation that do not have the standard library in + namespace std. +

+

+ The following sections list some possible solutions to support compilers + that cannot ignore std::-qualified names. +

+ +

First, see if the compiler has a flag for this. Namespace + back-portability-issues are generally not a problem for g++ + compilers that do not have libstdc++ in std::, as + the compilers use -fno-honor-std (ignore + std::, :: = std::) by default. That + is, the responsibility for enabling or disabling + std:: is on the user; the maintainer does not have + to care about it. This probably applies to some other compilers + as well. +

+ +

Second, experiment with a variety of pre-processor tricks.

+ +

By defining std as a macro, fully-qualified namespace calls become global. Volia.

+ +
+#ifdef WICKEDLY_OLD_COMPILER
+# define std
+#endif
+
+(thanks to Juergen Heinzl who posted this solution on gnu.gcc.help) + +

Another pre-processor based approach is to define a +macro NAMESPACE_STD, which is defined to either +"" or "std" based on a compile-type test. On GNU +systems, this can be done with autotools by means of an autoconf test +(see below) for HAVE_NAMESPACE_STD, then using that to +set a value for the NAMESPACE_STD macro. At that point, +one is able to use NAMESPACE_STD::string, which will +evaluate to std::string or +::string (ie, in the global namespace on systems that do +not put string in std::).

+ +
+dnl @synopsis AC_CXX_NAMESPACE_STD
+dnl
+dnl If the compiler supports namespace std, define
+dnl HAVE_NAMESPACE_STD.
+dnl
+dnl @category Cxx
+dnl @author Todd Veldhuizen
+dnl @author Luc Maisonobe 
+dnl @version 2004-02-04
+dnl @license AllPermissive
+AC_DEFUN([AC_CXX_NAMESPACE_STD], [
+  AC_CACHE_CHECK(if g++ supports namespace std,
+  ac_cv_cxx_have_std_namespace,
+  [AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  AC_TRY_COMPILE([#include  
+                  std::istream& is = std::cin;],,
+  ac_cv_cxx_have_std_namespace=yes, ac_cv_cxx_have_std_namespace=no)
+  AC_LANG_RESTORE
+  ])
+  if test "$ac_cv_cxx_have_std_namespace" = yes; then
+    AC_DEFINE(HAVE_NAMESPACE_STD,,[Define if g++ supports namespace std. ])
+  fi
+])
+
+ +
Illegal iterator usage
+

+ The following illustrate implementation-allowed illegal iterator + use, and then correct use. +

+ +
  • you cannot do + ostream::operator<<(iterator) to print the + address of the iterator => use operator<< + &*iterator instead +

  • +
  • you cannot clear an iterator's reference + (iterator = 0) => use + iterator = iterator_type(); +

  • +
  • +if (iterator) won't work any + more => use if (iterator != iterator_type()) +

  • +
+ +
isspace from <cctype> is a macro +
+ +

Glibc 2.0.x and 2.1.x define <ctype.h> +functionality as macros (isspace, isalpha etc.). +

+ +

+This implementations of libstdc++, however, keep these functions as +macros, and so it is not back-portable to use fully qualified +names. For example: +

+ +
 
+#include <cctype> 
+int main() { std::isspace('X'); } 
+
+ +

Results in something like this: +

+ +
 
+std:: (__ctype_b[(int) ( ( 'X' ) )] & (unsigned short int) _ISspace ) ; 
+
+ + +

A solution is to modify a header-file so that the compiler tells +<ctype.h> to define functions instead of macros: +

+ +
+// This keeps isalnum, et al from being propagated as macros. 
+#if __linux__
+# define __NO_CTYPE 1
+#endif
+
+ +

Then, include <ctype.h> +

+ +

+Another problem arises if you put a using namespace std; +declaration at the top, and include <ctype.h>. This +will result in ambiguities between the definitions in the global +namespace (<ctype.h>) and the definitions in namespace +std:: (<cctype>). +

+ +
No vector::at, deque::at, string::at
+ +

+ One solution is to add an autoconf-test for this: +

+
+AC_MSG_CHECKING(for container::at)
+AC_TRY_COMPILE(
+[
+#include <vector>
+#include <deque>
+#include <string>
+	
+using namespace std;
+],
+[
+deque<int> test_deque(3);
+test_deque.at(2);
+vector<int> test_vector(2);
+test_vector.at(1);
+string test_string("test_string");
+test_string.at(3);
+],
+[AC_MSG_RESULT(yes)
+AC_DEFINE(HAVE_CONTAINER_AT)],
+[AC_MSG_RESULT(no)])
+
+ +

+If you are using other (non-GNU) compilers it might be a good idea +to check for string::at separately. +

+ +
No std::char_traits<char>::eof
+ +

+Use some kind of autoconf test, plus this: +

+
 
+#ifdef HAVE_CHAR_TRAITS
+#define CPP_EOF std::char_traits<char>::eof()
+#else
+#define CPP_EOF EOF
+#endif
+
+ +
No string::clear
+ +

+ There are two functions for deleting the contents of a string: + clear and erase (the latter + returns the string). +

+ +
+void 
+clear() { _M_mutate(0, this->size(), 0); }
+
+
+basic_string& 
+erase(size_type __pos = 0, size_type __n = npos)
+{ 
+  return this->replace(_M_check(__pos), _M_fold(__pos, __n),
+                          _M_data(), _M_data()); 
+}
+
+ +

+ Unfortunately, ut clear is not + implemented in this version, so you should use + erase (which is probably faster than + operator=(charT*)). +

+ +
Removal of ostream::form and +istream::scan extensions
+ +

These are no longer supported. Please use + + stringstreams instead. +

+ +
No basic_stringbuf, basic_stringstream
+ +

+Although the ISO standard +i/ostringstream-classes are provided, (<sstream>), for compatibility with older implementations the pre-ISO i/ostrstream (<strstream>) interface is also provided, with these caveats: +

+ +
    +
  • strstream is considered to be + deprecated +

  • +
  • strstream is limited to + char +

  • +
  • with ostringstream you don't + have to take care of terminating the string or freeing its + memory +

  • +
  • istringstream can be re-filled + (clear(); str(input);) +

  • +
+

+ You can then use output-stringstreams like this: +

+ +
+#ifdef HAVE_SSTREAM
+# include <sstream>
+#else
+# include <strstream>
+#endif
+
+#ifdef HAVE_SSTREAM
+  std::ostringstream oss;
+#else
+  std::ostrstream oss;
+#endif
+
+oss << "Name=" << m_name << ", number=" << m_number << std::endl;
+...
+#ifndef HAVE_SSTREAM
+  oss << std::ends; // terminate the char*-string
+#endif
+
+// str() returns char* for ostrstream and a string for ostringstream
+// this also causes ostrstream to think that the buffer's memory
+// is yours
+m_label.set_text(oss.str());
+#ifndef HAVE_SSTREAM
+  // let the ostrstream take care of freeing the memory
+  oss.freeze(false);
+#endif
+
+ +

+ Input-stringstreams can be used similarly: +

+ +
 
+std::string input;
+...
+#ifdef HAVE_SSTREAM
+std::istringstream iss(input);
+#else
+std::istrstream iss(input.c_str());
+#endif
+
+int i;
+iss >> i; 
+
+ +

One (the only?) restriction is that an istrstream cannot be re-filled: +

+ +
+std::istringstream iss(numerator);
+iss >> m_num;
+// this is not possible with istrstream
+iss.clear();
+iss.str(denominator);
+iss >> m_den;
+ 
+ +

+If you don't care about speed, you can put these conversions in + a template-function: +

+
+template <class X>
+void fromString(const string& input, X& any)
+{
+#ifdef HAVE_SSTREAM
+std::istringstream iss(input);
+#else
+std::istrstream iss(input.c_str());
+#endif
+X temp;
+iss >> temp;
+if (iss.fail())
+throw runtime_error(..)
+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". +

+ +
Little or no wide character support
+ +
No templatized iostreams
+ +
Thread safety issues
+ +

This project is no longer maintained or supported, and the sources +archived. The code is considered replaced and rewritten. +

+ + +
+

+ Third. +

+

The third generation GNU C++ library is called libstdc++, or +libstdc++-v3. +

+ +

The subset commonly known as the Standard Template Library + (chapters 23 through 25, mostly) is adapted from the final release + 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.

+ +
Pre-ISO headers moved to backwards or removed
+ +

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. +

+ +

This compatibility layer is constructed by including the + standard C++ headers, and injecting any items in + std:: into the global namespace. +

+

For those of you new to ISO C++ (welcome, time travelers!), no, + that isn't a typo. Yes, the headers really have new names. + Marshall Cline's C++ FAQ Lite has a good explanation in item + [27.4]. +

+ +

Some include adjustment may be required. What follows is an +autoconf test that defines PRE_STDCXX_HEADERS when they +exist.

+ +
+# AC_HEADER_PRE_STDCXX
+AC_DEFUN([AC_HEADER_PRE_STDCXX], [
+  AC_CACHE_CHECK(for pre-ISO C++ include files,
+  ac_cv_cxx_pre_stdcxx,
+  [AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -Wno-deprecated"	
+
+  # Omit defalloc.h, as compilation with newer compilers is problematic.
+  AC_TRY_COMPILE([
+  #include <new.h>
+  #include <iterator.h>
+  #include <alloc.h>
+  #include <set.h>
+  #include <hashtable.h>
+  #include <hash_set.h>
+  #include <fstream.h>
+  #include <tempbuf.h>
+  #include <istream.h>
+  #include <bvector.h>
+  #include <stack.h>
+  #include <rope.h>
+  #include <complex.h>
+  #include <ostream.h>
+  #include <heap.h>
+  #include <iostream.h>
+  #include <function.h>
+  #include <multimap.h>
+  #include <pair.h>
+  #include <stream.h>
+  #include <iomanip.h>
+  #include <slist.h>
+  #include <tree.h>
+  #include <vector.h>
+  #include <deque.h>
+  #include <multiset.h>
+  #include <list.h>
+  #include <map.h>
+  #include <algobase.h>
+  #include <hash_map.h>
+  #include <algo.h>
+  #include <queue.h>
+  #include <streambuf.h>
+  ],,
+  ac_cv_cxx_pre_stdcxx=yes, ac_cv_cxx_pre_stdcxx=no)
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
+  ])
+  if test "$ac_cv_cxx_pre_stdcxx" = yes; then
+    AC_DEFINE(PRE_STDCXX_HEADERS,,[Define if pre-ISO C++ header files are present. ])
+  fi
+])
+
+ +

Porting between pre-ISO headers and ISO headers is simple: headers +like <vector.h> can be replaced with <vector> and a using +directive 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. +

+ +
Extension headers hash_map, hash_set moved to ext or backwards
+ +

Header files hash_map and hash_set moved +to ext/hash_map and ext/hash_set, +respectively. At the same time, all types in these files are enclosed +in namespace __gnu_cxx. Later versions move deprecate +these files, and suggest using TR1's unordered_map +and unordered_set instead. +

+ +

The following autoconf tests check for working HP/SGI hash containers. +

+ +
+# AC_HEADER_EXT_HASH_MAP
+AC_DEFUN([AC_HEADER_EXT_HASH_MAP], [
+  AC_CACHE_CHECK(for ext/hash_map,
+  ac_cv_cxx_ext_hash_map,
+  [AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -Werror"	
+  AC_TRY_COMPILE([#include ], [using __gnu_cxx::hash_map;],
+  ac_cv_cxx_ext_hash_map=yes, ac_cv_cxx_ext_hash_map=no)
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
+  ])
+  if test "$ac_cv_cxx_ext_hash_map" = yes; then
+    AC_DEFINE(HAVE_EXT_HASH_MAP,,[Define if ext/hash_map is present. ])
+  fi
+])
+
+ +
+# AC_HEADER_EXT_HASH_SET
+AC_DEFUN([AC_HEADER_EXT_HASH_SET], [
+  AC_CACHE_CHECK(for ext/hash_set,
+  ac_cv_cxx_ext_hash_set,
+  [AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -Werror"	
+  AC_TRY_COMPILE([#include ], [using __gnu_cxx::hash_set;],
+  ac_cv_cxx_ext_hash_set=yes, ac_cv_cxx_ext_hash_set=no)
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
+  ])
+  if test "$ac_cv_cxx_ext_hash_set" = yes; then
+    AC_DEFINE(HAVE_EXT_HASH_SET,,[Define if ext/hash_set is present. ])
+  fi
+])
+
+ + +
+No ios::nocreate/ios::noreplace. +
+ +

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 +it can be left out for input-streams. +

+ +

For output streams, "nocreate" is probably the default, +unless you specify std::ios::trunc ? To be safe, you can +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 ?). +

+ + +
+No stream::attach(int fd) +
+ +

+ Phil Edwards writes: It was considered and rejected for the ISO + standard. Not all environments use file descriptors. Of those + that do, not all of them use integers to represent them. +

+ +

+ For a portable solution (among systems which use + filedescriptors), you need to implement a subclass of + std::streambuf (or + std::basic_streambuf<..>) which opens a file + given a descriptor, and then pass an instance of this to the + stream-constructor. +

+ +

+ An extension is available that implements this. + <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. +

+ +

+ For another example of this, refer to + fdstream example + by Nicolai Josuttis. +

+ +
+Support for C++98 dialect. +
+ +

Check for complete library coverage of the C++1998/2003 standard. +

+ +
+
+# AC_HEADER_STDCXX_98
+AC_DEFUN([AC_HEADER_STDCXX_98], [
+  AC_CACHE_CHECK(for ISO C++ 98 include files,
+  ac_cv_cxx_stdcxx_98,
+  [AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  AC_TRY_COMPILE([
+    #include <cassert>
+    #include <cctype>
+    #include <cerrno>
+    #include <cfloat>
+    #include <ciso646>
+    #include <climits>
+    #include <clocale>
+    #include <cmath>
+    #include <csetjmp>
+    #include <csignal>
+    #include <cstdarg>
+    #include <cstddef>
+    #include <cstdio>
+    #include <cstdlib>
+    #include <cstring>
+    #include <ctime>
+
+    #include <algorithm>
+    #include <bitset>
+    #include <complex>
+    #include <deque>
+    #include <exception>
+    #include <fstream>
+    #include <functional>
+    #include <iomanip>
+    #include <ios>
+    #include <iosfwd>
+    #include <iostream>
+    #include <istream>
+    #include <iterator>
+    #include <limits>
+    #include <list>
+    #include <locale>
+    #include <map>
+    #include <memory>
+    #include <new>
+    #include <numeric>
+    #include <ostream>
+    #include <queue>
+    #include <set>
+    #include <sstream>
+    #include <stack>
+    #include <stdexcept>
+    #include <streambuf>
+    #include <string>
+    #include <typeinfo>
+    #include <utility>
+    #include <valarray>
+    #include <vector>
+  ],,
+  ac_cv_cxx_stdcxx_98=yes, ac_cv_cxx_stdcxx_98=no)
+  AC_LANG_RESTORE
+  ])
+  if test "$ac_cv_cxx_stdcxx_98" = yes; then
+    AC_DEFINE(STDCXX_98_HEADERS,,[Define if ISO C++ 1998 header files are present. ])
+  fi
+])
+
+ + +
+Support for C++TR1 dialect. +
+ +

Check for library coverage of the TR1 standard. +

+ +
+
+# AC_HEADER_STDCXX_TR1
+AC_DEFUN([AC_HEADER_STDCXX_TR1], [
+  AC_CACHE_CHECK(for ISO C++ TR1 include files,
+  ac_cv_cxx_stdcxx_tr1,
+  [AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  AC_TRY_COMPILE([
+  #include <tr1/array>
+  #include <tr1/ccomplex>
+  #include <tr1/cctype>
+  #include <tr1/cfenv>
+  #include <tr1/cfloat>
+  #include <tr1/cinttypes>
+  #include <tr1/climits>
+  #include <tr1/cmath>
+  #include <tr1/complex>
+  #include <tr1/cstdarg>
+  #include <tr1/cstdbool>
+  #include <tr1/cstdint>
+  #include <tr1/cstdio>
+  #include <tr1/cstdlib>
+  #include <tr1/ctgmath>
+  #include <tr1/ctime>
+  #include <tr1/cwchar>
+  #include <tr1/cwctype>
+  #include <tr1/functional>
+  #include <tr1/memory>
+  #include <tr1/random>
+  #include <tr1/regex>
+  #include <tr1/tuple>
+  #include <tr1/type_traits>
+  #include <tr1/unordered_set>
+  #include <tr1/unordered_map>
+  #include <tr1/utility>
+  ],,
+  ac_cv_cxx_stdcxx_tr1=yes, ac_cv_cxx_stdcxx_tr1=no)
+  AC_LANG_RESTORE
+  ])
+  if test "$ac_cv_cxx_stdcxx_tr1" = yes; then
+    AC_DEFINE(STDCXX_TR1_HEADERS,,[Define if ISO C++ TR1 header files are present. ])
+  fi
+])
+
+ +

An alternative is to check just for specific TR1 includes, such as <unordered_map> and <unordered_set>. +

+ +
+# AC_HEADER_TR1_UNORDERED_MAP
+AC_DEFUN([AC_HEADER_TR1_UNORDERED_MAP], [
+  AC_CACHE_CHECK(for tr1/unordered_map,
+  ac_cv_cxx_tr1_unordered_map,
+  [AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  AC_TRY_COMPILE([#include <tr1/unordered_map>], [using std::tr1::unordered_map;],
+  ac_cv_cxx_tr1_unordered_map=yes, ac_cv_cxx_tr1_unordered_map=no)
+  AC_LANG_RESTORE
+  ])
+  if test "$ac_cv_cxx_tr1_unordered_map" = yes; then
+    AC_DEFINE(HAVE_TR1_UNORDERED_MAP,,[Define if tr1/unordered_map is present. ])
+  fi
+])
+
+ +
+# AC_HEADER_TR1_UNORDERED_SET
+AC_DEFUN([AC_HEADER_TR1_UNORDERED_SET], [
+  AC_CACHE_CHECK(for tr1/unordered_set,
+  ac_cv_cxx_tr1_unordered_set,
+  [AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  AC_TRY_COMPILE([#include <tr1/unordered_set>], [using std::tr1::unordered_set;],
+  ac_cv_cxx_tr1_unordered_set=yes, ac_cv_cxx_tr1_unordered_set=no)
+  AC_LANG_RESTORE
+  ])
+  if test "$ac_cv_cxx_tr1_unordered_set" = yes; then
+    AC_DEFINE(HAVE_TR1_UNORDERED_SET,,[Define if tr1/unordered_set is present. ])
+  fi
+])
+
+ + + +
+Support for C++0x dialect. +
+ +

Check for baseline language coverage in the compiler for the C++0xstandard. +

+ +
+# AC_COMPILE_STDCXX_OX
+AC_DEFUN([AC_COMPILE_STDCXX_0X], [
+  AC_CACHE_CHECK(if g++ supports C++0x features without additional flags,
+  ac_cv_cxx_compile_cxx0x_native,
+  [AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  AC_TRY_COMPILE([
+  template <typename T>
+    struct check 
+    {
+      static_assert(sizeof(int) <= sizeof(T), "not big enough");
+    };
+
+    typedef check<check<bool>> right_angle_brackets;
+
+    int a;
+    decltype(a) b;
+
+    typedef check<int> check_type;
+    check_type c;
+    check_type&& cr = c;],,
+  ac_cv_cxx_compile_cxx0x_native=yes, ac_cv_cxx_compile_cxx0x_native=no)
+  AC_LANG_RESTORE
+  ])
+
+  AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x,
+  ac_cv_cxx_compile_cxx0x_cxx,
+  [AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -std=c++0x"	
+  AC_TRY_COMPILE([
+  template <typename T>
+    struct check 
+    {
+      static_assert(sizeof(int) <= sizeof(T), "not big enough");
+    };
+
+    typedef check<check<bool>> right_angle_brackets;
+
+    int a;
+    decltype(a) b;
+
+    typedef check<int> check_type;
+    check_type c;
+    check_type&& cr = c;],,
+  ac_cv_cxx_compile_cxx0x_cxx=yes, ac_cv_cxx_compile_cxx0x_cxx=no)
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
+  ])
+
+  AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x,
+  ac_cv_cxx_compile_cxx0x_gxx,
+  [AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -std=gnu++0x"	
+  AC_TRY_COMPILE([
+  template <typename T>
+    struct check 
+    {
+      static_assert(sizeof(int) <= sizeof(T), "not big enough");
+    };
+
+    typedef check<check<bool>> right_angle_brackets;
+
+    int a;
+    decltype(a) b;
+
+    typedef check<int> check_type;
+    check_type c;
+    check_type&& cr = c;],,
+  ac_cv_cxx_compile_cxx0x_gxx=yes, ac_cv_cxx_compile_cxx0x_gxx=no)
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
+  ])
+
+  if test "$ac_cv_cxx_compile_cxx0x_native" = yes || 
+     test "$ac_cv_cxx_compile_cxx0x_cxx" = yes || 
+     test "$ac_cv_cxx_compile_cxx0x_gxx" = yes; then
+    AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ])
+  fi
+])
+
+ + +

Check for library coverage of the C++0xstandard. +

+ +
+
+# AC_HEADER_STDCXX_0X
+AC_DEFUN([AC_HEADER_STDCXX_0X], [
+  AC_CACHE_CHECK(for ISO C++ 0x include files,
+  ac_cv_cxx_stdcxx_0x,
+  [AC_REQUIRE([AC_COMPILE_STDCXX_0X])
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -std=gnu++0x"	
+
+  AC_TRY_COMPILE([
+    #include <cassert>
+    #include <ccomplex>
+    #include <cctype>
+    #include <cerrno>
+    #include <cfenv>
+    #include <cfloat>
+    #include <cinttypes>
+    #include <ciso646>
+    #include <climits>
+    #include <clocale>
+    #include <cmath>
+    #include <csetjmp>
+    #include <csignal>
+    #include <cstdarg>
+    #include <cstdbool>
+    #include <cstddef>
+    #include <cstdint>
+    #include <cstdio>
+    #include <cstdlib>
+    #include <cstring>
+    #include <ctgmath>
+    #include <ctime>
+    #include <cwchar>
+    #include <cwctype>
+
+    #include <algorithm>
+    #include <array>
+    #include <bitset>
+    #include <complex>
+    #include <deque>
+    #include <exception>
+    #include <fstream>
+    #include <functional>
+    #include <iomanip>
+    #include <ios>
+    #include <iosfwd>
+    #include <iostream>
+    #include <istream>
+    #include <iterator>
+    #include <limits>
+    #include <list>
+    #include <locale>
+    #include <map>
+    #include <memory>
+    #include <new>
+    #include <numeric>
+    #include <ostream>
+    #include <queue>
+    #include <random>
+    #include <regex>
+    #include <set>
+    #include <sstream>
+    #include <stack>
+    #include <stdexcept>
+    #include <streambuf>
+    #include <string>
+    #include <tuple>
+    #include <typeinfo>
+    #include <type_traits>
+    #include <unordered_map>
+    #include <unordered_set>
+    #include <utility>
+    #include <valarray>
+    #include <vector>
+  ],,
+  ac_cv_cxx_stdcxx_0x=yes, ac_cv_cxx_stdcxx_0x=no)
+  AC_LANG_RESTORE
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  ])
+  if test "$ac_cv_cxx_stdcxx_0x" = yes; then
+    AC_DEFINE(STDCXX_0X_HEADERS,,[Define if ISO C++ 0x header files are present. ])
+  fi
+])
+
+ +

As is the case for TR1 support, these autoconf macros can be made for a finer-grained, per-header-file check. For <unordered_map> +

+ +
+
+# AC_HEADER_UNORDERED_MAP
+AC_DEFUN([AC_HEADER_UNORDERED_MAP], [
+  AC_CACHE_CHECK(for unordered_map,
+  ac_cv_cxx_unordered_map,
+  [AC_REQUIRE([AC_COMPILE_STDCXX_0X])
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -std=gnu++0x"	
+  AC_TRY_COMPILE([#include <unordered_map>], [using std::unordered_map;],
+  ac_cv_cxx_unordered_map=yes, ac_cv_cxx_unordered_map=no)
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
+  ])
+  if test "$ac_cv_cxx_unordered_map" = yes; then
+    AC_DEFINE(HAVE_UNORDERED_MAP,,[Define if unordered_map is present. ])
+  fi
+])
+
+ +
+# AC_HEADER_UNORDERED_SET
+AC_DEFUN([AC_HEADER_UNORDERED_SET], [
+  AC_CACHE_CHECK(for unordered_set,
+  ac_cv_cxx_unordered_set,
+  [AC_REQUIRE([AC_COMPILE_STDCXX_0X])
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -std=gnu++0x"	
+  AC_TRY_COMPILE([#include <unordered_set>], [using std::unordered_set;],
+  ac_cv_cxx_unordered_set=yes, ac_cv_cxx_unordered_set=no)
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
+  ])
+  if test "$ac_cv_cxx_unordered_set" = yes; then
+    AC_DEFINE(HAVE_UNORDERED_SET,,[Define if unordered_set is present. ])
+  fi
+])
+
+ + +
+Container iterator_type is not necessarily container value_type* +
+ + +
+

+ Fourth, and future +

+ +
+

+ Links +

+ +

+Migrating to gcc-4.1, by Dan Kegel. +

+ +

+Building the whole Debian archive with GCC 4.1: a summary, by Martin Michlmayr +

+ +

+Migration guide for GCC-3.2 +

+ + + + diff --git a/libstdc++-v3/docs/html/17_intro/howto.html b/libstdc++-v3/docs/html/17_intro/howto.html index d3bd6df..3e1bba0 100644 --- a/libstdc++-v3/docs/html/17_intro/howto.html +++ b/libstdc++-v3/docs/html/17_intro/howto.html @@ -34,123 +34,309 @@

Contents


-

Header Files

-

The C++ standard specifies 50 header files that must be +

Header Files

+

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 certain header, the - contents of that header, as defined by the Standard, become + only rule is that when one #include's a header, the + contents of that header become available, no matter how.

-

C++98/03 include files: +

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, ie -std=c++98 or -std=gnu++98.

-
-C++ Library Headers
-algorithm	ios      	new     	stack
-bitset		iosfwd   	numeric 	stdexcept
-complex     	iostream 	ostream 	streambuf
-    		istream  	queue      	string
-deque      	iterator 			
-exception  	limits   			typeinfo
-fstream    	list     	set
-functional 	locale   	map
-iomanip    	memory   	sstream 	
-
-C++ Headers for C Library Facilities
-cassert   	cfloat        	cmath         	cstddef     
-ccomplex  		     	csetjmp       	cstdio      	ctime
-cctype    	ciso646       	csignal			    	
-cerrno    	climits       	cstdarg       	cstdlib     	cwchar
-	    	clocale       		      	cstring     	cwctype
-
-

C++0x include files: +

+ + + + + + + +
C++98 Library Headers
<algorithm><iomanip><list><ostream><streambuf>
<bitset><ios><locale><queue><string>
<complex><iosfwd><map><set><typeinfo>
<deque><iostream><memory><sstream><utility>
<exception><istream><new><stack><valarray>
<fstream><iterator><numeric><stdexcept><vector>
<functional><limits>
+ +

+ +
+ + + + +
C++98 Headers for C Library Facilities
<cassert><ciso646><csetjmp><cstdio><ctime>
<cctype><climits><csignal><cstdlib><cwchar>
<cerrno><clocale><cstdarg><cstring><cwctype>
<cfloat><cmath><cstddef>
+ +

C++0x include files. These are only available in C++0x compilation mode, ie -std=c++0x or -std=gnu++0x.

+ +
+ + + + + + + + +
C++0x Library Headers
<algorithm><iomanip><locale><regex><tuple>
<array><ios><map><set><typeinfo>
<bitset><iosfwd><memory><sstream><type_traits>
<complex><iostream><new><stack><unordered_map>
<deque><istream><numeric><stdexcept><unordered_set>
<exception><iterator><ostream><streambuf><utility>
<fstream><limits><queue><string><valarray>
<functional><list><random><system_error><vector>
+ +

+ +
+ + + + + +
C++0x Headers for C Library Facilities
<cassert><cfloat><cmath><cstddef><ctgmath>
<ccomplex><cinttypes><csetjmp><cstdint><ctime>
<cctype><ciso646><csignal><cstdio><cuchar>
<cerrno><climits><cstdarg><cstdlib><cwchar>
<cfenv><clocale><cstdbool><cstring><cwctype>
+ + +

In addition, TR1 includes as: +

+ +
+ + + +
TR1 Library Headers
<tr1/array><tr1/memory><tr1/regex><tr1/type_traits><tr1/unordered_set>
<tr1/complex><tr1/random><tr1/tuple><tr1/unordered_map><tr1/utility>
<tr1/functional>
+ +

+ +
+ + + +
TR1 Headers for C Library Facilities
<tr1/cmath><tr1/cfloat><tr1/cstdarg><tr1/cstdio><tr1/ctime>
<tr1/ccomplex><tr1/cinttypes><tr1/cstdbool><tr1/cstdlib><tr1/cwchar>
<tr1/cfenv><tr1/climits><tr1/cstdint><tr1/ctgmath><tr1/cwctype>
+ +

Also included are files for the C++ ABI interface: +

+
+ +
C++ ABI Headers
<cxxabi.h><cxxabi_forced.h>
+ +

And a large variety of extensions. +

+ +
+ + + + + + +
Extension Headers
<ext/algorithm><ext/debug_allocator.h><ext/mt_allocator.h><ext/pod_char_traits.h><ext/stdio_sync_filebuf.h>
<ext/array_allocator.h><ext/enc_filebuf.h><ext/new_allocator.h><ext/pool_allocator.h><ext/throw_allocator.h>
<ext/atomicity.h><ext/functional><ext/numeric><ext/rb_tree><ext/typelist.h>
<ext/bitmap_allocator.h><ext/iterator><ext/numeric_traits.h><ext/rope><ext/type_traits.h>
<ext/codecvt_specializations.h><ext/malloc_allocator.h><ext/pb_ds/assoc_container.h><ext/slist><ext/vstring.h>
<ext/concurrence.h><ext/memory><ext/pb_ds/priority_queue.h><ext/stdio_filebuf.h>
+ +

+ +
+ + +
Extension Debug Headers
<debug/bitset><debug/list><debug/set><debug/unordered_map><debug/vector>
<debug/deque><debug/map><debug/string><debug/unordered_set>
+ +

+ +
+ +
Extension Parallel Headers
<parallel/algorithm><parallel/numeric>
+ +
+

Recipes for mixing headers

+ +

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 +

+
-C++ Library Headers
-algorithm	ios      	new     	stack
-array      	iosfwd   	numeric 	stdexcept
-bitset     	iostream 	ostream 	streambuf
-complex    	istream  	queue      	string
-deque      	iterator 	random		system_error
-exception  	limits   	regex      	tuple
-fstream    	list     	set        	type_traits
-functional 	locale   	map        	typeinfo
-iomanip    	memory   	sstream 	
-
-C++ Headers for C Library Facilities
-cassert   	cfloat        	cmath         	cstddef     	ctgmath
-ccomplex  	cinttypes     	csetjmp       	cstdio      	ctime
-cctype    	ciso646       	csignal       	cstdint     	cuchar
-cerrno    	climits       	cstdarg       	cstdlib     	cwchar
-cfenv     	clocale       	cstdbool      	cstring     	cwctype
+#include <array>
+#include <functional>
 
-

In addition, TR1 includes as: +

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: +

+
-C++ Library Headers
-tr1/array, tr1/complex, tr1/functional, tr1/memory, tr1/random,
-tr1/regex, tr1/tuple, tr1/type_traits, tr1/unordered_map,
-tr1/unordered_set, tr1/utility
-
-C++ Headers for C Library Facilities
-tr1/cmath, tr1/ccomplex, tr1/cfenv, tr1/cfloat, tr1/cinttypes,
-tr1/climits, tr1/cstdarg, tr1/cstdbool, tr1/cstdint, tr1/cstdio,
-tr1/cstdlib, tr1/ctgmath, tr1/ctime, tr1/cwchar, tr1/cwctype
-
-C++ Compatibility Headers for C Library Facilities
-tr1/complex.h, tr1/ctype.h, tr1/float.h, tr1/limits.h, tr1/math.h,
-tr1/stdarg.h, tr1/stdbool.h, tr1/stdint.h, tr1/stdio.h, tr1/stdlib.h,
-tr1/tgmath.h, tr1/wchar.h, tr1/wctype.h
+#include <tr1/type_traits>
+#include <type_traits>
 
+

Several parts of C++0x diverge quite substantially from TR1 predecessors. +

+ +
-

Headers and namespace std::

+

The C Headers and namespace std

- You should not use the C-headers (except for system-level - headers) from C++ programs. Instead, you should use a set of - headers that are named by prepending 'c' and, as usual, - omitting the extension (.h). For example, instead of using - <math.h>, you - should use <cmath>. In some cases this has - the advantage that the C++-header is more standardized than - the C-header (i.e. <ctime> (almost) - corresponds to either <time.h> or <sys/time.h>). - - The standard specifies that if you include the C-style header - (<math.h> in - this case), the symbols will be available both in the global - namespace and in namespace std:: (but - libstdc++ does not yet have fully compliant headers) On the - other hand, if you include only the new header (i.e. <cmath>), the symbols - will only be defined in namespace std:: - (and macros will be converted to inline-functions). + 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.

-

FIXME: this is no longer accurate.

-

- For more information on this, and for information on how the - GNU C++ implementation might reuse ("shadow") the C - library-functions, have a look at - www.cantrip.org. -

+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. +

+ +
+

Precompiled Headers

+ +

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. +

+
-

Namespace std::

+

Namespaces

+ + +

There are three main namespaces. +

+ +
    +
  • std +

    The ISO C++ standards specify that "all library entities are defined +within namespace std." This includes namepaces 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. +

+ + +
+

Namespace std::

One standard requirement is that the library components are defined @@ -167,37 +353,46 @@ should not be used in a global context, like header files. qualified name for 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 verbage becomes unweidly.) +cases where the qualified verbiage becomes unwieldy.)


-

Using namespace composition

+

Using namespace composition

- Gtk-- defines - most of its classes in namespace Gtk::. Thus, it was possible to - adapt Gtk-- to namespace std:: by using a C++-feature called +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 - you put a using-declaration into a + 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;
-	  class Window { ... }
-	  }
-	
+
+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 you don't have to use - std::string in this header, but still + 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 (::) unless the user does - using namespace Gtk; (which is not recommended - practice for Gtk--, so it is not a problem). Additionally, the - using-declarations are wrapped in macros that + 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 @@ -206,7 +401,103 @@ cases where the qualified verbage becomes unweidly.)


-

The Standard C++ library and multithreading

+

Macros for libstdc++

+ +

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. +
+
+ +
+

The Standard C++ library and multithreading

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++ @@ -419,107 +710,11 @@ cases where the qualified verbage becomes unweidly.) to the FAQ.

-
-

Macros for libstdc++

- -

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. -
- -

Return to top of page or to the FAQ.

diff --git a/libstdc++-v3/docs/html/18_support/howto.html b/libstdc++-v3/docs/html/18_support/howto.html index 87dd8a5..dc5bc2a 100644 --- a/libstdc++-v3/docs/html/18_support/howto.html +++ b/libstdc++-v3/docs/html/18_support/howto.html @@ -281,9 +281,6 @@

        std::set_terminate(std::abort);
-

Return to top of page or - to the FAQ. -

This function will attempt to write to stderr. If your application @@ -292,6 +289,11 @@ unspecified manner.

+

Return to top of page or + to the FAQ. +

+ +

Dynamic memory management

There are six flavors each of new and diff --git a/libstdc++-v3/docs/html/20_util/allocator.html b/libstdc++-v3/docs/html/20_util/allocator.html index 409c08b..951c12d 100644 --- a/libstdc++-v3/docs/html/20_util/allocator.html +++ b/libstdc++-v3/docs/html/20_util/allocator.html @@ -84,34 +84,47 @@

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. BUT - this - method is horribly slow. -

-

Or we can keep old memory around, and reuse it in a pool to save time. - The old libstdc++-v2 used a memory pool, and so do we. As of 3.0, - it's - on by default. The pool 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 we don't have to call operators new and - delete to pass the memory on, either, which is a speed bonus. - BUT... -

-

What about threads? No problem: in a threadsafe environment, the - memory pool is manipulated atomically, so you can grow a container in - one thread and shrink it in another, etc. BUT what - if threads in libstdc++ aren't set up properly? - That's been answered already. -

-

BUT what if you want to use your own allocator? What - if you plan on using a runtime-loadable version of malloc() which uses - shared telepathic anonymous mmap'd sections serializable over a - network, so that memory requests should go through malloc? - And what if you need to debug it? -

+ 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 std::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. +

+ +

Versions of libstdc++ prior to 3.4 cache allocations in a memory + pool, instead of passing through to call the global allocation + operators (ie, __gnu_cxx::pool_allocator). More + recent versions default to the + simpler __gnu_cxx::new_allocator. +

+

Implementation details of std::allocator

@@ -335,6 +348,11 @@ <ext/array_allocator.h> 4.0.0 + + __gnu_cxx::throw_allocator<T> + <ext/throw_allocator.h> + 4.2.0 +

More details on each of these extension allocators follows.

@@ -371,6 +389,12 @@ 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 exceptinos 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. diff --git a/libstdc++-v3/docs/html/documentation.html b/libstdc++-v3/docs/html/documentation.html index 92ce87b..d2a736f 100644 --- a/libstdc++-v3/docs/html/documentation.html +++ b/libstdc++-v3/docs/html/documentation.html @@ -26,7 +26,7 @@ href="http://gcc.gnu.org/libstdc++">project to implement the ISO annex D, extensions as described by TR1, and future C++ library standards still in progress. For those who want to see exactly how far the project has come, or just want the latest bleeding-edge code, the -up-to-date source is always publically available over anonymous SVN, +up-to-date source is always publicly available over anonymous SVN, and can be browsed over the web.

    @@ -34,13 +34,6 @@ href="http://gcc.gnu.org/svn.html">web.

    Stable versions of libstdc++ are included with releases of the GCC compilers.

    - -
  • diff --git a/libstdc++-v3/docs/html/ext/concurrence.html b/libstdc++-v3/docs/html/ext/concurrence.html new file mode 100644 index 0000000..e621bc9 --- /dev/null +++ b/libstdc++-v3/docs/html/ext/concurrence.html @@ -0,0 +1,342 @@ + + + + + + + + + + Concurrency Support + + + + + + +

    Concurrency Support

    + +

    + The latest version of this document is always available at + + http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/concurrence.html. +

    + +

    + To the libstdc++ homepage. +

    + + + + +
    + + +

    The interface for concurrency support is divided into two files: +<ext/atomicity.h> which provides support for atomic operations, +and <ext/concurrence.h>, which provides mutex and lock objects +as well as compile-time data structures for querying thread +support.

    + +

    It is expected that support for concurrence will evolve into what +is specified in the draft C++0x standard.

    + +

    + Atomics Interface +

    + +

    +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. +

    + +

    + Pthread Interface +

    + +

    A thin layer above IEEE 1003.1 (ie pthreads) is used to abastract +the thread interface for GCC. This layer is called "gthread," and is +comprised of one header file that wraps the host's default thread layer with +a POSIX-like interfaces. +

    + +

    The file <gthr-default.h> points to the deduced wrapper for +the current host. In libstdc++ implementation files, +<bits/gthr.h> is used to select the proper gthreads file. +

    + +

    Within libstdc++ sources, all calls to underlying thread functionality +use this layer. More detail as to the specific interface can be found in the source documentation. +

    + +

    By design, the gthread layer is interoperable with the types, +functions, and usage found in the usual <pthread.h> file, +including pthread_t, pthread_once_t, pthread_create, +etc. +

    + +

    + Concurrence Interface +

    + +

    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. +

    + +

    Typical usage of the last two constructs is demonstrated as follows: +

    + +
    +#include <ext/concurrence.h>
    +
    +namespace
    +{
    +  __gnu_cxx::__mutex safe_base_mutex;
    +} // anonymous namespace
    +
    +namespace other
    +{
    +  void
    +  foo()
    +  {
    +    __gnu_cxx::__scoped_lock sentry(safe_base_mutex);
    +    for (int i = 0; i < max;  ++i)
    +      {
    +	_Safe_iterator_base* __old = __iter;
    +	__iter = __iter->_M_next;
    +	__old->_M_detach_single();
    +      }
    +}
    +
    + +

    In this sample code, an anonymous namespace is used to keep +the __mutex private to the compilation unit, +and __scoped_lock is used to guard access to the critical +section within the for loop, locking the mutex on creation and freeing +the mutex as control moves out of this block. +

    + +

    Several exception classes are used to keep track of +concurrence-related errors. These classes +are: __concurrence_lock_error, __concurrence_unlock_error, __concurrence_wait_error, +and __concurrence_broadcast_error. +

    + + + +

    + Details on builtin atomic support and library fallbacks +

    + +

    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, +using them directly is problematic, and can result in undefined +function calls. (An example of an undefined symbol from the use +of __sync_fetch_and_add on an unsupported host is a +missing reference to __sync_fetch_and_add_4.) +

    + +

    In addition, on some hosts the compiler intrinsics are enabled +conditionally, via the -march command line flag. This makes +usage vary depending on the target hardware and the flags used during +compile. +

    + +

    If builtins are possible, _GLIBCXX_ATOMIC_BUILTINS +will be defined. +

    + + +

    For the following hosts, intrinsics are enabled by default. +

    + +
      +
    • alpha
    • +
    • ia64
    • +
    • powerpc
    • +
    • s390
    • +
    + +

    For others, some form of -march may work. On +non-ancient x86 hardware, -march=native usually does the +trick.

    + +

    For hosts without compiler intrinsics, but with capable +hardware, hand-crafted assembly is selected. This is the case for the following hosts: +

    + +
      +
    • cris
    • +
    • hppa
    • +
    • i386
    • +
    • i486
    • +
    • m48k
    • +
    • mips
    • +
    • sparc
    • +
    + +

    And for the rest, a simulated atomic lock via pthreads. +

    + +

    Detailed information about compiler intrinsics for atomic operations can be found in the GCC documentation. +

    + +

    More details on the library fallbacks from the porting section. +

    + + + + + + diff --git a/libstdc++-v3/docs/html/ext/howto.html b/libstdc++-v3/docs/html/ext/howto.html index 3171355..2e88c66 100644 --- a/libstdc++-v3/docs/html/ext/howto.html +++ b/libstdc++-v3/docs/html/ext/howto.html @@ -74,18 +74,13 @@ are deprecated but available as backwards-compatible extensions, as discussed further below. <rope> is the SGI specialization for large strings ("rope," - "large strings," get it? love those SGI folks). + "large strings," get it? Love that geeky humor.) <slist> is a singly-linked list, for when the doubly-linked list<> is too much space overhead, and <rb_tree> exposes the red-black tree classes used in the implementation of the standard maps and sets.

    -

    Okay, about those hashing classes... these classes have been - deprecated by the unordered_set, unordered_multiset, unordered_map, - unordered_multimap containers in TR1 and the upcoming C++0x, and - may be removed in future releases. -

    Each of the associative containers map, multimap, set, and multiset have a counterpart which uses a hashing @@ -111,11 +106,13 @@ components, and if you aren't scared about the possibility of pathological cases, you'll probably get better performance from hash_map. -

    (Side note: for those of you wondering, "Why wasn't a hash - table included in the Standard in the first #!$@ place?" - I'll give a quick answer: it was proposed, but too late and in too - unorganized a fashion.) + +

    Okay, about the SGI hashing classes... these classes have been + deprecated by the unordered_set, unordered_multiset, unordered_map, + unordered_multimap containers in TR1 and the upcoming C++0x, and + may be removed in future releases.

    +

    Return to top of page or to the FAQ.

    diff --git a/libstdc++-v3/docs/html/ext/sgiexts.html b/libstdc++-v3/docs/html/ext/sgiexts.html index 7f9b8c0..64b8e31 100644 --- a/libstdc++-v3/docs/html/ext/sgiexts.html +++ b/libstdc++-v3/docs/html/ext/sgiexts.html @@ -9,7 +9,7 @@ - SGI extensions to the library in libstdc++ + HP/SGI STL extensions @@ -19,29 +19,29 @@ -

    SGI extensions to the library in -libstdc++

    +

    HP/SGI STL extensions

    -

    This page describes the extensions that SGI made to their version of the - STL subset of the Standard C++ Library. For a time we - tracked and imported changes and updates - from most of the SGI STL, up through their (apparently) final release. - Their extensions were mostly preserved. +

    This page describes the extensions that SGI made to the STL subset + of the Standard C++ Library, which also includes work from the + originating HP codebase. This work is the basis for much of + libstdc++, and where possible these extensions have been + preserved.

    -

    They are listed according to the chapters of the library that they - extend (see the chapter-specific notes - for a description). Not every chapter may have extensions, and the - extensions may come and go. Also, this page is incomplete because the - author is pressed for time. Check back often; the latest change was on - $Date: 2003/04/16 17:02:47 $ (UTC). +

    What follows is a listing of these extensions, according to the + chapters of the library that they extend + (see the chapter-specific + notes for a description). Not every chapter has extensions, + and existing extensions may be removed (or moved) as their + functionality is standardized.

    -

    Descriptions range from the scanty to the verbose. You should also check - the generated documentation for notes - and comments, especially for entries marked with '*'. For more complete - doumentation, see the SGI website. For really complete - documentation, buy a copy of Matt Austern's book. *grin* +

    Descriptions range from the scanty to the verbose. Also check + the generated documentation + for notes and comments, especially for entries marked with '*'. + For more complete doumentation, see the SGI website. + For really complete documentation, consider perusing a + copy of Matt Austern's book "Generic Programming and the STL."

    Back to the libstdc++ extensions. diff --git a/libstdc++-v3/docs/html/faq/index.html b/libstdc++-v3/docs/html/faq/index.html index e353a1f..ff6cd65 100644 --- a/libstdc++-v3/docs/html/faq/index.html +++ b/libstdc++-v3/docs/html/faq/index.html @@ -1052,14 +1052,26 @@ http://clisp.cons.org/~haible/gccinclude-glibc-2.2-compat.diff


    5.6 Is libstdc++ thread-safe?

    -

    libstdc++ strives to be thread-safe when all of the following +

    The library strives to be thread-safe when all of the following conditions are met:

    • The system's libc is itself thread-safe,
    • -
    • gcc -v reports a thread model other than 'single',
    • -
    • [pre-3.3 only] a non-generic implementation of atomicity.h - exists for the architecture in question.
    • +
    • 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 diff --git a/libstdc++-v3/include/precompiled/stdc++.h b/libstdc++-v3/include/precompiled/stdc++.h index df9c217..7e7c268 100644 --- a/libstdc++-v3/include/precompiled/stdc++.h +++ b/libstdc++-v3/include/precompiled/stdc++.h @@ -1,6 +1,6 @@ // C++ includes used for precompiling -*- C++ -*- -// Copyright (C) 2003 Free Software Foundation, Inc. +// Copyright (C) 2003, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -51,6 +51,17 @@ #include #include +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#include +#include +#include +#include +#include +#include +#include +#endif + // C++ #include #include @@ -84,3 +95,14 @@ #include #include #include + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#include +#include +#include +#include +#include +#include +#include +#endif diff --git a/libstdc++-v3/testsuite/17_intro/headers/c++200x/all.cc b/libstdc++-v3/testsuite/17_intro/headers/c++200x/all.cc index 753f08e..f1ed7cf 100644 --- a/libstdc++-v3/testsuite/17_intro/headers/c++200x/all.cc +++ b/libstdc++-v3/testsuite/17_intro/headers/c++200x/all.cc @@ -121,6 +121,7 @@ #include #include #include +#include #include #include #include -- 2.7.4