X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;ds=inline;f=libstdc%2B%2B-v3%2Fdoc%2Fhtml%2Fmanual%2Fbackwards.html;h=8656c934d1f94d632584b242bec90a7fdc9f0f4d;hb=3ab1c2c296849ac32478360533acc0577471305d;hp=4e7f6e33c98d441895caefef71ebea2e1726af65;hpb=6abf9d66d70423209affe73ff738fc1e243edc31;p=pf3gnuchains%2Fgcc-fork.git diff --git a/libstdc++-v3/doc/html/manual/backwards.html b/libstdc++-v3/doc/html/manual/backwards.html index 4e7f6e33c98..8656c934d1f 100644 --- a/libstdc++-v3/doc/html/manual/backwards.html +++ b/libstdc++-v3/doc/html/manual/backwards.html @@ -1,6 +1,9 @@ -Backwards Compatibility

Backwards Compatibility

First

The first generation GNU C++ library was called libg++. It was a +Backwards Compatibility

Backwards Compatibility

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. @@ -13,9 +16,9 @@ now and are well-supported, whereas genclass (mostly) predates them.) 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.

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

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

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 @@ -29,26 +32,26 @@ archived. For the desperate, the GCC extensions page describes where to find the last libg++ source. The code is considered replaced and rewritten. -

Second

+

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.

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

Portability notes and known implementation limitations are as follows. -

Namespace std:: not supported

+

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 @@ -59,7 +62,7 @@ considered replaced and rewritten. 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.

@@ -71,7 +74,7 @@ considered replaced and rewritten.
   

