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>
18 <section xml:id="backwards.first"><info><title>First</title></info>
21 <para>The first generation GNU C++ library was called libg++. It was a
22 separate GNU project, although reliably paired with GCC. Rumors imply
23 that it had a working relationship with at least two kinds of
27 <para>Some background: libg++ was designed and created when there was no
28 ISO standard to provide guidance. Classes like linked lists are now
29 provided for by <classname>list<T></classname> and do not need to be
30 created by <function>genclass</function>. (For that matter, templates exist
31 now and are well-supported, whereas genclass (mostly) predates them.)
34 <para>There are other classes in libg++ that are not specified in the
35 ISO Standard (e.g., statistical analysis). While there are a lot of
36 really useful things that are used by a lot of people, the Standards
37 Committee couldn't include everything, and so a lot of those
38 <quote>obvious</quote> classes didn't get included.
41 <para>Known Issues include many of the limitations of its immediate ancestor.</para>
43 <para>Portability notes and known implementation limitations are as follows.</para>
45 <section xml:id="backwards.first.ios_base"><info><title>No <code>ios_base</code></title></info>
48 <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>.
52 <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>
56 In earlier versions of the standard,
57 <filename class="headerfile"><fstream.h></filename>,
58 <filename class="headerfile"><ostream.h></filename>
59 and <filename class="headerfile"><istream.h></filename>
61 <code>cout</code>, <code>cin</code> and so on. ISO C++ specifies that one needs to include
62 <filename class="headerfile"><iostream></filename>
63 explicitly to get the required definitions.
65 <para> Some include adjustment may be required.</para>
67 <para>This project is no longer maintained or supported, and the sources
68 archived. For the desperate,
69 the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/extensions.html">GCC extensions
70 page</link> describes where to find the last libg++ source. The code is
71 considered replaced and rewritten.
76 <section xml:id="backwards.second"><info><title>Second</title></info>
80 The second generation GNU C++ library was called libstdc++, or
81 libstdc++-v2. It spans the time between libg++ and pre-ISO C++
82 standardization and is usually associated with the following GCC
83 releases: egcs 1.x, gcc 2.95, and gcc 2.96.
87 The STL portions of this library are based on SGI/HP STL release 3.11.
91 This project is no longer maintained or supported, and the sources
92 archived. The code is considered replaced and rewritten.
96 Portability notes and known implementation limitations are as follows.
99 <section xml:id="backwards.second.std"><info><title>Namespace <code>std::</code> not supported</title></info>
103 Some care is required to support C++ compiler and or library
104 implementation that do not have the standard library in
105 <code>namespace std</code>.
109 The following sections list some possible solutions to support compilers
110 that cannot ignore <code>std::</code>-qualified names.
114 First, see if the compiler has a flag for this. Namespace
115 back-portability-issues are generally not a problem for g++
116 compilers that do not have libstdc++ in <code>std::</code>, as the
117 compilers use <option>-fno-honor-std</option> (ignore
118 <code>std::</code>, <code>:: = std::</code>) by default. That is,
119 the responsibility for enabling or disabling <code>std::</code> is
120 on the user; the maintainer does not have to care about it. This
121 probably applies to some other compilers as well.
125 Second, experiment with a variety of pre-processor tricks.
129 By defining <code>std</code> as a macro, fully-qualified namespace
130 calls become global. Volia.
134 #ifdef WICKEDLY_OLD_COMPILER
140 Thanks to Juergen Heinzl who posted this solution on gnu.gcc.help.
144 Another pre-processor based approach is to define a macro
145 <code>NAMESPACE_STD</code>, which is defined to either
146 <quote> </quote> or <quote>std</quote> based on a compile-type
147 test. On GNU systems, this can be done with autotools by means of
148 an autoconf test (see below) for <code>HAVE_NAMESPACE_STD</code>,
149 then using that to set a value for the <code>NAMESPACE_STD</code>
150 macro. At that point, one is able to use
151 <code>NAMESPACE_STD::string</code>, which will evaluate to
152 <code>std::string</code> or <code>::string</code> (i.e., in the
153 global namespace on systems that do not put <code>string</code> in
158 dnl @synopsis AC_CXX_NAMESPACE_STD
160 dnl If the compiler supports namespace std, define
161 dnl HAVE_NAMESPACE_STD.
164 dnl @author Todd Veldhuizen
165 dnl @author Luc Maisonobe <luc@spaceroots.org>
166 dnl @version 2004-02-04
167 dnl @license AllPermissive
168 AC_DEFUN([AC_CXX_NAMESPACE_STD], [
169 AC_CACHE_CHECK(if g++ supports namespace std,
170 ac_cv_cxx_have_std_namespace,
173 AC_TRY_COMPILE([#include <iostream>
174 std::istream& is = std::cin;],,
175 ac_cv_cxx_have_std_namespace=yes, ac_cv_cxx_have_std_namespace=no)
178 if test "$ac_cv_cxx_have_std_namespace" = yes; then
179 AC_DEFINE(HAVE_NAMESPACE_STD,,[Define if g++ supports namespace std. ])
185 <section xml:id="backwards.second.iterators"><info><title>Illegal iterator usage</title></info>
188 The following illustrate implementation-allowed illegal iterator
189 use, and then correct use.
195 you cannot do <code>ostream::operator<<(iterator)</code>
196 to print the address of the iterator => use
197 <code>operator<< &*iterator</code> instead
202 you cannot clear an iterator's reference (<code>iterator =
203 0</code>) => use <code>iterator = iterator_type();</code>
208 <code>if (iterator)</code> won't work any more => use
209 <code>if (iterator != iterator_type())</code>
215 <section xml:id="backwards.second.isspace"><info><title><code>isspace</code> from <filename class="headerfile"><cctype></filename> is a macro
220 Glibc 2.0.x and 2.1.x define <filename class="headerfile"><ctype.h></filename> functionality as macros
221 (isspace, isalpha etc.).
225 This implementations of libstdc++, however, keep these functions
226 as macros, and so it is not back-portable to use fully qualified
231 #include <cctype>
232 int main() { std::isspace('X'); }
236 Results in something like this:
240 std:: (__ctype_b[(int) ( ( 'X' ) )] & (unsigned short int) _ISspace ) ;
244 A solution is to modify a header-file so that the compiler tells
245 <filename class="headerfile"><ctype.h></filename> to define functions
250 // This keeps isalnum, et al from being propagated as macros.
252 # define __NO_CTYPE 1
257 Then, include <filename class="headerfile"><ctype.h></filename>
261 Another problem arises if you put a <code>using namespace
262 std;</code> declaration at the top, and include
263 <filename class="headerfile"><ctype.h></filename>. This will
264 result in ambiguities between the definitions in the global namespace
265 (<filename class="headerfile"><ctype.h></filename>) and the
266 definitions in namespace <code>std::</code>
267 (<code><cctype></code>).
271 <section xml:id="backwards.second.at"><info><title>No <code>vector::at</code>, <code>deque::at</code>, <code>string::at</code></title></info>
275 One solution is to add an autoconf-test for this:
279 AC_MSG_CHECKING(for container::at)
282 #include <vector>
283 #include <deque>
284 #include <string>
289 deque<int> test_deque(3);
291 vector<int> test_vector(2);
293 string test_string(<quote>test_string</quote>);
297 AC_DEFINE(HAVE_CONTAINER_AT)],
302 If you are using other (non-GNU) compilers it might be a good idea
303 to check for <code>string::at</code> separately.
308 <section xml:id="backwards.second.eof"><info><title>No <code>std::char_traits<char>::eof</code></title></info>
312 Use some kind of autoconf test, plus this:
316 #ifdef HAVE_CHAR_TRAITS
317 #define CPP_EOF std::char_traits<char>::eof()
325 <section xml:id="backwards.second.stringclear"><info><title>No <code>string::clear</code></title></info>
329 There are two functions for deleting the contents of a string:
330 <code>clear</code> and <code>erase</code> (the latter returns the
336 clear() { _M_mutate(0, this->size(), 0); }
341 erase(size_type __pos = 0, size_type __n = npos)
343 return this->replace(_M_check(__pos), _M_fold(__pos, __n),
344 _M_data(), _M_data());
349 Unfortunately, <code>clear</code> is not implemented in this
350 version, so you should use <code>erase</code> (which is probably
351 faster than <code>operator=(charT*)</code>).
355 <section xml:id="backwards.second.ostreamform_istreamscan"><info><title>
356 Removal of <code>ostream::form</code> and <code>istream::scan</code>
362 These are no longer supported. Please use stringstreams instead.
366 <section xml:id="backwards.second.stringstreams"><info><title>No <code>basic_stringbuf</code>, <code>basic_stringstream</code></title></info>
370 Although the ISO standard <code>i/ostringstream</code>-classes are
371 provided, (<filename class="headerfile"><sstream></filename>), for
372 compatibility with older implementations the pre-ISO
373 <code>i/ostrstream</code> (<filename class="headerfile"><strstream></filename>) interface is also provided,
380 <code>strstream</code> is considered to be deprecated
385 <code>strstream</code> is limited to <code>char</code>
390 with <code>ostringstream</code> you don't have to take care of
391 terminating the string or freeing its memory
396 <code>istringstream</code> can be re-filled (clear();
403 You can then use output-stringstreams like this:
408 # include <sstream>
410 # include <strstream>
414 std::ostringstream oss;
419 oss << <quote>Name=</quote> << m_name << <quote>, number=</quote> << m_number << std::endl;
422 oss << std::ends; // terminate the char*-string
425 // str() returns char* for ostrstream and a string for ostringstream
426 // this also causes ostrstream to think that the buffer's memory
428 m_label.set_text(oss.str());
430 // let the ostrstream take care of freeing the memory
436 Input-stringstreams can be used similarly:
443 std::istringstream iss(input);
445 std::istrstream iss(input.c_str());
452 <para> One (the only?) restriction is that an istrstream cannot be re-filled:
456 std::istringstream iss(numerator);
458 // this is not possible with istrstream
460 iss.str(denominator);
465 If you don't care about speed, you can put these conversions in
469 template <class X>
470 void fromString(const string& input, X& any)
473 std::istringstream iss(input);
475 std::istrstream iss(input.c_str());
480 throw runtime_error(..)
486 Another example of using stringstreams is in <link linkend="strings.string.shrink">this howto</link>.
489 <para> There is additional information in the libstdc++-v2 info files, in
490 particular <quote>info iostream</quote>.
494 <section xml:id="backwards.second.wchar"><info><title>Little or no wide character support</title></info>
497 Classes <classname>wstring</classname> and
498 <classname>char_traits<wchar_t></classname> are
503 <section xml:id="backwards.second.iostream_templates"><info><title>No templatized iostreams</title></info>
506 Classes <classname>wfilebuf</classname> and
507 <classname>wstringstream</classname> are not supported.
511 <section xml:id="backwards.second.thread_safety"><info><title>Thread safety issues</title></info>
515 Earlier GCC releases had a somewhat different approach to
516 threading configuration and proper compilation. Before GCC 3.0,
517 configuration of the threading model was dictated by compiler
518 command-line options and macros (both of which were somewhat
519 thread-implementation and port-specific). There were no
520 guarantees related to being able to link code compiled with one
521 set of options and macro setting with another set.
525 For GCC 3.0, configuration of the threading model used with
526 libraries and user-code is performed when GCC is configured and
527 built using the --enable-threads and --disable-threads options.
528 The ABI is stable for symbol name-mangling and limited functional
529 compatibility exists between code compiled under different
534 The libstdc++ library has been designed so that it can be used in
535 multithreaded applications (with libstdc++-v2 this was only true
536 of the STL parts.) The first problem is finding a
537 <emphasis>fast</emphasis> method of implementation portable to
538 all platforms. Due to historical reasons, some of the library is
539 written against per-CPU-architecture spinlocks and other parts
540 against the gthr.h abstraction layer which is provided by gcc. A
541 minor problem that pops up every so often is different
542 interpretations of what "thread-safe" means for a
543 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
544 definition that SGI</link> uses for their STL subset. However,
545 the exception for read-only containers only applies to the STL
546 components. This definition is widely-used and something similar
547 will be used in the next version of the C++ standard library.
551 Here is a small link farm to threads (no pun) in the mail
552 archives that discuss the threading problem. Each link is to the
553 first relevant message in the thread; from there you can use
554 "Thread Next" to move down the thread. This farm is in
555 latest-to-oldest order.
561 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
562 six situations involving threads</link> for the 3.0
568 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/libstdc++/2001-05/msg00384.html">
569 This message</link> inspired a recent updating of issues with
570 threading and the SGI STL library. It also contains some
571 example POSIX-multithreaded STL code.
577 (A large selection of links to older messages has been removed;
578 many of the messages from 1999 were lost in a disk crash, and the
579 few people with access to the backup tapes have been too swamped
580 with work to restore them. Many of the points have been
587 <section xml:id="backwards.third"><info><title>Third</title></info>
590 <para> The third generation GNU C++ library is called libstdc++, or
594 <para>The subset commonly known as the Standard Template Library
595 (chapters 23 through 25, mostly) is adapted from the final release
596 of the SGI STL (version 3.3), with extensive changes.
599 <para>A more formal description of the V3 goals can be found in the
600 official <link linkend="contrib.design_notes">design document</link>.
603 <para>Portability notes and known implementation limitations are as follows.</para>
605 <section xml:id="backwards.third.headers"><info><title>Pre-ISO headers moved to backwards or removed</title></info>
608 <para> The pre-ISO C++ headers
609 (<filename class="headerfile"><iostream.h></filename>,
610 <filename class="headerfile"><defalloc.h></filename> etc.) are
611 available, unlike previous libstdc++ versions, but inclusion
612 generates a warning that you are using deprecated headers.
615 <para>This compatibility layer is constructed by including the
616 standard C++ headers, and injecting any items in
617 <code>std::</code> into the global namespace.
619 <para>For those of you new to ISO C++ (welcome, time travelers!), no,
620 that isn't a typo. Yes, the headers really have new names.
621 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
625 <para> Some include adjustment may be required. What follows is an
626 autoconf test that defines <code>PRE_STDCXX_HEADERS</code> when they
630 # AC_HEADER_PRE_STDCXX
631 AC_DEFUN([AC_HEADER_PRE_STDCXX], [
632 AC_CACHE_CHECK(for pre-ISO C++ include files,
633 ac_cv_cxx_pre_stdcxx,
636 ac_save_CXXFLAGS="$CXXFLAGS"
637 CXXFLAGS="$CXXFLAGS -Wno-deprecated"
639 # Omit defalloc.h, as compilation with newer compilers is problematic.
641 #include <new.h>
642 #include <iterator.h>
643 #include <alloc.h>
644 #include <set.h>
645 #include <hashtable.h>
646 #include <hash_set.h>
647 #include <fstream.h>
648 #include <tempbuf.h>
649 #include <istream.h>
650 #include <bvector.h>
651 #include <stack.h>
652 #include <rope.h>
653 #include <complex.h>
654 #include <ostream.h>
655 #include <heap.h>
656 #include <iostream.h>
657 #include <function.h>
658 #include <multimap.h>
659 #include <pair.h>
660 #include <stream.h>
661 #include <iomanip.h>
662 #include <slist.h>
663 #include <tree.h>
664 #include <vector.h>
665 #include <deque.h>
666 #include <multiset.h>
667 #include <list.h>
668 #include <map.h>
669 #include <algobase.h>
670 #include <hash_map.h>
671 #include <algo.h>
672 #include <queue.h>
673 #include <streambuf.h>
675 ac_cv_cxx_pre_stdcxx=yes, ac_cv_cxx_pre_stdcxx=no)
676 CXXFLAGS="$ac_save_CXXFLAGS"
679 if test "$ac_cv_cxx_pre_stdcxx" = yes; then
680 AC_DEFINE(PRE_STDCXX_HEADERS,,[Define if pre-ISO C++ header files are present. ])
685 <para>Porting between pre-ISO headers and ISO headers is simple: headers
686 like <filename class="headerfile"><vector.h></filename> can be replaced with <filename class="headerfile"><vector></filename> and a using
687 directive <code>using namespace std;</code> can be put at the global
688 scope. This should be enough to get this code compiling, assuming the
689 other usage is correct.
693 <section xml:id="backwards.third.hash"><info><title>Extension headers hash_map, hash_set moved to ext or backwards</title></info>
696 <para>At this time most of the features of the SGI STL extension have been
697 replaced by standardized libraries.
698 In particular, the <classname>unordered_map</classname> and
699 <classname>unordered_set</classname> containers of TR1 and C++ 2011
700 are suitable replacements for the non-standard
701 <classname>hash_map</classname> and <classname>hash_set</classname>
702 containers in the SGI STL.
704 <para> Header files <filename class="headerfile"><hash_map></filename> and <filename class="headerfile"><hash_set></filename> moved
705 to <filename class="headerfile"><ext/hash_map></filename> and <filename class="headerfile"><ext/hash_set></filename>,
706 respectively. At the same time, all types in these files are enclosed
707 in <code>namespace __gnu_cxx</code>. Later versions deprecate
708 these files, and suggest using TR1's <filename class="headerfile"><unordered_map></filename>
709 and <filename class="headerfile"><unordered_set></filename> instead.
712 <para>The extensions are no longer in the global or <code>std</code>
713 namespaces, instead they are declared in the <code>__gnu_cxx</code>
714 namespace. For maximum portability, consider defining a namespace
715 alias to use to talk about extensions, e.g.:
720 #include <hash_map.h>
721 namespace extension { using ::hash_map; }; // inherit globals
723 #include <backward/hash_map>
724 #if __GNUC__ == 3 && __GNUC_MINOR__ == 0
725 namespace extension = std; // GCC 3.0
727 namespace extension = ::__gnu_cxx; // GCC 3.1 and later
730 #else // ... there are other compilers, right?
731 namespace extension = std;
734 extension::hash_map<int,int> my_map;
736 <para>This is a bit cleaner than defining typedefs for all the
737 instantiations you might need.
741 <para>The following autoconf tests check for working HP/SGI hash containers.
745 # AC_HEADER_EXT_HASH_MAP
746 AC_DEFUN([AC_HEADER_EXT_HASH_MAP], [
747 AC_CACHE_CHECK(for ext/hash_map,
748 ac_cv_cxx_ext_hash_map,
751 ac_save_CXXFLAGS="$CXXFLAGS"
752 CXXFLAGS="$CXXFLAGS -Werror"
753 AC_TRY_COMPILE([#include <ext/hash_map>], [using __gnu_cxx::hash_map;],
754 ac_cv_cxx_ext_hash_map=yes, ac_cv_cxx_ext_hash_map=no)
755 CXXFLAGS="$ac_save_CXXFLAGS"
758 if test "$ac_cv_cxx_ext_hash_map" = yes; then
759 AC_DEFINE(HAVE_EXT_HASH_MAP,,[Define if ext/hash_map is present. ])
765 # AC_HEADER_EXT_HASH_SET
766 AC_DEFUN([AC_HEADER_EXT_HASH_SET], [
767 AC_CACHE_CHECK(for ext/hash_set,
768 ac_cv_cxx_ext_hash_set,
771 ac_save_CXXFLAGS="$CXXFLAGS"
772 CXXFLAGS="$CXXFLAGS -Werror"
773 AC_TRY_COMPILE([#include <ext/hash_set>], [using __gnu_cxx::hash_set;],
774 ac_cv_cxx_ext_hash_set=yes, ac_cv_cxx_ext_hash_set=no)
775 CXXFLAGS="$ac_save_CXXFLAGS"
778 if test "$ac_cv_cxx_ext_hash_set" = yes; then
779 AC_DEFINE(HAVE_EXT_HASH_SET,,[Define if ext/hash_set is present. ])
785 <section xml:id="backwards.third.nocreate_noreplace"><info><title>No <code>ios::nocreate/ios::noreplace</code>.
789 <para> The existence of <code>ios::nocreate</code> being used for
790 input-streams has been confirmed, most probably because the author
791 thought it would be more correct to specify nocreate explicitly. So
792 it can be left out for input-streams.
795 <para>For output streams, <quote>nocreate</quote> is probably the default,
796 unless you specify <code>std::ios::trunc</code> ? To be safe, you can
797 open the file for reading, check if it has been opened, and then
798 decide whether you want to create/replace or not. To my knowledge,
799 even older implementations support <code>app</code>, <code>ate</code>
800 and <code>trunc</code> (except for <code>app</code> ?).
804 <section xml:id="backwards.third.streamattach"><info><title>
805 No <code>stream::attach(int fd)</code>
810 Phil Edwards writes: It was considered and rejected for the ISO
811 standard. Not all environments use file descriptors. Of those
812 that do, not all of them use integers to represent them.
816 For a portable solution (among systems which use
817 file descriptors), you need to implement a subclass of
818 <code>std::streambuf</code> (or
819 <code>std::basic_streambuf<..></code>) which opens a file
820 given a descriptor, and then pass an instance of this to the
825 An extension is available that implements this.
826 <filename class="headerfile"><ext/stdio_filebuf.h></filename> contains a derived class called
827 <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>.
828 This class can be constructed from a C <code>FILE*</code> or a file
829 descriptor, and provides the <code>fd()</code> function.
833 For another example of this, refer to
834 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.josuttis.com/cppcode/fdstream.html">fdstream example</link>
839 <section xml:id="backwards.third.support_cxx98"><info><title>
840 Support for C++98 dialect.
844 <para>Check for complete library coverage of the C++1998/2003 standard.
848 # AC_HEADER_STDCXX_98
849 AC_DEFUN([AC_HEADER_STDCXX_98], [
850 AC_CACHE_CHECK(for ISO C++ 98 include files,
855 #include <cassert>
856 #include <cctype>
857 #include <cerrno>
858 #include <cfloat>
859 #include <ciso646>
860 #include <climits>
861 #include <clocale>
862 #include <cmath>
863 #include <csetjmp>
864 #include <csignal>
865 #include <cstdarg>
866 #include <cstddef>
867 #include <cstdio>
868 #include <cstdlib>
869 #include <cstring>
870 #include <ctime>
872 #include <algorithm>
873 #include <bitset>
874 #include <complex>
875 #include <deque>
876 #include <exception>
877 #include <fstream>
878 #include <functional>
879 #include <iomanip>
881 #include <iosfwd>
882 #include <iostream>
883 #include <istream>
884 #include <iterator>
885 #include <limits>
886 #include <list>
887 #include <locale>
889 #include <memory>
891 #include <numeric>
892 #include <ostream>
893 #include <queue>
895 #include <sstream>
896 #include <stack>
897 #include <stdexcept>
898 #include <streambuf>
899 #include <string>
900 #include <typeinfo>
901 #include <utility>
902 #include <valarray>
903 #include <vector>
905 ac_cv_cxx_stdcxx_98=yes, ac_cv_cxx_stdcxx_98=no)
908 if test "$ac_cv_cxx_stdcxx_98" = yes; then
909 AC_DEFINE(STDCXX_98_HEADERS,,[Define if ISO C++ 1998 header files are present. ])
915 <section xml:id="backwards.third.support_tr1"><info><title>
916 Support for C++TR1 dialect.
920 <para>Check for library coverage of the TR1 standard.
924 # AC_HEADER_STDCXX_TR1
925 AC_DEFUN([AC_HEADER_STDCXX_TR1], [
926 AC_CACHE_CHECK(for ISO C++ TR1 include files,
927 ac_cv_cxx_stdcxx_tr1,
931 #include <tr1/array>
932 #include <tr1/ccomplex>
933 #include <tr1/cctype>
934 #include <tr1/cfenv>
935 #include <tr1/cfloat>
936 #include <tr1/cinttypes>
937 #include <tr1/climits>
938 #include <tr1/cmath>
939 #include <tr1/complex>
940 #include <tr1/cstdarg>
941 #include <tr1/cstdbool>
942 #include <tr1/cstdint>
943 #include <tr1/cstdio>
944 #include <tr1/cstdlib>
945 #include <tr1/ctgmath>
946 #include <tr1/ctime>
947 #include <tr1/cwchar>
948 #include <tr1/cwctype>
949 #include <tr1/functional>
950 #include <tr1/memory>
951 #include <tr1/random>
952 #include <tr1/regex>
953 #include <tr1/tuple>
954 #include <tr1/type_traits>
955 #include <tr1/unordered_set>
956 #include <tr1/unordered_map>
957 #include <tr1/utility>
959 ac_cv_cxx_stdcxx_tr1=yes, ac_cv_cxx_stdcxx_tr1=no)
962 if test "$ac_cv_cxx_stdcxx_tr1" = yes; then
963 AC_DEFINE(STDCXX_TR1_HEADERS,,[Define if ISO C++ TR1 header files are present. ])
968 <para>An alternative is to check just for specific TR1 includes, such as <unordered_map> and <unordered_set>.
972 # AC_HEADER_TR1_UNORDERED_MAP
973 AC_DEFUN([AC_HEADER_TR1_UNORDERED_MAP], [
974 AC_CACHE_CHECK(for tr1/unordered_map,
975 ac_cv_cxx_tr1_unordered_map,
978 AC_TRY_COMPILE([#include <tr1/unordered_map>], [using std::tr1::unordered_map;],
979 ac_cv_cxx_tr1_unordered_map=yes, ac_cv_cxx_tr1_unordered_map=no)
982 if test "$ac_cv_cxx_tr1_unordered_map" = yes; then
983 AC_DEFINE(HAVE_TR1_UNORDERED_MAP,,[Define if tr1/unordered_map is present. ])
989 # AC_HEADER_TR1_UNORDERED_SET
990 AC_DEFUN([AC_HEADER_TR1_UNORDERED_SET], [
991 AC_CACHE_CHECK(for tr1/unordered_set,
992 ac_cv_cxx_tr1_unordered_set,
995 AC_TRY_COMPILE([#include <tr1/unordered_set>], [using std::tr1::unordered_set;],
996 ac_cv_cxx_tr1_unordered_set=yes, ac_cv_cxx_tr1_unordered_set=no)
999 if test "$ac_cv_cxx_tr1_unordered_set" = yes; then
1000 AC_DEFINE(HAVE_TR1_UNORDERED_SET,,[Define if tr1/unordered_set is present. ])
1007 <section xml:id="backwards.third.support_cxx11"><info><title>
1008 Support for C++11 dialect.
1012 <para>Check for baseline language coverage in the compiler for the C++11 standard.
1016 # AC_COMPILE_STDCXX_11
1017 AC_DEFUN([AC_COMPILE_STDCXX_11], [
1018 AC_CACHE_CHECK(if g++ supports C++11 features without additional flags,
1019 ac_cv_cxx_compile_cxx11_native,
1023 template <typename T>
1026 static constexpr T value{ __cplusplus };
1029 typedef check<check<bool>> right_angle_brackets;
1034 typedef check<int> check_type;
1036 check_type&& cr = static_cast<check_type&&>(c);
1038 static_assert(check_type::value == 201103L, "C++11 compiler");],,
1039 ac_cv_cxx_compile_cxx11_native=yes, ac_cv_cxx_compile_cxx11_native=no)
1043 AC_CACHE_CHECK(if g++ supports C++11 features with -std=c++11,
1044 ac_cv_cxx_compile_cxx11_cxx,
1047 ac_save_CXXFLAGS="$CXXFLAGS"
1048 CXXFLAGS="$CXXFLAGS -std=c++11"
1050 template <typename T>
1053 static constexpr T value{ __cplusplus };
1056 typedef check<check<bool>> right_angle_brackets;
1061 typedef check<int> check_type;
1063 check_type&& cr = static_cast<check_type&&>(c);
1065 static_assert(check_type::value == 201103L, "C++11 compiler");],,
1066 ac_cv_cxx_compile_cxx11_cxx=yes, ac_cv_cxx_compile_cxx11_cxx=no)
1067 CXXFLAGS="$ac_save_CXXFLAGS"
1071 AC_CACHE_CHECK(if g++ supports C++11 features with -std=gnu++11,
1072 ac_cv_cxx_compile_cxx11_gxx,
1075 ac_save_CXXFLAGS="$CXXFLAGS"
1076 CXXFLAGS="$CXXFLAGS -std=gnu++11"
1078 template <typename T>
1081 static constexpr T value{ __cplusplus };
1084 typedef check<check<bool>> right_angle_brackets;
1089 typedef check<int> check_type;
1091 check_type&& cr = static_cast<check_type&&>(c);
1093 static_assert(check_type::value == 201103L, "C++11 compiler");],,
1094 ac_cv_cxx_compile_cxx11_gxx=yes, ac_cv_cxx_compile_cxx11_gxx=no)
1095 CXXFLAGS="$ac_save_CXXFLAGS"
1099 if test "$ac_cv_cxx_compile_cxx11_native" = yes ||
1100 test "$ac_cv_cxx_compile_cxx11_cxx" = yes ||
1101 test "$ac_cv_cxx_compile_cxx11_gxx" = yes; then
1102 AC_DEFINE(HAVE_STDCXX_11,,[Define if g++ supports C++11 features. ])
1108 <para>Check for library coverage of the C++2011 standard.
1109 (Some library headers are commented out in this check, they are
1110 not currently provided by libstdc++).
1114 # AC_HEADER_STDCXX_11
1115 AC_DEFUN([AC_HEADER_STDCXX_11], [
1116 AC_CACHE_CHECK(for ISO C++11 include files,
1117 ac_cv_cxx_stdcxx_11,
1118 [AC_REQUIRE([AC_COMPILE_STDCXX_11])
1121 ac_save_CXXFLAGS="$CXXFLAGS"
1122 CXXFLAGS="$CXXFLAGS -std=gnu++11"
1125 #include <cassert>
1126 #include <ccomplex>
1127 #include <cctype>
1128 #include <cerrno>
1129 #include <cfenv>
1130 #include <cfloat>
1131 #include <cinttypes>
1132 #include <ciso646>
1133 #include <climits>
1134 #include <clocale>
1135 #include <cmath>
1136 #include <csetjmp>
1137 #include <csignal>
1138 #include <cstdalign>
1139 #include <cstdarg>
1140 #include <cstdbool>
1141 #include <cstddef>
1142 #include <cstdint>
1143 #include <cstdio>
1144 #include <cstdlib>
1145 #include <cstring>
1146 #include <ctgmath>
1147 #include <ctime>
1148 // #include <cuchar>
1149 #include <cwchar>
1150 #include <cwctype>
1152 #include <algorithm>
1153 #include <array>
1154 #include <atomic>
1155 #include <bitset>
1156 #include <chrono>
1157 // #include <codecvt>
1158 #include <complex>
1159 #include <condition_variable>
1160 #include <deque>
1161 #include <exception>
1162 #include <forward_list>
1163 #include <fstream>
1164 #include <functional>
1165 #include <future>
1166 #include <initializer_list>
1167 #include <iomanip>
1168 #include <ios>
1169 #include <iosfwd>
1170 #include <iostream>
1171 #include <istream>
1172 #include <iterator>
1173 #include <limits>
1174 #include <list>
1175 #include <locale>
1176 #include <map>
1177 #include <memory>
1178 #include <mutex>
1179 #include <new>
1180 #include <numeric>
1181 #include <ostream>
1182 #include <queue>
1183 #include <random>
1184 #include <ratio>
1185 #include <regex>
1186 #include <scoped_allocator>
1187 #include <set>
1188 #include <sstream>
1189 #include <stack>
1190 #include <stdexcept>
1191 #include <streambuf>
1192 #include <string>
1193 #include <system_error>
1194 #include <thread>
1195 #include <tuple>
1196 #include <typeindex>
1197 #include <typeinfo>
1198 #include <type_traits>
1199 #include <unordered_map>
1200 #include <unordered_set>
1201 #include <utility>
1202 #include <valarray>
1203 #include <vector>
1205 ac_cv_cxx_stdcxx_11=yes, ac_cv_cxx_stdcxx_11=no)
1207 CXXFLAGS="$ac_save_CXXFLAGS"
1209 if test "$ac_cv_cxx_stdcxx_11" = yes; then
1210 AC_DEFINE(STDCXX_11_HEADERS,,[Define if ISO C++11 header files are present. ])
1215 <para>As is the case for TR1 support, these autoconf macros can be made for a finer-grained, per-header-file check. For
1216 <filename class="headerfile"><unordered_map></filename>
1220 # AC_HEADER_UNORDERED_MAP
1221 AC_DEFUN([AC_HEADER_UNORDERED_MAP], [
1222 AC_CACHE_CHECK(for unordered_map,
1223 ac_cv_cxx_unordered_map,
1224 [AC_REQUIRE([AC_COMPILE_STDCXX_11])
1227 ac_save_CXXFLAGS="$CXXFLAGS"
1228 CXXFLAGS="$CXXFLAGS -std=gnu++11"
1229 AC_TRY_COMPILE([#include <unordered_map>], [using std::unordered_map;],
1230 ac_cv_cxx_unordered_map=yes, ac_cv_cxx_unordered_map=no)
1231 CXXFLAGS="$ac_save_CXXFLAGS"
1234 if test "$ac_cv_cxx_unordered_map" = yes; then
1235 AC_DEFINE(HAVE_UNORDERED_MAP,,[Define if unordered_map is present. ])
1241 # AC_HEADER_UNORDERED_SET
1242 AC_DEFUN([AC_HEADER_UNORDERED_SET], [
1243 AC_CACHE_CHECK(for unordered_set,
1244 ac_cv_cxx_unordered_set,
1245 [AC_REQUIRE([AC_COMPILE_STDCXX_11])
1248 ac_save_CXXFLAGS="$CXXFLAGS"
1249 CXXFLAGS="$CXXFLAGS -std=gnu++11"
1250 AC_TRY_COMPILE([#include <unordered_set>], [using std::unordered_set;],
1251 ac_cv_cxx_unordered_set=yes, ac_cv_cxx_unordered_set=no)
1252 CXXFLAGS="$ac_save_CXXFLAGS"
1255 if test "$ac_cv_cxx_unordered_set" = yes; then
1256 AC_DEFINE(HAVE_UNORDERED_SET,,[Define if unordered_set is present. ])
1262 Some C++11 features first appeared in GCC 4.3 and could be enabled by
1263 <option>-std=c++0x</option> and <option>-std=gnu++0x</option> for GCC
1264 releases which pre-date the 2011 standard. Those C++11 features and GCC's
1265 support for them were still changing until the 2011 standard was finished,
1266 but the autoconf checks above could be extended to test for incomplete
1267 C++11 support with <option>-std=c++0x</option> and
1268 <option>-std=gnu++0x</option>.
1273 <section xml:id="backwards.third.iterator_type"><info><title>
1274 <code>Container::iterator_type</code> is not necessarily <code>Container::value_type*</code>
1279 This is a change in behavior from older versions. Now, most
1280 <type>iterator_type</type> typedefs in container classes are POD
1281 objects, not <type>value_type</type> pointers.
1287 <bibliography xml:id="backwards.biblio"><info><title>Bibliography</title></info>
1292 <link xmlns:xlink="http://www.w3.org/1999/xlink"
1293 xlink:href="http://www.kegel.com/gcc/gcc4.html">
1294 Migrating to GCC 4.1
1298 <author><personname><firstname>Dan</firstname><surname>Kegel</surname></personname></author>
1303 <link xmlns:xlink="http://www.w3.org/1999/xlink"
1304 xlink:href="http://lists.debian.org/debian-gcc/2006/03/msg00405.html">
1305 Building the Whole Debian Archive with GCC 4.1: A Summary
1308 <author><personname><firstname>Martin</firstname><surname>Michlmayr</surname></personname></author>
1313 <link xmlns:xlink="http://www.w3.org/1999/xlink"
1314 xlink:href="http://annwm.lbl.gov/~leggett/Atlas/gcc-3.2.html">
1315 Migration guide for GCC-3.2