14fee23f9Smrg<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2d79abf08Smrg<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Backwards Compatibility</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><meta name="keywords" content="ISO C++, backwards" /><meta name="keywords" content="ISO C++, library" /><meta name="keywords" content="ISO C++, runtime, library" /><link rel="home" href="../index.html" title="The GNU C++ Library" /><link rel="up" href="appendix_porting.html" title="Appendix B. Porting and Maintenance" /><link rel="prev" href="api.html" title="API Evolution and Deprecation History" /><link rel="next" href="appendix_free.html" title="Appendix C. Free Software Needs Free Documentation" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Backwards Compatibility</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="api.html">Prev</a> </td><th width="60%" align="center">Appendix B. 34fee23f9Smrg Porting and Maintenance 44fee23f9Smrg 548fb7bfaSmrg</th><td width="20%" align="right"> <a accesskey="n" href="appendix_free.html">Next</a></td></tr></table><hr /></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="manual.appendix.porting.backwards"></a>Backwards Compatibility</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="backwards.first"></a>First</h3></div></div></div><p>The first generation GNU C++ library was called libg++. It was a 64fee23f9Smrgseparate GNU project, although reliably paired with GCC. Rumors imply 74fee23f9Smrgthat it had a working relationship with at least two kinds of 84fee23f9Smrgdinosaur. 94fee23f9Smrg</p><p>Some background: libg++ was designed and created when there was no 104fee23f9SmrgISO standard to provide guidance. Classes like linked lists are now 11*b1e83836Smrgprovided for by <code class="classname">std::list<T></code> and do not need to be 124fee23f9Smrgcreated by <code class="function">genclass</code>. (For that matter, templates exist 134fee23f9Smrgnow and are well-supported, whereas genclass (mostly) predates them.) 144fee23f9Smrg</p><p>There are other classes in libg++ that are not specified in the 154fee23f9SmrgISO Standard (e.g., statistical analysis). While there are a lot of 164fee23f9Smrgreally useful things that are used by a lot of people, the Standards 174fee23f9SmrgCommittee couldn't include everything, and so a lot of those 184fee23f9Smrg<span class="quote">“<span class="quote">obvious</span>”</span> classes didn't get included. 19*b1e83836Smrg</p><p>That project is no longer maintained or supported, and the sources 20*b1e83836Smrgarchived. For the desperate, the 21*b1e83836Smrg<a class="link" href="https://ftp.gnu.org/old-gnu/libg++/" target="_top">ftp.gnu.org</a> 22*b1e83836Smrgserver still has the libg++ source. 23*b1e83836Smrg</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="backwards.second"></a>Second</h3></div></div></div><p> 244fee23f9Smrg The second generation GNU C++ library was called libstdc++, or 254fee23f9Smrg libstdc++-v2. It spans the time between libg++ and pre-ISO C++ 264fee23f9Smrg standardization and is usually associated with the following GCC 274fee23f9Smrg releases: egcs 1.x, gcc 2.95, and gcc 2.96. 284fee23f9Smrg</p><p> 29*b1e83836Smrg The STL portions of that library are based on SGI/HP STL release 3.11. 304fee23f9Smrg</p><p> 31*b1e83836Smrg That project is no longer maintained or supported, and the sources 32*b1e83836Smrg archived. The code was replaced and rewritten for libstdc++-v3. 33*b1e83836Smrg</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="backwards.third"></a>Third</h3></div></div></div><p> The third generation GNU C++ library is called libstdc++, or 344fee23f9Smrglibstdc++-v3. 354fee23f9Smrg</p><p>The subset commonly known as the Standard Template Library 36*b1e83836Smrg (clauses 23 through 25 in C++98, mostly) is adapted from the final release 374fee23f9Smrg of the SGI STL (version 3.3), with extensive changes. 384fee23f9Smrg </p><p>A more formal description of the V3 goals can be found in the 394fee23f9Smrg official <a class="link" href="source_design_notes.html" title="Design Notes">design document</a>. 40b17d1066Smrg </p><p>Portability notes and known implementation limitations are as follows.</p><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.third.headers"></a>Pre-ISO headers removed</h4></div></div></div><p> The pre-ISO C++ headers 4148fb7bfaSmrg (<code class="filename"><iostream.h></code>, 4248fb7bfaSmrg <code class="filename"><defalloc.h></code> etc.) are 43b17d1066Smrg not supported. 44b17d1066Smrg</p><p>For those of you new to ISO C++ (welcome, time travelers!), the 45b17d1066Smrg ancient pre-ISO headers have new names. 46b17d1066Smrg The C++ FAQ has a good explanation in <a class="link" href="https://isocpp.org/wiki/faq/coding-standards#std-headers" target="_top">What's 474d5abbe8Smrg the difference between <xxx> and <xxx.h> headers?</a>. 48b17d1066Smrg </p><p>Porting between pre-ISO headers and ISO headers is simple: headers 4948fb7bfaSmrglike <code class="filename"><vector.h></code> can be replaced with <code class="filename"><vector></code> and a using 504fee23f9Smrgdirective <code class="code">using namespace std;</code> can be put at the global 514fee23f9Smrgscope. This should be enough to get this code compiling, assuming the 524fee23f9Smrgother usage is correct. 5348fb7bfaSmrg</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.third.hash"></a>Extension headers hash_map, hash_set moved to ext or backwards</h4></div></div></div><p>At this time most of the features of the SGI STL extension have been 544fee23f9Smrg replaced by standardized libraries. 5548fb7bfaSmrg In particular, the <code class="classname">unordered_map</code> and 5648fb7bfaSmrg <code class="classname">unordered_set</code> containers of TR1 and C++ 2011 5748fb7bfaSmrg are suitable replacements for the non-standard 5848fb7bfaSmrg <code class="classname">hash_map</code> and <code class="classname">hash_set</code> 594fee23f9Smrg containers in the SGI STL. 6048fb7bfaSmrg </p><p> Header files <code class="filename"><hash_map></code> and <code class="filename"><hash_set></code> moved 6148fb7bfaSmrgto <code class="filename"><ext/hash_map></code> and <code class="filename"><ext/hash_set></code>, 624fee23f9Smrgrespectively. At the same time, all types in these files are enclosed 6348fb7bfaSmrgin <code class="code">namespace __gnu_cxx</code>. Later versions deprecate 6448fb7bfaSmrgthese files, and suggest using TR1's <code class="filename"><unordered_map></code> 6548fb7bfaSmrgand <code class="filename"><unordered_set></code> instead. 664fee23f9Smrg</p><p>The extensions are no longer in the global or <code class="code">std</code> 674fee23f9Smrg namespaces, instead they are declared in the <code class="code">__gnu_cxx</code> 684fee23f9Smrg namespace. For maximum portability, consider defining a namespace 694fee23f9Smrg alias to use to talk about extensions, e.g.: 704fee23f9Smrg </p><pre class="programlisting"> 714fee23f9Smrg #ifdef __GNUC__ 724fee23f9Smrg #if __GNUC__ < 3 734fee23f9Smrg #include <hash_map.h> 744fee23f9Smrg namespace extension { using ::hash_map; }; // inherit globals 754fee23f9Smrg #else 764fee23f9Smrg #include <backward/hash_map> 774fee23f9Smrg #if __GNUC__ == 3 && __GNUC_MINOR__ == 0 784fee23f9Smrg namespace extension = std; // GCC 3.0 794fee23f9Smrg #else 804fee23f9Smrg namespace extension = ::__gnu_cxx; // GCC 3.1 and later 814fee23f9Smrg #endif 824fee23f9Smrg #endif 834fee23f9Smrg #else // ... there are other compilers, right? 844fee23f9Smrg namespace extension = std; 854fee23f9Smrg #endif 864fee23f9Smrg 874fee23f9Smrg extension::hash_map<int,int> my_map; 884fee23f9Smrg </pre><p>This is a bit cleaner than defining typedefs for all the 894fee23f9Smrg instantiations you might need. 904fee23f9Smrg </p><p>The following autoconf tests check for working HP/SGI hash containers. 914fee23f9Smrg</p><pre class="programlisting"> 924fee23f9Smrg# AC_HEADER_EXT_HASH_MAP 934fee23f9SmrgAC_DEFUN([AC_HEADER_EXT_HASH_MAP], [ 944fee23f9Smrg AC_CACHE_CHECK(for ext/hash_map, 954fee23f9Smrg ac_cv_cxx_ext_hash_map, 964fee23f9Smrg [AC_LANG_SAVE 974fee23f9Smrg AC_LANG_CPLUSPLUS 984fee23f9Smrg ac_save_CXXFLAGS="$CXXFLAGS" 994fee23f9Smrg CXXFLAGS="$CXXFLAGS -Werror" 1004fee23f9Smrg AC_TRY_COMPILE([#include <ext/hash_map>], [using __gnu_cxx::hash_map;], 1014fee23f9Smrg ac_cv_cxx_ext_hash_map=yes, ac_cv_cxx_ext_hash_map=no) 1024fee23f9Smrg CXXFLAGS="$ac_save_CXXFLAGS" 1034fee23f9Smrg AC_LANG_RESTORE 1044fee23f9Smrg ]) 1054fee23f9Smrg if test "$ac_cv_cxx_ext_hash_map" = yes; then 1064fee23f9Smrg AC_DEFINE(HAVE_EXT_HASH_MAP,,[Define if ext/hash_map is present. ]) 1074fee23f9Smrg fi 1084fee23f9Smrg]) 1094fee23f9Smrg</pre><pre class="programlisting"> 1104fee23f9Smrg# AC_HEADER_EXT_HASH_SET 1114fee23f9SmrgAC_DEFUN([AC_HEADER_EXT_HASH_SET], [ 1124fee23f9Smrg AC_CACHE_CHECK(for ext/hash_set, 1134fee23f9Smrg ac_cv_cxx_ext_hash_set, 1144fee23f9Smrg [AC_LANG_SAVE 1154fee23f9Smrg AC_LANG_CPLUSPLUS 1164fee23f9Smrg ac_save_CXXFLAGS="$CXXFLAGS" 1174fee23f9Smrg CXXFLAGS="$CXXFLAGS -Werror" 1184fee23f9Smrg AC_TRY_COMPILE([#include <ext/hash_set>], [using __gnu_cxx::hash_set;], 1194fee23f9Smrg ac_cv_cxx_ext_hash_set=yes, ac_cv_cxx_ext_hash_set=no) 1204fee23f9Smrg CXXFLAGS="$ac_save_CXXFLAGS" 1214fee23f9Smrg AC_LANG_RESTORE 1224fee23f9Smrg ]) 1234fee23f9Smrg if test "$ac_cv_cxx_ext_hash_set" = yes; then 1244fee23f9Smrg AC_DEFINE(HAVE_EXT_HASH_SET,,[Define if ext/hash_set is present. ]) 1254fee23f9Smrg fi 1264fee23f9Smrg]) 12748fb7bfaSmrg</pre></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.third.nocreate_noreplace"></a>No <code class="code">ios::nocreate/ios::noreplace</code>. 1284d5abbe8Smrg</h4></div></div></div><p>Historically these flags were used with iostreams to control whether 1294d5abbe8Smrgnew files are created or not when opening a file stream, similar to the 1304d5abbe8Smrg<code class="code">O_CREAT</code> and <code class="code">O_EXCL</code> flags for the 1314d5abbe8Smrg<code class="function">open(2)</code> system call. Because iostream modes correspond 1324d5abbe8Smrgto <code class="function">fopen(3)</code> modes these flags are not supported. 1334d5abbe8SmrgFor input streams a new file will not be created anyway, so 1344d5abbe8Smrg<code class="code">ios::nocreate</code> is not needed. 1354d5abbe8SmrgFor output streams, a new file will be created if it does not exist, which is 1364d5abbe8Smrgconsistent with the behaviour of <code class="function">fopen</code>. 1374d5abbe8Smrg</p><p>When one of these flags is needed a possible alternative is to attempt 1384d5abbe8Smrgto open the file using <span class="type">std::ifstream</span> first to determine whether 1394d5abbe8Smrgthe file already exists or not. This may not be reliable however, because 1404d5abbe8Smrgwhether the file exists or not could change between opening the 1414d5abbe8Smrg<span class="type">std::istream</span> and re-opening with an output stream. If you need 1424d5abbe8Smrgto check for existence and open a file as a single operation then you will 1434d5abbe8Smrgneed to use OS-specific facilities outside the C++ standard library, such 1444d5abbe8Smrgas <code class="function">open(2)</code>. 14548fb7bfaSmrg</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.third.streamattach"></a> 1464fee23f9SmrgNo <code class="code">stream::attach(int fd)</code> 1474fee23f9Smrg</h4></div></div></div><p> 1484fee23f9Smrg Phil Edwards writes: It was considered and rejected for the ISO 1494fee23f9Smrg standard. Not all environments use file descriptors. Of those 1504fee23f9Smrg that do, not all of them use integers to represent them. 1514fee23f9Smrg </p><p> 1524fee23f9Smrg For a portable solution (among systems which use 1534fee23f9Smrg file descriptors), you need to implement a subclass of 1544fee23f9Smrg <code class="code">std::streambuf</code> (or 1554fee23f9Smrg <code class="code">std::basic_streambuf<..></code>) which opens a file 1564fee23f9Smrg given a descriptor, and then pass an instance of this to the 1574fee23f9Smrg stream-constructor. 1584fee23f9Smrg </p><p> 1594fee23f9Smrg An extension is available that implements this. 160181254a7Smrg <code class="filename"><ext/stdio_filebuf.h></code> 161181254a7Smrg contains a derived class called 162181254a7Smrg <code class="classname">__gnu_cxx::stdio_filebuf</code>. 1634fee23f9Smrg This class can be constructed from a C <code class="code">FILE*</code> or a file 1644fee23f9Smrg descriptor, and provides the <code class="code">fd()</code> function. 1654fee23f9Smrg </p><p> 1664fee23f9Smrg For another example of this, refer to 16748fb7bfaSmrg <a class="link" href="http://www.josuttis.com/cppcode/fdstream.html" target="_top">fdstream example</a> 1684fee23f9Smrg by Nicolai Josuttis. 16948fb7bfaSmrg</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.third.support_cxx98"></a> 1704fee23f9SmrgSupport for C++98 dialect. 1714fee23f9Smrg</h4></div></div></div><p>Check for complete library coverage of the C++1998/2003 standard. 1724fee23f9Smrg</p><pre class="programlisting"> 1734fee23f9Smrg# AC_HEADER_STDCXX_98 1744fee23f9SmrgAC_DEFUN([AC_HEADER_STDCXX_98], [ 1754fee23f9Smrg AC_CACHE_CHECK(for ISO C++ 98 include files, 1764fee23f9Smrg ac_cv_cxx_stdcxx_98, 1774fee23f9Smrg [AC_LANG_SAVE 1784fee23f9Smrg AC_LANG_CPLUSPLUS 1794fee23f9Smrg AC_TRY_COMPILE([ 1804fee23f9Smrg #include <cassert> 1814fee23f9Smrg #include <cctype> 1824fee23f9Smrg #include <cerrno> 1834fee23f9Smrg #include <cfloat> 1844fee23f9Smrg #include <ciso646> 1854fee23f9Smrg #include <climits> 1864fee23f9Smrg #include <clocale> 1874fee23f9Smrg #include <cmath> 1884fee23f9Smrg #include <csetjmp> 1894fee23f9Smrg #include <csignal> 1904fee23f9Smrg #include <cstdarg> 1914fee23f9Smrg #include <cstddef> 1924fee23f9Smrg #include <cstdio> 1934fee23f9Smrg #include <cstdlib> 1944fee23f9Smrg #include <cstring> 1954fee23f9Smrg #include <ctime> 1964fee23f9Smrg 1974fee23f9Smrg #include <algorithm> 1984fee23f9Smrg #include <bitset> 1994fee23f9Smrg #include <complex> 2004fee23f9Smrg #include <deque> 2014fee23f9Smrg #include <exception> 2024fee23f9Smrg #include <fstream> 2034fee23f9Smrg #include <functional> 2044fee23f9Smrg #include <iomanip> 2054fee23f9Smrg #include <ios> 2064fee23f9Smrg #include <iosfwd> 2074fee23f9Smrg #include <iostream> 2084fee23f9Smrg #include <istream> 2094fee23f9Smrg #include <iterator> 2104fee23f9Smrg #include <limits> 2114fee23f9Smrg #include <list> 2124fee23f9Smrg #include <locale> 2134fee23f9Smrg #include <map> 2144fee23f9Smrg #include <memory> 2154fee23f9Smrg #include <new> 2164fee23f9Smrg #include <numeric> 2174fee23f9Smrg #include <ostream> 2184fee23f9Smrg #include <queue> 2194fee23f9Smrg #include <set> 2204fee23f9Smrg #include <sstream> 2214fee23f9Smrg #include <stack> 2224fee23f9Smrg #include <stdexcept> 2234fee23f9Smrg #include <streambuf> 2244fee23f9Smrg #include <string> 2254fee23f9Smrg #include <typeinfo> 2264fee23f9Smrg #include <utility> 2274fee23f9Smrg #include <valarray> 2284fee23f9Smrg #include <vector> 2294fee23f9Smrg ],, 2304fee23f9Smrg ac_cv_cxx_stdcxx_98=yes, ac_cv_cxx_stdcxx_98=no) 2314fee23f9Smrg AC_LANG_RESTORE 2324fee23f9Smrg ]) 2334fee23f9Smrg if test "$ac_cv_cxx_stdcxx_98" = yes; then 2344fee23f9Smrg AC_DEFINE(STDCXX_98_HEADERS,,[Define if ISO C++ 1998 header files are present. ]) 2354fee23f9Smrg fi 2364fee23f9Smrg]) 23748fb7bfaSmrg</pre></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.third.support_tr1"></a> 2384fee23f9SmrgSupport for C++TR1 dialect. 2394fee23f9Smrg</h4></div></div></div><p>Check for library coverage of the TR1 standard. 2404fee23f9Smrg</p><pre class="programlisting"> 2414fee23f9Smrg# AC_HEADER_STDCXX_TR1 2424fee23f9SmrgAC_DEFUN([AC_HEADER_STDCXX_TR1], [ 2434fee23f9Smrg AC_CACHE_CHECK(for ISO C++ TR1 include files, 2444fee23f9Smrg ac_cv_cxx_stdcxx_tr1, 2454fee23f9Smrg [AC_LANG_SAVE 2464fee23f9Smrg AC_LANG_CPLUSPLUS 2474fee23f9Smrg AC_TRY_COMPILE([ 2484fee23f9Smrg #include <tr1/array> 2494fee23f9Smrg #include <tr1/ccomplex> 2504fee23f9Smrg #include <tr1/cctype> 2514fee23f9Smrg #include <tr1/cfenv> 2524fee23f9Smrg #include <tr1/cfloat> 2534fee23f9Smrg #include <tr1/cinttypes> 2544fee23f9Smrg #include <tr1/climits> 2554fee23f9Smrg #include <tr1/cmath> 2564fee23f9Smrg #include <tr1/complex> 2574fee23f9Smrg #include <tr1/cstdarg> 2584fee23f9Smrg #include <tr1/cstdbool> 2594fee23f9Smrg #include <tr1/cstdint> 2604fee23f9Smrg #include <tr1/cstdio> 2614fee23f9Smrg #include <tr1/cstdlib> 2624fee23f9Smrg #include <tr1/ctgmath> 2634fee23f9Smrg #include <tr1/ctime> 2644fee23f9Smrg #include <tr1/cwchar> 2654fee23f9Smrg #include <tr1/cwctype> 2664fee23f9Smrg #include <tr1/functional> 2674fee23f9Smrg #include <tr1/memory> 2684fee23f9Smrg #include <tr1/random> 2694fee23f9Smrg #include <tr1/regex> 2704fee23f9Smrg #include <tr1/tuple> 2714fee23f9Smrg #include <tr1/type_traits> 2724fee23f9Smrg #include <tr1/unordered_set> 2734fee23f9Smrg #include <tr1/unordered_map> 2744fee23f9Smrg #include <tr1/utility> 2754fee23f9Smrg ],, 2764fee23f9Smrg ac_cv_cxx_stdcxx_tr1=yes, ac_cv_cxx_stdcxx_tr1=no) 2774fee23f9Smrg AC_LANG_RESTORE 2784fee23f9Smrg ]) 2794fee23f9Smrg if test "$ac_cv_cxx_stdcxx_tr1" = yes; then 2804fee23f9Smrg AC_DEFINE(STDCXX_TR1_HEADERS,,[Define if ISO C++ TR1 header files are present. ]) 2814fee23f9Smrg fi 2824fee23f9Smrg]) 2834fee23f9Smrg</pre><p>An alternative is to check just for specific TR1 includes, such as <unordered_map> and <unordered_set>. 2844fee23f9Smrg</p><pre class="programlisting"> 2854fee23f9Smrg# AC_HEADER_TR1_UNORDERED_MAP 2864fee23f9SmrgAC_DEFUN([AC_HEADER_TR1_UNORDERED_MAP], [ 2874fee23f9Smrg AC_CACHE_CHECK(for tr1/unordered_map, 2884fee23f9Smrg ac_cv_cxx_tr1_unordered_map, 2894fee23f9Smrg [AC_LANG_SAVE 2904fee23f9Smrg AC_LANG_CPLUSPLUS 2914fee23f9Smrg AC_TRY_COMPILE([#include <tr1/unordered_map>], [using std::tr1::unordered_map;], 2924fee23f9Smrg ac_cv_cxx_tr1_unordered_map=yes, ac_cv_cxx_tr1_unordered_map=no) 2934fee23f9Smrg AC_LANG_RESTORE 2944fee23f9Smrg ]) 2954fee23f9Smrg if test "$ac_cv_cxx_tr1_unordered_map" = yes; then 2964fee23f9Smrg AC_DEFINE(HAVE_TR1_UNORDERED_MAP,,[Define if tr1/unordered_map is present. ]) 2974fee23f9Smrg fi 2984fee23f9Smrg]) 2994fee23f9Smrg</pre><pre class="programlisting"> 3004fee23f9Smrg# AC_HEADER_TR1_UNORDERED_SET 3014fee23f9SmrgAC_DEFUN([AC_HEADER_TR1_UNORDERED_SET], [ 3024fee23f9Smrg AC_CACHE_CHECK(for tr1/unordered_set, 3034fee23f9Smrg ac_cv_cxx_tr1_unordered_set, 3044fee23f9Smrg [AC_LANG_SAVE 3054fee23f9Smrg AC_LANG_CPLUSPLUS 3064fee23f9Smrg AC_TRY_COMPILE([#include <tr1/unordered_set>], [using std::tr1::unordered_set;], 3074fee23f9Smrg ac_cv_cxx_tr1_unordered_set=yes, ac_cv_cxx_tr1_unordered_set=no) 3084fee23f9Smrg AC_LANG_RESTORE 3094fee23f9Smrg ]) 3104fee23f9Smrg if test "$ac_cv_cxx_tr1_unordered_set" = yes; then 3114fee23f9Smrg AC_DEFINE(HAVE_TR1_UNORDERED_SET,,[Define if tr1/unordered_set is present. ]) 3124fee23f9Smrg fi 3134fee23f9Smrg]) 31448fb7bfaSmrg</pre></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.third.support_cxx11"></a> 31548fb7bfaSmrgSupport for C++11 dialect. 31648fb7bfaSmrg</h4></div></div></div><p>Check for baseline language coverage in the compiler for the C++11 standard. 3174fee23f9Smrg</p><pre class="programlisting"> 31848fb7bfaSmrg# AC_COMPILE_STDCXX_11 31948fb7bfaSmrgAC_DEFUN([AC_COMPILE_STDCXX_11], [ 32048fb7bfaSmrg AC_CACHE_CHECK(if g++ supports C++11 features without additional flags, 32148fb7bfaSmrg ac_cv_cxx_compile_cxx11_native, 3224fee23f9Smrg [AC_LANG_SAVE 3234fee23f9Smrg AC_LANG_CPLUSPLUS 3244fee23f9Smrg AC_TRY_COMPILE([ 3254fee23f9Smrg template <typename T> 32648fb7bfaSmrg struct check final 3274fee23f9Smrg { 32848fb7bfaSmrg static constexpr T value{ __cplusplus }; 3294fee23f9Smrg }; 3304fee23f9Smrg 3314fee23f9Smrg typedef check<check<bool>> right_angle_brackets; 3324fee23f9Smrg 3334fee23f9Smrg int a; 3344fee23f9Smrg decltype(a) b; 3354fee23f9Smrg 3364fee23f9Smrg typedef check<int> check_type; 33748fb7bfaSmrg check_type c{}; 33848fb7bfaSmrg check_type&& cr = static_cast<check_type&&>(c); 33948fb7bfaSmrg 34048fb7bfaSmrg static_assert(check_type::value == 201103L, "C++11 compiler");],, 34148fb7bfaSmrg ac_cv_cxx_compile_cxx11_native=yes, ac_cv_cxx_compile_cxx11_native=no) 3424fee23f9Smrg AC_LANG_RESTORE 3434fee23f9Smrg ]) 3444fee23f9Smrg 34548fb7bfaSmrg AC_CACHE_CHECK(if g++ supports C++11 features with -std=c++11, 34648fb7bfaSmrg ac_cv_cxx_compile_cxx11_cxx, 3474fee23f9Smrg [AC_LANG_SAVE 3484fee23f9Smrg AC_LANG_CPLUSPLUS 3494fee23f9Smrg ac_save_CXXFLAGS="$CXXFLAGS" 35048fb7bfaSmrg CXXFLAGS="$CXXFLAGS -std=c++11" 3514fee23f9Smrg AC_TRY_COMPILE([ 3524fee23f9Smrg template <typename T> 35348fb7bfaSmrg struct check final 3544fee23f9Smrg { 35548fb7bfaSmrg static constexpr T value{ __cplusplus }; 3564fee23f9Smrg }; 3574fee23f9Smrg 3584fee23f9Smrg typedef check<check<bool>> right_angle_brackets; 3594fee23f9Smrg 3604fee23f9Smrg int a; 3614fee23f9Smrg decltype(a) b; 3624fee23f9Smrg 3634fee23f9Smrg typedef check<int> check_type; 36448fb7bfaSmrg check_type c{}; 36548fb7bfaSmrg check_type&& cr = static_cast<check_type&&>(c); 36648fb7bfaSmrg 36748fb7bfaSmrg static_assert(check_type::value == 201103L, "C++11 compiler");],, 36848fb7bfaSmrg ac_cv_cxx_compile_cxx11_cxx=yes, ac_cv_cxx_compile_cxx11_cxx=no) 3694fee23f9Smrg CXXFLAGS="$ac_save_CXXFLAGS" 3704fee23f9Smrg AC_LANG_RESTORE 3714fee23f9Smrg ]) 3724fee23f9Smrg 37348fb7bfaSmrg AC_CACHE_CHECK(if g++ supports C++11 features with -std=gnu++11, 37448fb7bfaSmrg ac_cv_cxx_compile_cxx11_gxx, 3754fee23f9Smrg [AC_LANG_SAVE 3764fee23f9Smrg AC_LANG_CPLUSPLUS 3774fee23f9Smrg ac_save_CXXFLAGS="$CXXFLAGS" 37848fb7bfaSmrg CXXFLAGS="$CXXFLAGS -std=gnu++11" 3794fee23f9Smrg AC_TRY_COMPILE([ 3804fee23f9Smrg template <typename T> 38148fb7bfaSmrg struct check final 3824fee23f9Smrg { 38348fb7bfaSmrg static constexpr T value{ __cplusplus }; 3844fee23f9Smrg }; 3854fee23f9Smrg 3864fee23f9Smrg typedef check<check<bool>> right_angle_brackets; 3874fee23f9Smrg 3884fee23f9Smrg int a; 3894fee23f9Smrg decltype(a) b; 3904fee23f9Smrg 3914fee23f9Smrg typedef check<int> check_type; 39248fb7bfaSmrg check_type c{}; 39348fb7bfaSmrg check_type&& cr = static_cast<check_type&&>(c); 39448fb7bfaSmrg 39548fb7bfaSmrg static_assert(check_type::value == 201103L, "C++11 compiler");],, 39648fb7bfaSmrg ac_cv_cxx_compile_cxx11_gxx=yes, ac_cv_cxx_compile_cxx11_gxx=no) 3974fee23f9Smrg CXXFLAGS="$ac_save_CXXFLAGS" 3984fee23f9Smrg AC_LANG_RESTORE 3994fee23f9Smrg ]) 4004fee23f9Smrg 40148fb7bfaSmrg if test "$ac_cv_cxx_compile_cxx11_native" = yes || 40248fb7bfaSmrg test "$ac_cv_cxx_compile_cxx11_cxx" = yes || 40348fb7bfaSmrg test "$ac_cv_cxx_compile_cxx11_gxx" = yes; then 40448fb7bfaSmrg AC_DEFINE(HAVE_STDCXX_11,,[Define if g++ supports C++11 features. ]) 4054fee23f9Smrg fi 4064fee23f9Smrg]) 40748fb7bfaSmrg</pre><p>Check for library coverage of the C++2011 standard. 40848fb7bfaSmrg (Some library headers are commented out in this check, they are 40948fb7bfaSmrg not currently provided by libstdc++). 4104fee23f9Smrg</p><pre class="programlisting"> 41148fb7bfaSmrg# AC_HEADER_STDCXX_11 41248fb7bfaSmrgAC_DEFUN([AC_HEADER_STDCXX_11], [ 41348fb7bfaSmrg AC_CACHE_CHECK(for ISO C++11 include files, 41448fb7bfaSmrg ac_cv_cxx_stdcxx_11, 41548fb7bfaSmrg [AC_REQUIRE([AC_COMPILE_STDCXX_11]) 4164fee23f9Smrg AC_LANG_SAVE 4174fee23f9Smrg AC_LANG_CPLUSPLUS 4184fee23f9Smrg ac_save_CXXFLAGS="$CXXFLAGS" 41948fb7bfaSmrg CXXFLAGS="$CXXFLAGS -std=gnu++11" 4204fee23f9Smrg 4214fee23f9Smrg AC_TRY_COMPILE([ 4224fee23f9Smrg #include <cassert> 4234fee23f9Smrg #include <ccomplex> 4244fee23f9Smrg #include <cctype> 4254fee23f9Smrg #include <cerrno> 4264fee23f9Smrg #include <cfenv> 4274fee23f9Smrg #include <cfloat> 4284fee23f9Smrg #include <cinttypes> 4294fee23f9Smrg #include <ciso646> 4304fee23f9Smrg #include <climits> 4314fee23f9Smrg #include <clocale> 4324fee23f9Smrg #include <cmath> 4334fee23f9Smrg #include <csetjmp> 4344fee23f9Smrg #include <csignal> 43548fb7bfaSmrg #include <cstdalign> 4364fee23f9Smrg #include <cstdarg> 4374fee23f9Smrg #include <cstdbool> 4384fee23f9Smrg #include <cstddef> 4394fee23f9Smrg #include <cstdint> 4404fee23f9Smrg #include <cstdio> 4414fee23f9Smrg #include <cstdlib> 4424fee23f9Smrg #include <cstring> 4434fee23f9Smrg #include <ctgmath> 4444fee23f9Smrg #include <ctime> 44548fb7bfaSmrg // #include <cuchar> 4464fee23f9Smrg #include <cwchar> 4474fee23f9Smrg #include <cwctype> 4484fee23f9Smrg 4494fee23f9Smrg #include <algorithm> 4504fee23f9Smrg #include <array> 45148fb7bfaSmrg #include <atomic> 4524fee23f9Smrg #include <bitset> 45348fb7bfaSmrg #include <chrono> 45448fb7bfaSmrg // #include <codecvt> 4554fee23f9Smrg #include <complex> 45648fb7bfaSmrg #include <condition_variable> 4574fee23f9Smrg #include <deque> 4584fee23f9Smrg #include <exception> 45948fb7bfaSmrg #include <forward_list> 4604fee23f9Smrg #include <fstream> 4614fee23f9Smrg #include <functional> 46248fb7bfaSmrg #include <future> 46348fb7bfaSmrg #include <initializer_list> 4644fee23f9Smrg #include <iomanip> 4654fee23f9Smrg #include <ios> 4664fee23f9Smrg #include <iosfwd> 4674fee23f9Smrg #include <iostream> 4684fee23f9Smrg #include <istream> 4694fee23f9Smrg #include <iterator> 4704fee23f9Smrg #include <limits> 4714fee23f9Smrg #include <list> 4724fee23f9Smrg #include <locale> 4734fee23f9Smrg #include <map> 4744fee23f9Smrg #include <memory> 47548fb7bfaSmrg #include <mutex> 4764fee23f9Smrg #include <new> 4774fee23f9Smrg #include <numeric> 4784fee23f9Smrg #include <ostream> 4794fee23f9Smrg #include <queue> 4804fee23f9Smrg #include <random> 48148fb7bfaSmrg #include <ratio> 4824fee23f9Smrg #include <regex> 48348fb7bfaSmrg #include <scoped_allocator> 4844fee23f9Smrg #include <set> 4854fee23f9Smrg #include <sstream> 4864fee23f9Smrg #include <stack> 4874fee23f9Smrg #include <stdexcept> 4884fee23f9Smrg #include <streambuf> 4894fee23f9Smrg #include <string> 49048fb7bfaSmrg #include <system_error> 49148fb7bfaSmrg #include <thread> 4924fee23f9Smrg #include <tuple> 49348fb7bfaSmrg #include <typeindex> 4944fee23f9Smrg #include <typeinfo> 4954fee23f9Smrg #include <type_traits> 4964fee23f9Smrg #include <unordered_map> 4974fee23f9Smrg #include <unordered_set> 4984fee23f9Smrg #include <utility> 4994fee23f9Smrg #include <valarray> 5004fee23f9Smrg #include <vector> 5014fee23f9Smrg ],, 50248fb7bfaSmrg ac_cv_cxx_stdcxx_11=yes, ac_cv_cxx_stdcxx_11=no) 5034fee23f9Smrg AC_LANG_RESTORE 5044fee23f9Smrg CXXFLAGS="$ac_save_CXXFLAGS" 5054fee23f9Smrg ]) 50648fb7bfaSmrg if test "$ac_cv_cxx_stdcxx_11" = yes; then 50748fb7bfaSmrg AC_DEFINE(STDCXX_11_HEADERS,,[Define if ISO C++11 header files are present. ]) 5084fee23f9Smrg fi 5094fee23f9Smrg]) 51048fb7bfaSmrg</pre><p>As is the case for TR1 support, these autoconf macros can be made for a finer-grained, per-header-file check. For 51148fb7bfaSmrg<code class="filename"><unordered_map></code> 5124fee23f9Smrg</p><pre class="programlisting"> 5134fee23f9Smrg# AC_HEADER_UNORDERED_MAP 5144fee23f9SmrgAC_DEFUN([AC_HEADER_UNORDERED_MAP], [ 5154fee23f9Smrg AC_CACHE_CHECK(for unordered_map, 5164fee23f9Smrg ac_cv_cxx_unordered_map, 51748fb7bfaSmrg [AC_REQUIRE([AC_COMPILE_STDCXX_11]) 5184fee23f9Smrg AC_LANG_SAVE 5194fee23f9Smrg AC_LANG_CPLUSPLUS 5204fee23f9Smrg ac_save_CXXFLAGS="$CXXFLAGS" 52148fb7bfaSmrg CXXFLAGS="$CXXFLAGS -std=gnu++11" 5224fee23f9Smrg AC_TRY_COMPILE([#include <unordered_map>], [using std::unordered_map;], 5234fee23f9Smrg ac_cv_cxx_unordered_map=yes, ac_cv_cxx_unordered_map=no) 5244fee23f9Smrg CXXFLAGS="$ac_save_CXXFLAGS" 5254fee23f9Smrg AC_LANG_RESTORE 5264fee23f9Smrg ]) 5274fee23f9Smrg if test "$ac_cv_cxx_unordered_map" = yes; then 5284fee23f9Smrg AC_DEFINE(HAVE_UNORDERED_MAP,,[Define if unordered_map is present. ]) 5294fee23f9Smrg fi 5304fee23f9Smrg]) 5314fee23f9Smrg</pre><pre class="programlisting"> 5324fee23f9Smrg# AC_HEADER_UNORDERED_SET 5334fee23f9SmrgAC_DEFUN([AC_HEADER_UNORDERED_SET], [ 5344fee23f9Smrg AC_CACHE_CHECK(for unordered_set, 5354fee23f9Smrg ac_cv_cxx_unordered_set, 53648fb7bfaSmrg [AC_REQUIRE([AC_COMPILE_STDCXX_11]) 5374fee23f9Smrg AC_LANG_SAVE 5384fee23f9Smrg AC_LANG_CPLUSPLUS 5394fee23f9Smrg ac_save_CXXFLAGS="$CXXFLAGS" 54048fb7bfaSmrg CXXFLAGS="$CXXFLAGS -std=gnu++11" 5414fee23f9Smrg AC_TRY_COMPILE([#include <unordered_set>], [using std::unordered_set;], 5424fee23f9Smrg ac_cv_cxx_unordered_set=yes, ac_cv_cxx_unordered_set=no) 5434fee23f9Smrg CXXFLAGS="$ac_save_CXXFLAGS" 5444fee23f9Smrg AC_LANG_RESTORE 5454fee23f9Smrg ]) 5464fee23f9Smrg if test "$ac_cv_cxx_unordered_set" = yes; then 5474fee23f9Smrg AC_DEFINE(HAVE_UNORDERED_SET,,[Define if unordered_set is present. ]) 5484fee23f9Smrg fi 5494fee23f9Smrg]) 55048fb7bfaSmrg</pre><p> 55148fb7bfaSmrg Some C++11 features first appeared in GCC 4.3 and could be enabled by 55248fb7bfaSmrg <code class="option">-std=c++0x</code> and <code class="option">-std=gnu++0x</code> for GCC 55348fb7bfaSmrg releases which pre-date the 2011 standard. Those C++11 features and GCC's 55448fb7bfaSmrg support for them were still changing until the 2011 standard was finished, 55548fb7bfaSmrg but the autoconf checks above could be extended to test for incomplete 55648fb7bfaSmrg C++11 support with <code class="option">-std=c++0x</code> and 55748fb7bfaSmrg <code class="option">-std=gnu++0x</code>. 55848fb7bfaSmrg</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.third.iterator_type"></a> 55948fb7bfaSmrg <code class="code">Container::iterator_type</code> is not necessarily <code class="code">Container::value_type*</code> 5604fee23f9Smrg</h4></div></div></div><p> 56148fb7bfaSmrg This is a change in behavior from older versions. Now, most 5624fee23f9Smrg <span class="type">iterator_type</span> typedefs in container classes are POD 5634fee23f9Smrg objects, not <span class="type">value_type</span> pointers. 564*b1e83836Smrg</p></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="api.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="appendix_porting.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="appendix_free.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">API Evolution and Deprecation History </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> Appendix C. 5654fee23f9Smrg Free Software Needs Free Documentation 5664fee23f9Smrg 5674fee23f9Smrg</td></tr></table></div></body></html>