Another pre-processor based approach is to define a macro NAMESPACE_STD, which is defined to either - “ ” or “std” based on a compile-type + “ ” 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 @@ -96,8 +99,8 @@ AC_DEFUN([AC_CXX_NAMESPACE_STD], [ ac_cv_cxx_have_std_namespace, [AC_LANG_SAVE AC_LANG_CPLUSPLUS - AC_TRY_COMPILE([#include <iostream> - std::istream& is = std::cin;],, + AC_TRY_COMPILE([#include <iostream> + std::istream& is = std::cin;],, ac_cv_cxx_have_std_namespace=yes, ac_cv_cxx_have_std_namespace=no) AC_LANG_RESTORE ]) @@ -105,40 +108,40 @@ AC_DEFUN([AC_CXX_NAMESPACE_STD], [ AC_DEFINE(HAVE_NAMESPACE_STD,,[Define if g++ supports namespace std. ]) fi ]) -

Illegal iterator usage

+

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 -

+ 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'); } 
+  

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

Results in something like this: -

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

+

+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. 
+// This keeps isalnum, et al from being propagated as macros.
 #if __linux__
 # define __NO_CTYPE 1
 #endif
@@ -151,7 +154,7 @@ std:: (__ctype_b[(int) ( ( 'X' ) )] & (unsigned short int) _ISspace ) ;
   (ctype.h) and the
   definitions in namespace std::
   (<cctype>).
-

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

+

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

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

 AC_MSG_CHECKING(for container::at)
@@ -160,7 +163,7 @@ AC_TRY_COMPILE(
 #include <vector>
 #include <deque>
 #include <string>
-	
+
 using namespace std;
 ],
 [
@@ -168,7 +171,7 @@ deque<int> test_deque(3);
 test_deque.at(2);
 vector<int> test_vector(2);
 test_vector.at(1);
-string test_string(“test_string”);
+string test_string(“test_string”);
 test_string.at(3);
 ],
 [AC_MSG_RESULT(yes)
@@ -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. -

No std::char_traits<char>::eof

+

No std::char_traits<char>::eof

Use some kind of autoconf test, plus this:

 #ifdef HAVE_CHAR_TRAITS
@@ -185,45 +188,45 @@ AC_DEFINE(HAVE_CONTAINER_AT)],
 #else
 #define CPP_EOF EOF
 #endif
-

No string::clear

+

No string::clear

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

-void 
+void
 clear() { _M_mutate(0, this->size(), 0); }
 
-basic_string& 
+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()); 
+			  _M_data(), _M_data());
 }
 

Unfortunately, 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

+

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 -

    • + terminating the string or freeing its memory +

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

    You can then use output-stringstreams like this:

    @@ -239,7 +242,7 @@ erase(size_type __pos = 0, size_type __n = npos)
       std::ostrstream oss;
     #endif
     
    -oss << “Name=” << m_name << “, number=” << m_number << std::endl;
    +oss << “Name=” << m_name << “, number=” << m_number << std::endl;
     ...
     #ifndef HAVE_SSTREAM
       oss << std::ends; // terminate the char*-string
    @@ -265,7 +268,7 @@ std::istrstream iss(input.c_str());
     #endif
     
     int i;
    -iss >> i; 
    +iss >> i;
     

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

     std::istringstream iss(numerator);
    @@ -292,18 +295,18 @@ if (iss.fail())
     throw runtime_error(..)
     any = temp;
     }
    -

    - Another example of using stringstreams is in this howto. +

    + 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

+particular “info iostream”. +

Little or no wide character support

Classes wstring and char_traits<wchar_t> are not supported. -

No templatized iostreams

+

No templatized iostreams

Classes wfilebuf and wstringstream are not supported. -

Thread safety issues

+

Thread safety issues

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 @@ -339,29 +342,29 @@ particular “info iostream”. first relevant message in the thread; from there you can use "Thread Next" to move down the thread. This farm is in latest-to-oldest order. -

  • +

    • Our threading expert Loren gives a breakdown of the six situations involving threads for the 3.0 release series. -

    • +

    • - This message inspired a recent updating of issues with - threading and the SGI STL library. It also contains some - example POSIX-multithreaded STL code. -

    + This message inspired a recent updating of issues with + threading and the SGI STL library. It also contains some + example POSIX-multithreaded STL code. +

(A large selection of links to older messages has been removed; many of the messages from 1999 were lost in a disk crash, and the few people with access to the backup tapes have been too swamped with work to restore them. Many of the points have been superseded anyhow.) -

Third

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

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. + (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 + 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. @@ -382,7 +385,7 @@ AC_DEFUN([AC_HEADER_PRE_STDCXX], [ [AC_LANG_SAVE AC_LANG_CPLUSPLUS ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -Wno-deprecated" + CXXFLAGS="$CXXFLAGS -Wno-deprecated" # Omit defalloc.h, as compilation with newer compilers is problematic. AC_TRY_COMPILE([ @@ -433,11 +436,11 @@ 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. -

Extension headers hash_map, hash_set moved to ext or backwards

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 - containers in the SGI STL. +

Extension headers hash_map, hash_set moved to ext or backwards

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 + containers in the SGI STL.

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 @@ -445,29 +448,29 @@ in namespace __gnu_cxx. Later versions move deprecate these files, and suggest using TR1's unordered_map and unordered_set instead.

The extensions are no longer in the global or std - namespaces, instead they are declared in the __gnu_cxx - namespace. For maximum portability, consider defining a namespace - alias to use to talk about extensions, e.g.: + namespaces, instead they are declared in the __gnu_cxx + namespace. For maximum portability, consider defining a namespace + alias to use to talk about extensions, e.g.:

       #ifdef __GNUC__
       #if __GNUC__ < 3
-        #include <hash_map.h>
-        namespace extension { using ::hash_map; }; // inherit globals
+	#include <hash_map.h>
+	namespace extension { using ::hash_map; }; // inherit globals
       #else
-        #include <backward/hash_map>
-        #if __GNUC__ == 3 && __GNUC_MINOR__ == 0
-          namespace extension = std;               // GCC 3.0
-        #else
-          namespace extension = ::__gnu_cxx;       // GCC 3.1 and later
-        #endif
+	#include <backward/hash_map>
+	#if __GNUC__ == 3 && __GNUC_MINOR__ == 0
+	  namespace extension = std;               // GCC 3.0
+	#else
+	  namespace extension = ::__gnu_cxx;       // GCC 3.1 and later
+	#endif
       #endif
       #else      // ...  there are other compilers, right?
-        namespace extension = std;
+	namespace extension = std;
       #endif
 
-      extension::hash_map<int,int> my_map; 
+      extension::hash_map<int,int> my_map;
       

This is a bit cleaner than defining typedefs for all the - instantiations you might need. + instantiations you might need.

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

 # AC_HEADER_EXT_HASH_MAP
@@ -477,7 +480,7 @@ AC_DEFUN([AC_HEADER_EXT_HASH_MAP], [
   [AC_LANG_SAVE
   AC_LANG_CPLUSPLUS
   ac_save_CXXFLAGS="$CXXFLAGS"
-  CXXFLAGS="$CXXFLAGS -Werror"	
+  CXXFLAGS="$CXXFLAGS -Werror"
   AC_TRY_COMPILE([#include <ext/hash_map>], [using __gnu_cxx::hash_map;],
   ac_cv_cxx_ext_hash_map=yes, ac_cv_cxx_ext_hash_map=no)
   CXXFLAGS="$ac_save_CXXFLAGS"
@@ -495,7 +498,7 @@ AC_DEFUN([AC_HEADER_EXT_HASH_SET], [
   [AC_LANG_SAVE
   AC_LANG_CPLUSPLUS
   ac_save_CXXFLAGS="$CXXFLAGS"
-  CXXFLAGS="$CXXFLAGS -Werror"	
+  CXXFLAGS="$CXXFLAGS -Werror"
   AC_TRY_COMPILE([#include <ext/hash_set>], [using __gnu_cxx::hash_set;],
   ac_cv_cxx_ext_hash_set=yes, ac_cv_cxx_ext_hash_set=no)
   CXXFLAGS="$ac_save_CXXFLAGS"
@@ -505,18 +508,18 @@ AC_DEFUN([AC_HEADER_EXT_HASH_SET], [
     AC_DEFINE(HAVE_EXT_HASH_SET,,[Define if ext/hash_set is present. ])
   fi
 ])
-

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

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

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 @@ -528,18 +531,18 @@ No stream::attach(int fd) std::streambuf (or std::basic_streambuf<..>) which opens a file given a descriptor, and then pass an instance of this to the - stream-constructor. + stream-constructor.

An extension is available that implements this. ext/stdio_filebuf.h contains a derived class called - __gnu_cxx::stdio_filebuf. + __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 + fdstream example by Nicolai Josuttis. -

+

Support for C++98 dialect.

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
 ])
-

+

Support for C++TR1 dialect.

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
 ])
-

+

Support for C++0x dialect.

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

@@ -696,7 +699,7 @@ AC_DEFUN([AC_COMPILE_STDCXX_0X], [
   AC_LANG_CPLUSPLUS
   AC_TRY_COMPILE([
   template <typename T>
-    struct check 
+    struct check
     {
       static_assert(sizeof(int) <= sizeof(T), "not big enough");
     };
@@ -718,10 +721,10 @@ AC_DEFUN([AC_COMPILE_STDCXX_0X], [
   [AC_LANG_SAVE
   AC_LANG_CPLUSPLUS
   ac_save_CXXFLAGS="$CXXFLAGS"
-  CXXFLAGS="$CXXFLAGS -std=c++0x"	
+  CXXFLAGS="$CXXFLAGS -std=c++0x"
   AC_TRY_COMPILE([
   template <typename T>
-    struct check 
+    struct check
     {
       static_assert(sizeof(int) <= sizeof(T), "not big enough");
     };
@@ -744,10 +747,10 @@ AC_DEFUN([AC_COMPILE_STDCXX_0X], [
   [AC_LANG_SAVE
   AC_LANG_CPLUSPLUS
   ac_save_CXXFLAGS="$CXXFLAGS"
-  CXXFLAGS="$CXXFLAGS -std=gnu++0x"	
+  CXXFLAGS="$CXXFLAGS -std=gnu++0x"
   AC_TRY_COMPILE([
   template <typename T>
-    struct check 
+    struct check
     {
       static_assert(sizeof(int) <= sizeof(T), "not big enough");
     };
@@ -765,8 +768,8 @@ AC_DEFUN([AC_COMPILE_STDCXX_0X], [
   AC_LANG_RESTORE
   ])
 
-  if test "$ac_cv_cxx_compile_cxx0x_native" = yes || 
-     test "$ac_cv_cxx_compile_cxx0x_cxx" = yes || 
+  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
@@ -781,7 +784,7 @@ AC_DEFUN([AC_HEADER_STDCXX_0X], [
   AC_LANG_SAVE
   AC_LANG_CPLUSPLUS
   ac_save_CXXFLAGS="$CXXFLAGS"
-  CXXFLAGS="$CXXFLAGS -std=gnu++0x"	
+  CXXFLAGS="$CXXFLAGS -std=gnu++0x"
 
   AC_TRY_COMPILE([
     #include <cassert>
@@ -867,7 +870,7 @@ AC_DEFUN([AC_HEADER_UNORDERED_MAP], [
   AC_LANG_SAVE
   AC_LANG_CPLUSPLUS
   ac_save_CXXFLAGS="$CXXFLAGS"
-  CXXFLAGS="$CXXFLAGS -std=gnu++0x"	
+  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"
@@ -886,7 +889,7 @@ AC_DEFUN([AC_HEADER_UNORDERED_SET], [
   AC_LANG_SAVE
   AC_LANG_CPLUSPLUS
   ac_save_CXXFLAGS="$CXXFLAGS"
-  CXXFLAGS="$CXXFLAGS -std=gnu++0x"	
+  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"
@@ -896,31 +899,31 @@ AC_DEFUN([AC_HEADER_UNORDERED_SET], [
     AC_DEFINE(HAVE_UNORDERED_SET,,[Define if unordered_set is present. ])
   fi
 ])
-

+

Container::iterator_type is not necessarily Container::value_type*

This is a change in behavior from the previous version. Now, most iterator_type typedefs in container classes are POD objects, not value_type pointers. -

Bibliography

[ - kegel41 - ] - Migrating to GCC 4.1 - . Dan Kegel. +

Bibliography

- - .

[ - kegel41 - ] - Building the Whole Debian Archive with GCC 4.1: A Summary - . Martin Michlmayr. + + Migrating to GCC 4.1 + + + . Dan Kegel.

[ - lbl32 - ] - Migration guide for GCC-3.2 - . + . Martin Michlmayr.

+ .