1 <section xmlns="http://docbook.org/ns/docbook" version="5.0"
2 xml:id="manual.appendix.porting.backwards" xreflabel="backwards">
3 <?dbhtml filename="backwards.html"?>
5 <info><title>Backwards Compatibility</title>
7 <keyword>ISO C++</keyword>
8 <keyword>backwards</keyword>
14 <section xml:id="backwards.first"><info><title>First</title></info>
17 <para>The first generation GNU C++ library was called libg++. It was a
18 separate GNU project, although reliably paired with GCC. Rumors imply
19 that it had a working relationship with at least two kinds of
23 <para>Some background: libg++ was designed and created when there was no
24 ISO standard to provide guidance. Classes like linked lists are now
25 provided for by <classname>list<T></classname> and do not need to be
26 created by <function>genclass</function>. (For that matter, templates exist
27 now and are well-supported, whereas genclass (mostly) predates them.)
30 <para>There are other classes in libg++ that are not specified in the
31 ISO Standard (e.g., statistical analysis). While there are a lot of
32 really useful things that are used by a lot of people, the Standards
33 Committee couldn't include everything, and so a lot of those
34 <quote>obvious</quote> classes didn't get included.
37 <para>Known Issues include many of the limitations of its immediate ancestor.</para>
39 <para>Portability notes and known implementation limitations are as follows.</para>
41 <section xml:id="backwards.first.ios_base"><info><title>No <code>ios_base</code></title></info>
44 <para> At least some older implementations don't have <code>std::ios_base</code>, so you should use <code>std::ios::badbit</code>, <code>std::ios::failbit</code> and <code>std::ios::eofbit</code> and <code>std::ios::goodbit</code>.
48 <section xml:id="backwards.first.cout_cin"><info><title>No <code>cout</code> in <filename class="headerfile"><ostream.h></filename>, no <code>cin</code> in <filename class="headerfile"><istream.h></filename></title></info>
52 In earlier versions of the standard,
53 <filename class="headerfile"><fstream.h></filename>,
54 <filename class="headerfile"><ostream.h></filename>
55 and <filename class="headerfile"><istream.h></filename>
57 <code>cout</code>, <code>cin</code> and so on. ISO C++ specifies that one needs to include
58 <filename class="headerfile"><iostream></filename>
59 explicitly to get the required definitions.
61 <para> Some include adjustment may be required.</para>
63 <para>This project is no longer maintained or supported, and the sources
64 archived. For the desperate,
65 the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/extensions.html">GCC extensions
66 page</link> describes where to find the last libg++ source. The code is
67 considered replaced and rewritten.
72 <section xml:id="backwards.second"><info><title>Second</title></info>
76 The second generation GNU C++ library was called libstdc++, or
77 libstdc++-v2. It spans the time between libg++ and pre-ISO C++
78 standardization and is usually associated with the following GCC
79 releases: egcs 1.x, gcc 2.95, and gcc 2.96.
83 The STL portions of this library are based on SGI/HP STL release 3.11.
87 This project is no longer maintained or supported, and the sources
88 archived. The code is considered replaced and rewritten.
92 Portability notes and known implementation limitations are as follows.
95 <section xml:id="backwards.second.std"><info><title>Namespace <code>std::</code> not supported</title></info>
99 Some care is required to support C++ compiler and or library
100 implementation that do not have the standard library in
101 <code>namespace std</code>.
105 The following sections list some possible solutions to support compilers
106 that cannot ignore <code>std::</code>-qualified names.
110 First, see if the compiler has a flag for this. Namespace
111 back-portability-issues are generally not a problem for g++
112 compilers that do not have libstdc++ in <code>std::</code>, as the
113 compilers use <option>-fno-honor-std</option> (ignore
114 <code>std::</code>, <code>:: = std::</code>) by default. That is,
115 the responsibility for enabling or disabling <code>std::</code> is
116 on the user; the maintainer does not have to care about it. This
117 probably applies to some other compilers as well.
121 Second, experiment with a variety of pre-processor tricks.
125 By defining <code>std</code> as a macro, fully-qualified namespace
126 calls become global. Volia.
130 #ifdef WICKEDLY_OLD_COMPILER
136 Thanks to Juergen Heinzl who posted this solution on gnu.gcc.help.
140 Another pre-processor based approach is to define a macro
141 <code>NAMESPACE_STD</code>, which is defined to either
142 <quote> </quote> or <quote>std</quote> based on a compile-type
143 test. On GNU systems, this can be done with autotools by means of
144 an autoconf test (see below) for <code>HAVE_NAMESPACE_STD</code>,
145 then using that to set a value for the <code>NAMESPACE_STD</code>
146 macro. At that point, one is able to use
147 <code>NAMESPACE_STD::string</code>, which will evaluate to
148 <code>std::string</code> or <code>::string</code> (i.e., in the
149 global namespace on systems that do not put <code>string</code> in
154 dnl @synopsis AC_CXX_NAMESPACE_STD
156 dnl If the compiler supports namespace std, define
157 dnl HAVE_NAMESPACE_STD.
160 dnl @author Todd Veldhuizen
161 dnl @author Luc Maisonobe <luc@spaceroots.org>
162 dnl @version 2004-02-04
163 dnl @license AllPermissive
164 AC_DEFUN([AC_CXX_NAMESPACE_STD], [
165 AC_CACHE_CHECK(if g++ supports namespace std,
166 ac_cv_cxx_have_std_namespace,
169 AC_TRY_COMPILE([#include <iostream>
170 std::istream& is = std::cin;],,
171 ac_cv_cxx_have_std_namespace=yes, ac_cv_cxx_have_std_namespace=no)
174 if test "$ac_cv_cxx_have_std_namespace" = yes; then
175 AC_DEFINE(HAVE_NAMESPACE_STD,,[Define if g++ supports namespace std. ])
181 <section xml:id="backwards.second.iterators"><info><title>Illegal iterator usage</title></info>
184 The following illustrate implementation-allowed illegal iterator
185 use, and then correct use.
191 you cannot do <code>ostream::operator<<(iterator)</code>
192 to print the address of the iterator => use
193 <code>operator<< &*iterator</code> instead
198 you cannot clear an iterator's reference (<code>iterator =
199 0</code>) => use <code>iterator = iterator_type();</code>
204 <code>if (iterator)</code> won't work any more => use
205 <code>if (iterator != iterator_type())</code>
211 <section xml:id="backwards.second.isspace"><info><title><code>isspace</code> from <filename class="headerfile"><cctype></filename> is a macro
216 Glibc 2.0.x and 2.1.x define <filename class="headerfile"><ctype.h></filename> functionality as macros
217 (isspace, isalpha etc.).
221 This implementations of libstdc++, however, keep these functions
222 as macros, and so it is not back-portable to use fully qualified
227 #include <cctype>
228 int main() { std::isspace('X'); }
232 Results in something like this:
236 std:: (__ctype_b[(int) ( ( 'X' ) )] & (unsigned short int) _ISspace ) ;
240 A solution is to modify a header-file so that the compiler tells
241 <filename class="headerfile"><ctype.h></filename> to define functions
246 // This keeps isalnum, et al from being propagated as macros.
248 # define __NO_CTYPE 1
253 Then, include <filename class="headerfile"><ctype.h></filename>
257 Another problem arises if you put a <code>using namespace
258 std;</code> declaration at the top, and include
259 <filename class="headerfile"><ctype.h></filename>. This will
260 result in ambiguities between the definitions in the global namespace
261 (<filename class="headerfile"><ctype.h></filename>) and the
262 definitions in namespace <code>std::</code>
263 (<code><cctype></code>).
267 <section xml:id="backwards.second.at"><info><title>No <code>vector::at</code>, <code>deque::at</code>, <code>string::at</code></title></info>
271 One solution is to add an autoconf-test for this:
275 AC_MSG_CHECKING(for container::at)
278 #include <vector>
279 #include <deque>
280 #include <string>
285 deque<int> test_deque(3);
287 vector<int> test_vector(2);
289 string test_string(<quote>test_string</quote>);
293 AC_DEFINE(HAVE_CONTAINER_AT)],
298 If you are using other (non-GNU) compilers it might be a good idea
299 to check for <code>string::at</code> separately.
304 <section xml:id="backwards.second.eof"><info><title>No <code>std::char_traits<char>::eof</code></title></info>
308 Use some kind of autoconf test, plus this:
312 #ifdef HAVE_CHAR_TRAITS
313 #define CPP_EOF std::char_traits<char>::eof()
321 <section xml:id="backwards.second.stringclear"><info><title>No <code>string::clear</code></title></info>
325 There are two functions for deleting the contents of a string:
326 <code>clear</code> and <code>erase</code> (the latter returns the
332 clear() { _M_mutate(0, this->size(), 0); }
337 erase(size_type __pos = 0, size_type __n = npos)
339 return this->replace(_M_check(__pos), _M_fold(__pos, __n),
340 _M_data(), _M_data());
345 Unfortunately, <code>clear</code> is not implemented in this
346 version, so you should use <code>erase</code> (which is probably
347 faster than <code>operator=(charT*)</code>).
351 <section xml:id="backwards.second.ostreamform_istreamscan"><info><title>
352 Removal of <code>ostream::form</code> and <code>istream::scan</code>
358 These are no longer supported. Please use stringstreams instead.
362 <section xml:id="backwards.second.stringstreams"><info><title>No <code>basic_stringbuf</code>, <code>basic_stringstream</code></title></info>
366 Although the ISO standard <code>i/ostringstream</code>-classes are
367 provided, (<filename class="headerfile"><sstream></filename>), for
368 compatibility with older implementations the pre-ISO
369 <code>i/ostrstream</code> (<filename class="headerfile"><strstream></filename>) interface is also provided,
376 <code>strstream</code> is considered to be deprecated
381 <code>strstream</code> is limited to <code>char</code>
386 with <code>ostringstream</code> you don't have to take care of
387 terminating the string or freeing its memory
392 <code>istringstream</code> can be re-filled (clear();
399 You can then use output-stringstreams like this:
404 # include <sstream>
406 # include <strstream>
410 std::ostringstream oss;
415 oss << <quote>Name=</quote> << m_name << <quote>, number=</quote> << m_number << std::endl;
418 oss << std::ends; // terminate the char*-string
421 // str() returns char* for ostrstream and a string for ostringstream
422 // this also causes ostrstream to think that the buffer's memory
424 m_label.set_text(oss.str());
426 // let the ostrstream take care of freeing the memory
432 Input-stringstreams can be used similarly:
439 std::istringstream iss(input);
441 std::istrstream iss(input.c_str());
448 <para> One (the only?) restriction is that an istrstream cannot be re-filled:
452 std::istringstream iss(numerator);
454 // this is not possible with istrstream
456 iss.str(denominator);
461 If you don't care about speed, you can put these conversions in
465 template <class X>
466 void fromString(const string& input, X& any)
469 std::istringstream iss(input);
471 std::istrstream iss(input.c_str());
476 throw runtime_error(..)
482 Another example of using stringstreams is in <link linkend="strings.string.shrink">this howto</link>.
485 <para> There is additional information in the libstdc++-v2 info files, in
486 particular <quote>info iostream</quote>.
490 <section xml:id="backwards.second.wchar"><info><title>Little or no wide character support</title></info>
493 Classes <classname>wstring</classname> and
494 <classname>char_traits<wchar_t></classname> are
499 <section xml:id="backwards.second.iostream_templates"><info><title>No templatized iostreams</title></info>
502 Classes <classname>wfilebuf</classname> and
503 <classname>wstringstream</classname> are not supported.
507 <section xml:id="backwards.second.thread_safety"><info><title>Thread safety issues</title></info>
511 Earlier GCC releases had a somewhat different approach to
512 threading configuration and proper compilation. Before GCC 3.0,
513 configuration of the threading model was dictated by compiler
514 command-line options and macros (both of which were somewhat
515 thread-implementation and port-specific). There were no
516 guarantees related to being able to link code compiled with one
517 set of options and macro setting with another set.
521 For GCC 3.0, configuration of the threading model used with
522 libraries and user-code is performed when GCC is configured and
523 built using the --enable-threads and --disable-threads options.
524 The ABI is stable for symbol name-mangling and limited functional
525 compatibility exists between code compiled under different
530 The libstdc++ library has been designed so that it can be used in
531 multithreaded applications (with libstdc++-v2 this was only true
532 of the STL parts.) The first problem is finding a
533 <emphasis>fast</emphasis> method of implementation portable to
534 all platforms. Due to historical reasons, some of the library is
535 written against per-CPU-architecture spinlocks and other parts
536 against the gthr.h abstraction layer which is provided by gcc. A
537 minor problem that pops up every so often is different
538 interpretations of what "thread-safe" means for a
539 library (not a general program). We currently use the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.sgi.com/tech/stl/thread_safety.html">same
540 definition that SGI</link> uses for their STL subset. However,
541 the exception for read-only containers only applies to the STL
542 components. This definition is widely-used and something similar
543 will be used in the next version of the C++ standard library.
547 Here is a small link farm to threads (no pun) in the mail
548 archives that discuss the threading problem. Each link is to the
549 first relevant message in the thread; from there you can use
550 "Thread Next" to move down the thread. This farm is in
551 latest-to-oldest order.
557 Our threading expert Loren gives a breakdown of <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/libstdc++/2001-10/msg00024.html">the
558 six situations involving threads</link> for the 3.0
564 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/libstdc++/2001-05/msg00384.html">
565 This message</link> inspired a recent updating of issues with
566 threading and the SGI STL library. It also contains some
567 example POSIX-multithreaded STL code.
573 (A large selection of links to older messages has been removed;
574 many of the messages from 1999 were lost in a disk crash, and the
575 few people with access to the backup tapes have been too swamped
576 with work to restore them. Many of the points have been
583 <section xml:id="backwards.third"><info><title>Third</title></info>
586 <para> The third generation GNU C++ library is called libstdc++, or
590 <para>The subset commonly known as the Standard Template Library
591 (chapters 23 through 25, mostly) is adapted from the final release
592 of the SGI STL (version 3.3), with extensive changes.
595 <para>A more formal description of the V3 goals can be found in the
596 official <link linkend="contrib.design_notes">design document</link>.
599 <para>Portability notes and known implementation limitations are as follows.</para>
601 <section xml:id="backwards.third.headers"><info><title>Pre-ISO headers moved to backwards or removed</title></info>
604 <para> The pre-ISO C++ headers
605 (<filename class="headerfile"><iostream.h></filename>,
606 <filename class="headerfile"><defalloc.h></filename> etc.) are
607 available, unlike previous libstdc++ versions, but inclusion
608 generates a warning that you are using deprecated headers.
611 <para>This compatibility layer is constructed by including the
612 standard C++ headers, and injecting any items in
613 <code>std::</code> into the global namespace.
615 <para>For those of you new to ISO C++ (welcome, time travelers!), no,
616 that isn't a typo. Yes, the headers really have new names.
617 Marshall Cline's C++ FAQ Lite has a good explanation in <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4">item
621 <para> Some include adjustment may be required. What follows is an
622 autoconf test that defines <code>PRE_STDCXX_HEADERS</code> when they
626 # AC_HEADER_PRE_STDCXX
627 AC_DEFUN([AC_HEADER_PRE_STDCXX], [
628 AC_CACHE_CHECK(for pre-ISO C++ include files,
629 ac_cv_cxx_pre_stdcxx,
632 ac_save_CXXFLAGS="$CXXFLAGS"
633 CXXFLAGS="$CXXFLAGS -Wno-deprecated"
635 # Omit defalloc.h, as compilation with newer compilers is problematic.
637 #include <new.h>
638 #include <iterator.h>
639 #include <alloc.h>
640 #include <set.h>
641 #include <hashtable.h>
642 #include <hash_set.h>
643 #include <fstream.h>
644 #include <tempbuf.h>
645 #include <istream.h>
646 #include <bvector.h>
647 #include <stack.h>
648 #include <rope.h>
649 #include <complex.h>
650 #include <ostream.h>
651 #include <heap.h>
652 #include <iostream.h>
653 #include <function.h>
654 #include <multimap.h>
655 #include <pair.h>
656 #include <stream.h>
657 #include <iomanip.h>
658 #include <slist.h>
659 #include <tree.h>
660 #include <vector.h>
661 #include <deque.h>
662 #include <multiset.h>
663 #include <list.h>
664 #include <map.h>
665 #include <algobase.h>
666 #include <hash_map.h>
667 #include <algo.h>
668 #include <queue.h>
669 #include <streambuf.h>
671 ac_cv_cxx_pre_stdcxx=yes, ac_cv_cxx_pre_stdcxx=no)
672 CXXFLAGS="$ac_save_CXXFLAGS"
675 if test "$ac_cv_cxx_pre_stdcxx" = yes; then
676 AC_DEFINE(PRE_STDCXX_HEADERS,,[Define if pre-ISO C++ header files are present. ])
681 <para>Porting between pre-ISO headers and ISO headers is simple: headers
682 like <filename class="headerfile"><vector.h></filename> can be replaced with <filename class="headerfile"><vector></filename> and a using
683 directive <code>using namespace std;</code> can be put at the global
684 scope. This should be enough to get this code compiling, assuming the
685 other usage is correct.
689 <section xml:id="backwards.third.hash"><info><title>Extension headers hash_map, hash_set moved to ext or backwards</title></info>
692 <para>At this time most of the features of the SGI STL extension have been
693 replaced by standardized libraries.
694 In particular, the <classname>unordered_map</classname> and
695 <classname>unordered_set</classname> containers of TR1 and C++ 2011
696 are suitable replacements for the non-standard
697 <classname>hash_map</classname> and <classname>hash_set</classname>
698 containers in the SGI STL.
700 <para> Header files <filename class="headerfile"><hash_map></filename> and <filename class="headerfile"><hash_set></filename> moved
701 to <filename class="headerfile"><ext/hash_map></filename> and <filename class="headerfile"><ext/hash_set></filename>,
702 respectively. At the same time, all types in these files are enclosed
703 in <code>namespace __gnu_cxx</code>. Later versions deprecate
704 these files, and suggest using TR1's <filename class="headerfile"><unordered_map></filename>
705 and <filename class="headerfile"><unordered_set></filename> instead.
708 <para>The extensions are no longer in the global or <code>std</code>
709 namespaces, instead they are declared in the <code>__gnu_cxx</code>
710 namespace. For maximum portability, consider defining a namespace
711 alias to use to talk about extensions, e.g.:
716 #include <hash_map.h>
717 namespace extension { using ::hash_map; }; // inherit globals
719 #include <backward/hash_map>
720 #if __GNUC__ == 3 && __GNUC_MINOR__ == 0
721 namespace extension = std; // GCC 3.0
723 namespace extension = ::__gnu_cxx; // GCC 3.1 and later
726 #else // ... there are other compilers, right?
727 namespace extension = std;
730 extension::hash_map<int,int> my_map;
732 <para>This is a bit cleaner than defining typedefs for all the
733 instantiations you might need.
737 <para>The following autoconf tests check for working HP/SGI hash containers.
741 # AC_HEADER_EXT_HASH_MAP
742 AC_DEFUN([AC_HEADER_EXT_HASH_MAP], [
743 AC_CACHE_CHECK(for ext/hash_map,
744 ac_cv_cxx_ext_hash_map,
747 ac_save_CXXFLAGS="$CXXFLAGS"
748 CXXFLAGS="$CXXFLAGS -Werror"
749 AC_TRY_COMPILE([#include <ext/hash_map>], [using __gnu_cxx::hash_map;],
750 ac_cv_cxx_ext_hash_map=yes, ac_cv_cxx_ext_hash_map=no)
751 CXXFLAGS="$ac_save_CXXFLAGS"
754 if test "$ac_cv_cxx_ext_hash_map" = yes; then
755 AC_DEFINE(HAVE_EXT_HASH_MAP,,[Define if ext/hash_map is present. ])
761 # AC_HEADER_EXT_HASH_SET
762 AC_DEFUN([AC_HEADER_EXT_HASH_SET], [
763 AC_CACHE_CHECK(for ext/hash_set,
764 ac_cv_cxx_ext_hash_set,
767 ac_save_CXXFLAGS="$CXXFLAGS"
768 CXXFLAGS="$CXXFLAGS -Werror"
769 AC_TRY_COMPILE([#include <ext/hash_set>], [using __gnu_cxx::hash_set;],
770 ac_cv_cxx_ext_hash_set=yes, ac_cv_cxx_ext_hash_set=no)
771 CXXFLAGS="$ac_save_CXXFLAGS"
774 if test "$ac_cv_cxx_ext_hash_set" = yes; then
775 AC_DEFINE(HAVE_EXT_HASH_SET,,[Define if ext/hash_set is present. ])
781 <section xml:id="backwards.third.nocreate_noreplace"><info><title>No <code>ios::nocreate/ios::noreplace</code>.
785 <para>Historically these flags were used with iostreams to control whether
786 new files are created or not when opening a file stream, similar to the
787 <code>O_CREAT</code> and <code>O_EXCL</code> flags for the
788 <function>open(2)</function> system call. Because iostream modes correspond
789 to <function>fopen(3)</function> modes these flags are not supported.
790 For input streams a new file will not be created anyway, so
791 <code>ios::nocreate</code> is not needed.
792 For output streams, a new file will be created if it does not exist, which is
793 consistent with the behaviour of <function>fopen</function>.
796 <para>When one of these flags is needed a possible alternative is to attempt
797 to open the file using <type>std::ifstream</type> first to determine whether
798 the file already exists or not. This may not be reliable however, because
799 whether the file exists or not could change between opening the
800 <type>std::istream</type> and re-opening with an output stream. If you need
801 to check for existence and open a file as a single operation then you will
802 need to use OS-specific facilities outside the C++ standard library, such
803 as <function>open(2)</function>.
807 <section xml:id="backwards.third.streamattach"><info><title>
808 No <code>stream::attach(int fd)</code>
813 Phil Edwards writes: It was considered and rejected for the ISO
814 standard. Not all environments use file descriptors. Of those
815 that do, not all of them use integers to represent them.
819 For a portable solution (among systems which use
820 file descriptors), you need to implement a subclass of
821 <code>std::streambuf</code> (or
822 <code>std::basic_streambuf<..></code>) which opens a file
823 given a descriptor, and then pass an instance of this to the
828 An extension is available that implements this.
829 <filename class="headerfile"><ext/stdio_filebuf.h></filename> contains a derived class called
830 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00074.html"><code>__gnu_cxx::stdio_filebuf</code></link>.
831 This class can be constructed from a C <code>FILE*</code> or a file
832 descriptor, and provides the <code>fd()</code> function.
836 For another example of this, refer to
837 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.josuttis.com/cppcode/fdstream.html">fdstream example</link>
842 <section xml:id="backwards.third.support_cxx98"><info><title>
843 Support for C++98 dialect.
847 <para>Check for complete library coverage of the C++1998/2003 standard.
851 # AC_HEADER_STDCXX_98
852 AC_DEFUN([AC_HEADER_STDCXX_98], [
853 AC_CACHE_CHECK(for ISO C++ 98 include files,
858 #include <cassert>
859 #include <cctype>
860 #include <cerrno>
861 #include <cfloat>
862 #include <ciso646>
863 #include <climits>
864 #include <clocale>
865 #include <cmath>
866 #include <csetjmp>
867 #include <csignal>
868 #include <cstdarg>
869 #include <cstddef>
870 #include <cstdio>
871 #include <cstdlib>
872 #include <cstring>
873 #include <ctime>
875 #include <algorithm>
876 #include <bitset>
877 #include <complex>
878 #include <deque>
879 #include <exception>
880 #include <fstream>
881 #include <functional>
882 #include <iomanip>
884 #include <iosfwd>
885 #include <iostream>
886 #include <istream>
887 #include <iterator>
888 #include <limits>
889 #include <list>
890 #include <locale>
892 #include <memory>
894 #include <numeric>
895 #include <ostream>
896 #include <queue>
898 #include <sstream>
899 #include <stack>
900 #include <stdexcept>
901 #include <streambuf>
902 #include <string>
903 #include <typeinfo>
904 #include <utility>
905 #include <valarray>
906 #include <vector>
908 ac_cv_cxx_stdcxx_98=yes, ac_cv_cxx_stdcxx_98=no)
911 if test "$ac_cv_cxx_stdcxx_98" = yes; then
912 AC_DEFINE(STDCXX_98_HEADERS,,[Define if ISO C++ 1998 header files are present. ])
918 <section xml:id="backwards.third.support_tr1"><info><title>
919 Support for C++TR1 dialect.
923 <para>Check for library coverage of the TR1 standard.
927 # AC_HEADER_STDCXX_TR1
928 AC_DEFUN([AC_HEADER_STDCXX_TR1], [
929 AC_CACHE_CHECK(for ISO C++ TR1 include files,
930 ac_cv_cxx_stdcxx_tr1,
934 #include <tr1/array>
935 #include <tr1/ccomplex>
936 #include <tr1/cctype>
937 #include <tr1/cfenv>
938 #include <tr1/cfloat>
939 #include <tr1/cinttypes>
940 #include <tr1/climits>
941 #include <tr1/cmath>
942 #include <tr1/complex>
943 #include <tr1/cstdarg>
944 #include <tr1/cstdbool>
945 #include <tr1/cstdint>
946 #include <tr1/cstdio>
947 #include <tr1/cstdlib>
948 #include <tr1/ctgmath>
949 #include <tr1/ctime>
950 #include <tr1/cwchar>
951 #include <tr1/cwctype>
952 #include <tr1/functional>
953 #include <tr1/memory>
954 #include <tr1/random>
955 #include <tr1/regex>
956 #include <tr1/tuple>
957 #include <tr1/type_traits>
958 #include <tr1/unordered_set>
959 #include <tr1/unordered_map>
960 #include <tr1/utility>
962 ac_cv_cxx_stdcxx_tr1=yes, ac_cv_cxx_stdcxx_tr1=no)
965 if test "$ac_cv_cxx_stdcxx_tr1" = yes; then
966 AC_DEFINE(STDCXX_TR1_HEADERS,,[Define if ISO C++ TR1 header files are present. ])
971 <para>An alternative is to check just for specific TR1 includes, such as <unordered_map> and <unordered_set>.
975 # AC_HEADER_TR1_UNORDERED_MAP
976 AC_DEFUN([AC_HEADER_TR1_UNORDERED_MAP], [
977 AC_CACHE_CHECK(for tr1/unordered_map,
978 ac_cv_cxx_tr1_unordered_map,
981 AC_TRY_COMPILE([#include <tr1/unordered_map>], [using std::tr1::unordered_map;],
982 ac_cv_cxx_tr1_unordered_map=yes, ac_cv_cxx_tr1_unordered_map=no)
985 if test "$ac_cv_cxx_tr1_unordered_map" = yes; then
986 AC_DEFINE(HAVE_TR1_UNORDERED_MAP,,[Define if tr1/unordered_map is present. ])
992 # AC_HEADER_TR1_UNORDERED_SET
993 AC_DEFUN([AC_HEADER_TR1_UNORDERED_SET], [
994 AC_CACHE_CHECK(for tr1/unordered_set,
995 ac_cv_cxx_tr1_unordered_set,
998 AC_TRY_COMPILE([#include <tr1/unordered_set>], [using std::tr1::unordered_set;],
999 ac_cv_cxx_tr1_unordered_set=yes, ac_cv_cxx_tr1_unordered_set=no)
1002 if test "$ac_cv_cxx_tr1_unordered_set" = yes; then
1003 AC_DEFINE(HAVE_TR1_UNORDERED_SET,,[Define if tr1/unordered_set is present. ])
1010 <section xml:id="backwards.third.support_cxx11"><info><title>
1011 Support for C++11 dialect.
1015 <para>Check for baseline language coverage in the compiler for the C++11 standard.
1019 # AC_COMPILE_STDCXX_11
1020 AC_DEFUN([AC_COMPILE_STDCXX_11], [
1021 AC_CACHE_CHECK(if g++ supports C++11 features without additional flags,
1022 ac_cv_cxx_compile_cxx11_native,
1026 template <typename T>
1029 static constexpr T value{ __cplusplus };
1032 typedef check<check<bool>> right_angle_brackets;
1037 typedef check<int> check_type;
1039 check_type&& cr = static_cast<check_type&&>(c);
1041 static_assert(check_type::value == 201103L, "C++11 compiler");],,
1042 ac_cv_cxx_compile_cxx11_native=yes, ac_cv_cxx_compile_cxx11_native=no)
1046 AC_CACHE_CHECK(if g++ supports C++11 features with -std=c++11,
1047 ac_cv_cxx_compile_cxx11_cxx,
1050 ac_save_CXXFLAGS="$CXXFLAGS"
1051 CXXFLAGS="$CXXFLAGS -std=c++11"
1053 template <typename T>
1056 static constexpr T value{ __cplusplus };
1059 typedef check<check<bool>> right_angle_brackets;
1064 typedef check<int> check_type;
1066 check_type&& cr = static_cast<check_type&&>(c);
1068 static_assert(check_type::value == 201103L, "C++11 compiler");],,
1069 ac_cv_cxx_compile_cxx11_cxx=yes, ac_cv_cxx_compile_cxx11_cxx=no)
1070 CXXFLAGS="$ac_save_CXXFLAGS"
1074 AC_CACHE_CHECK(if g++ supports C++11 features with -std=gnu++11,
1075 ac_cv_cxx_compile_cxx11_gxx,
1078 ac_save_CXXFLAGS="$CXXFLAGS"
1079 CXXFLAGS="$CXXFLAGS -std=gnu++11"
1081 template <typename T>
1084 static constexpr T value{ __cplusplus };
1087 typedef check<check<bool>> right_angle_brackets;
1092 typedef check<int> check_type;
1094 check_type&& cr = static_cast<check_type&&>(c);
1096 static_assert(check_type::value == 201103L, "C++11 compiler");],,
1097 ac_cv_cxx_compile_cxx11_gxx=yes, ac_cv_cxx_compile_cxx11_gxx=no)
1098 CXXFLAGS="$ac_save_CXXFLAGS"
1102 if test "$ac_cv_cxx_compile_cxx11_native" = yes ||
1103 test "$ac_cv_cxx_compile_cxx11_cxx" = yes ||
1104 test "$ac_cv_cxx_compile_cxx11_gxx" = yes; then
1105 AC_DEFINE(HAVE_STDCXX_11,,[Define if g++ supports C++11 features. ])
1111 <para>Check for library coverage of the C++2011 standard.
1112 (Some library headers are commented out in this check, they are
1113 not currently provided by libstdc++).
1117 # AC_HEADER_STDCXX_11
1118 AC_DEFUN([AC_HEADER_STDCXX_11], [
1119 AC_CACHE_CHECK(for ISO C++11 include files,
1120 ac_cv_cxx_stdcxx_11,
1121 [AC_REQUIRE([AC_COMPILE_STDCXX_11])
1124 ac_save_CXXFLAGS="$CXXFLAGS"
1125 CXXFLAGS="$CXXFLAGS -std=gnu++11"
1128 #include <cassert>
1129 #include <ccomplex>
1130 #include <cctype>
1131 #include <cerrno>
1132 #include <cfenv>
1133 #include <cfloat>
1134 #include <cinttypes>
1135 #include <ciso646>
1136 #include <climits>
1137 #include <clocale>
1138 #include <cmath>
1139 #include <csetjmp>
1140 #include <csignal>
1141 #include <cstdalign>
1142 #include <cstdarg>
1143 #include <cstdbool>
1144 #include <cstddef>
1145 #include <cstdint>
1146 #include <cstdio>
1147 #include <cstdlib>
1148 #include <cstring>
1149 #include <ctgmath>
1150 #include <ctime>
1151 // #include <cuchar>
1152 #include <cwchar>
1153 #include <cwctype>
1155 #include <algorithm>
1156 #include <array>
1157 #include <atomic>
1158 #include <bitset>
1159 #include <chrono>
1160 // #include <codecvt>
1161 #include <complex>
1162 #include <condition_variable>
1163 #include <deque>
1164 #include <exception>
1165 #include <forward_list>
1166 #include <fstream>
1167 #include <functional>
1168 #include <future>
1169 #include <initializer_list>
1170 #include <iomanip>
1171 #include <ios>
1172 #include <iosfwd>
1173 #include <iostream>
1174 #include <istream>
1175 #include <iterator>
1176 #include <limits>
1177 #include <list>
1178 #include <locale>
1179 #include <map>
1180 #include <memory>
1181 #include <mutex>
1182 #include <new>
1183 #include <numeric>
1184 #include <ostream>
1185 #include <queue>
1186 #include <random>
1187 #include <ratio>
1188 #include <regex>
1189 #include <scoped_allocator>
1190 #include <set>
1191 #include <sstream>
1192 #include <stack>
1193 #include <stdexcept>
1194 #include <streambuf>
1195 #include <string>
1196 #include <system_error>
1197 #include <thread>
1198 #include <tuple>
1199 #include <typeindex>
1200 #include <typeinfo>
1201 #include <type_traits>
1202 #include <unordered_map>
1203 #include <unordered_set>
1204 #include <utility>
1205 #include <valarray>
1206 #include <vector>
1208 ac_cv_cxx_stdcxx_11=yes, ac_cv_cxx_stdcxx_11=no)
1210 CXXFLAGS="$ac_save_CXXFLAGS"
1212 if test "$ac_cv_cxx_stdcxx_11" = yes; then
1213 AC_DEFINE(STDCXX_11_HEADERS,,[Define if ISO C++11 header files are present. ])
1218 <para>As is the case for TR1 support, these autoconf macros can be made for a finer-grained, per-header-file check. For
1219 <filename class="headerfile"><unordered_map></filename>
1223 # AC_HEADER_UNORDERED_MAP
1224 AC_DEFUN([AC_HEADER_UNORDERED_MAP], [
1225 AC_CACHE_CHECK(for unordered_map,
1226 ac_cv_cxx_unordered_map,
1227 [AC_REQUIRE([AC_COMPILE_STDCXX_11])
1230 ac_save_CXXFLAGS="$CXXFLAGS"
1231 CXXFLAGS="$CXXFLAGS -std=gnu++11"
1232 AC_TRY_COMPILE([#include <unordered_map>], [using std::unordered_map;],
1233 ac_cv_cxx_unordered_map=yes, ac_cv_cxx_unordered_map=no)
1234 CXXFLAGS="$ac_save_CXXFLAGS"
1237 if test "$ac_cv_cxx_unordered_map" = yes; then
1238 AC_DEFINE(HAVE_UNORDERED_MAP,,[Define if unordered_map is present. ])
1244 # AC_HEADER_UNORDERED_SET
1245 AC_DEFUN([AC_HEADER_UNORDERED_SET], [
1246 AC_CACHE_CHECK(for unordered_set,
1247 ac_cv_cxx_unordered_set,
1248 [AC_REQUIRE([AC_COMPILE_STDCXX_11])
1251 ac_save_CXXFLAGS="$CXXFLAGS"
1252 CXXFLAGS="$CXXFLAGS -std=gnu++11"
1253 AC_TRY_COMPILE([#include <unordered_set>], [using std::unordered_set;],
1254 ac_cv_cxx_unordered_set=yes, ac_cv_cxx_unordered_set=no)
1255 CXXFLAGS="$ac_save_CXXFLAGS"
1258 if test "$ac_cv_cxx_unordered_set" = yes; then
1259 AC_DEFINE(HAVE_UNORDERED_SET,,[Define if unordered_set is present. ])
1265 Some C++11 features first appeared in GCC 4.3 and could be enabled by
1266 <option>-std=c++0x</option> and <option>-std=gnu++0x</option> for GCC
1267 releases which pre-date the 2011 standard. Those C++11 features and GCC's
1268 support for them were still changing until the 2011 standard was finished,
1269 but the autoconf checks above could be extended to test for incomplete
1270 C++11 support with <option>-std=c++0x</option> and
1271 <option>-std=gnu++0x</option>.
1276 <section xml:id="backwards.third.iterator_type"><info><title>
1277 <code>Container::iterator_type</code> is not necessarily <code>Container::value_type*</code>
1282 This is a change in behavior from older versions. Now, most
1283 <type>iterator_type</type> typedefs in container classes are POD
1284 objects, not <type>value_type</type> pointers.
1290 <bibliography xml:id="backwards.biblio"><info><title>Bibliography</title></info>
1295 <link xmlns:xlink="http://www.w3.org/1999/xlink"
1296 xlink:href="http://www.kegel.com/gcc/gcc4.html">
1297 Migrating to GCC 4.1
1301 <author><personname><firstname>Dan</firstname><surname>Kegel</surname></personname></author>
1306 <link xmlns:xlink="http://www.w3.org/1999/xlink"
1307 xlink:href="http://lists.debian.org/debian-gcc/2006/03/msg00405.html">
1308 Building the Whole Debian Archive with GCC 4.1: A Summary
1311 <author><personname><firstname>Martin</firstname><surname>Michlmayr</surname></personname></author>
1316 <link xmlns:xlink="http://www.w3.org/1999/xlink"
1317 xlink:href="http://annwm.lbl.gov/~leggett/Atlas/gcc-3.2.html">
1318 Migration guide for GCC-3.2