1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!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-NS Stylesheets V1.77.1" /><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.
3 Porting and Maintenance
5 </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
6 separate GNU project, although reliably paired with GCC. Rumors imply
7 that it had a working relationship with at least two kinds of
9 </p><p>Some background: libg++ was designed and created when there was no
10 ISO standard to provide guidance. Classes like linked lists are now
11 provided for by <code class="classname">list<T></code> and do not need to be
12 created by <code class="function">genclass</code>. (For that matter, templates exist
13 now and are well-supported, whereas genclass (mostly) predates them.)
14 </p><p>There are other classes in libg++ that are not specified in the
15 ISO Standard (e.g., statistical analysis). While there are a lot of
16 really useful things that are used by a lot of people, the Standards
17 Committee couldn't include everything, and so a lot of those
18 <span class="quote">“<span class="quote">obvious</span>”</span> classes didn't get included.
19 </p><p>Known Issues include many of the limitations of its immediate ancestor.</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.first.ios_base"></a>No <code class="code">ios_base</code></h4></div></div></div><p> At least some older implementations don't have <code class="code">std::ios_base</code>, so you should use <code class="code">std::ios::badbit</code>, <code class="code">std::ios::failbit</code> and <code class="code">std::ios::eofbit</code> and <code class="code">std::ios::goodbit</code>.
20 </p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.first.cout_cin"></a>No <code class="code">cout</code> in <code class="filename"><ostream.h></code>, no <code class="code">cin</code> in <code class="filename"><istream.h></code></h4></div></div></div><p>
21 In earlier versions of the standard,
22 <code class="filename"><fstream.h></code>,
23 <code class="filename"><ostream.h></code>
24 and <code class="filename"><istream.h></code>
26 <code class="code">cout</code>, <code class="code">cin</code> and so on. ISO C++ specifies that one needs to include
27 <code class="filename"><iostream></code>
28 explicitly to get the required definitions.
29 </p><p> Some include adjustment may be required.</p><p>This project is no longer maintained or supported, and the sources
30 archived. For the desperate,
31 the <a class="link" href="http://gcc.gnu.org/extensions.html" target="_top">GCC extensions
32 page</a> describes where to find the last libg++ source. The code is
33 considered replaced and rewritten.
34 </p></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="backwards.second"></a>Second</h3></div></div></div><p>
35 The second generation GNU C++ library was called libstdc++, or
36 libstdc++-v2. It spans the time between libg++ and pre-ISO C++
37 standardization and is usually associated with the following GCC
38 releases: egcs 1.x, gcc 2.95, and gcc 2.96.
40 The STL portions of this library are based on SGI/HP STL release 3.11.
42 This project is no longer maintained or supported, and the sources
43 archived. The code is considered replaced and rewritten.
45 Portability notes and known implementation limitations are as follows.
46 </p><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.second.std"></a>Namespace <code class="code">std::</code> not supported</h4></div></div></div><p>
47 Some care is required to support C++ compiler and or library
48 implementation that do not have the standard library in
49 <code class="code">namespace std</code>.
51 The following sections list some possible solutions to support compilers
52 that cannot ignore <code class="code">std::</code>-qualified names.
54 First, see if the compiler has a flag for this. Namespace
55 back-portability-issues are generally not a problem for g++
56 compilers that do not have libstdc++ in <code class="code">std::</code>, as the
57 compilers use <code class="option">-fno-honor-std</code> (ignore
58 <code class="code">std::</code>, <code class="code">:: = std::</code>) by default. That is,
59 the responsibility for enabling or disabling <code class="code">std::</code> is
60 on the user; the maintainer does not have to care about it. This
61 probably applies to some other compilers as well.
63 Second, experiment with a variety of pre-processor tricks.
65 By defining <code class="code">std</code> as a macro, fully-qualified namespace
66 calls become global. Volia.
67 </p><pre class="programlisting">
68 #ifdef WICKEDLY_OLD_COMPILER
72 Thanks to Juergen Heinzl who posted this solution on gnu.gcc.help.
74 Another pre-processor based approach is to define a macro
75 <code class="code">NAMESPACE_STD</code>, which is defined to either
76 <span class="quote">“<span class="quote"> </span>”</span> or <span class="quote">“<span class="quote">std</span>”</span> based on a compile-type
77 test. On GNU systems, this can be done with autotools by means of
78 an autoconf test (see below) for <code class="code">HAVE_NAMESPACE_STD</code>,
79 then using that to set a value for the <code class="code">NAMESPACE_STD</code>
80 macro. At that point, one is able to use
81 <code class="code">NAMESPACE_STD::string</code>, which will evaluate to
82 <code class="code">std::string</code> or <code class="code">::string</code> (i.e., in the
83 global namespace on systems that do not put <code class="code">string</code> in
84 <code class="code">std::</code>).
85 </p><pre class="programlisting">
86 dnl @synopsis AC_CXX_NAMESPACE_STD
88 dnl If the compiler supports namespace std, define
89 dnl HAVE_NAMESPACE_STD.
92 dnl @author Todd Veldhuizen
93 dnl @author Luc Maisonobe <luc@spaceroots.org>
94 dnl @version 2004-02-04
95 dnl @license AllPermissive
96 AC_DEFUN([AC_CXX_NAMESPACE_STD], [
97 AC_CACHE_CHECK(if g++ supports namespace std,
98 ac_cv_cxx_have_std_namespace,
101 AC_TRY_COMPILE([#include <iostream>
102 std::istream& is = std::cin;],,
103 ac_cv_cxx_have_std_namespace=yes, ac_cv_cxx_have_std_namespace=no)
106 if test "$ac_cv_cxx_have_std_namespace" = yes; then
107 AC_DEFINE(HAVE_NAMESPACE_STD,,[Define if g++ supports namespace std. ])
110 </pre></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.second.iterators"></a>Illegal iterator usage</h4></div></div></div><p>
111 The following illustrate implementation-allowed illegal iterator
112 use, and then correct use.
113 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
114 you cannot do <code class="code">ostream::operator<<(iterator)</code>
115 to print the address of the iterator => use
116 <code class="code">operator<< &*iterator</code> instead
117 </p></li><li class="listitem"><p>
118 you cannot clear an iterator's reference (<code class="code">iterator =
119 0</code>) => use <code class="code">iterator = iterator_type();</code>
120 </p></li><li class="listitem"><p>
121 <code class="code">if (iterator)</code> won't work any more => use
122 <code class="code">if (iterator != iterator_type())</code>
123 </p></li></ul></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.second.isspace"></a><code class="code">isspace</code> from <code class="filename"><cctype></code> is a macro
124 </h4></div></div></div><p>
125 Glibc 2.0.x and 2.1.x define <code class="filename"><ctype.h></code> functionality as macros
126 (isspace, isalpha etc.).
128 This implementations of libstdc++, however, keep these functions
129 as macros, and so it is not back-portable to use fully qualified
131 </p><pre class="programlisting">
132 #include <cctype>
133 int main() { std::isspace('X'); }
135 Results in something like this:
136 </p><pre class="programlisting">
137 std:: (__ctype_b[(int) ( ( 'X' ) )] & (unsigned short int) _ISspace ) ;
139 A solution is to modify a header-file so that the compiler tells
140 <code class="filename"><ctype.h></code> to define functions
142 </p><pre class="programlisting">
143 // This keeps isalnum, et al from being propagated as macros.
145 # define __NO_CTYPE 1
148 Then, include <code class="filename"><ctype.h></code>
150 Another problem arises if you put a <code class="code">using namespace
151 std;</code> declaration at the top, and include
152 <code class="filename"><ctype.h></code>. This will
153 result in ambiguities between the definitions in the global namespace
154 (<code class="filename"><ctype.h></code>) and the
155 definitions in namespace <code class="code">std::</code>
156 (<code class="code"><cctype></code>).
157 </p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.second.at"></a>No <code class="code">vector::at</code>, <code class="code">deque::at</code>, <code class="code">string::at</code></h4></div></div></div><p>
158 One solution is to add an autoconf-test for this:
159 </p><pre class="programlisting">
160 AC_MSG_CHECKING(for container::at)
163 #include <vector>
164 #include <deque>
165 #include <string>
170 deque<int> test_deque(3);
172 vector<int> test_vector(2);
174 string test_string(<span class="quote">“<span class="quote">test_string</span>”</span>);
178 AC_DEFINE(HAVE_CONTAINER_AT)],
181 If you are using other (non-GNU) compilers it might be a good idea
182 to check for <code class="code">string::at</code> separately.
183 </p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.second.eof"></a>No <code class="code">std::char_traits<char>::eof</code></h4></div></div></div><p>
184 Use some kind of autoconf test, plus this:
185 </p><pre class="programlisting">
186 #ifdef HAVE_CHAR_TRAITS
187 #define CPP_EOF std::char_traits<char>::eof()
191 </pre></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.second.stringclear"></a>No <code class="code">string::clear</code></h4></div></div></div><p>
192 There are two functions for deleting the contents of a string:
193 <code class="code">clear</code> and <code class="code">erase</code> (the latter returns the
195 </p><pre class="programlisting">
197 clear() { _M_mutate(0, this->size(), 0); }
198 </pre><pre class="programlisting">
200 erase(size_type __pos = 0, size_type __n = npos)
202 return this->replace(_M_check(__pos), _M_fold(__pos, __n),
203 _M_data(), _M_data());
206 Unfortunately, <code class="code">clear</code> is not implemented in this
207 version, so you should use <code class="code">erase</code> (which is probably
208 faster than <code class="code">operator=(charT*)</code>).
209 </p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.second.ostreamform_istreamscan"></a>
210 Removal of <code class="code">ostream::form</code> and <code class="code">istream::scan</code>
212 </h4></div></div></div><p>
213 These are no longer supported. Please use stringstreams instead.
214 </p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.second.stringstreams"></a>No <code class="code">basic_stringbuf</code>, <code class="code">basic_stringstream</code></h4></div></div></div><p>
215 Although the ISO standard <code class="code">i/ostringstream</code>-classes are
216 provided, (<code class="filename"><sstream></code>), for
217 compatibility with older implementations the pre-ISO
218 <code class="code">i/ostrstream</code> (<code class="filename"><strstream></code>) interface is also provided,
220 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
221 <code class="code">strstream</code> is considered to be deprecated
222 </p></li><li class="listitem"><p>
223 <code class="code">strstream</code> is limited to <code class="code">char</code>
224 </p></li><li class="listitem"><p>
225 with <code class="code">ostringstream</code> you don't have to take care of
226 terminating the string or freeing its memory
227 </p></li><li class="listitem"><p>
228 <code class="code">istringstream</code> can be re-filled (clear();
230 </p></li></ul></div><p>
231 You can then use output-stringstreams like this:
232 </p><pre class="programlisting">
234 # include <sstream>
236 # include <strstream>
240 std::ostringstream oss;
245 oss << <span class="quote">“<span class="quote">Name=</span>”</span> << m_name << <span class="quote">“<span class="quote">, number=</span>”</span> << m_number << std::endl;
248 oss << std::ends; // terminate the char*-string
251 // str() returns char* for ostrstream and a string for ostringstream
252 // this also causes ostrstream to think that the buffer's memory
254 m_label.set_text(oss.str());
256 // let the ostrstream take care of freeing the memory
260 Input-stringstreams can be used similarly:
261 </p><pre class="programlisting">
265 std::istringstream iss(input);
267 std::istrstream iss(input.c_str());
272 </pre><p> One (the only?) restriction is that an istrstream cannot be re-filled:
273 </p><pre class="programlisting">
274 std::istringstream iss(numerator);
276 // this is not possible with istrstream
278 iss.str(denominator);
281 If you don't care about speed, you can put these conversions in
283 </p><pre class="programlisting">
284 template <class X>
285 void fromString(const string& input, X& any)
288 std::istringstream iss(input);
290 std::istrstream iss(input.c_str());
295 throw runtime_error(..)
299 Another example of using stringstreams is in <a class="link" href="strings.html#strings.string.shrink" title="Shrink to Fit">this howto</a>.
300 </p><p> There is additional information in the libstdc++-v2 info files, in
301 particular <span class="quote">“<span class="quote">info iostream</span>”</span>.
302 </p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.second.wchar"></a>Little or no wide character support</h4></div></div></div><p>
303 Classes <code class="classname">wstring</code> and
304 <code class="classname">char_traits<wchar_t></code> are
306 </p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.second.iostream_templates"></a>No templatized iostreams</h4></div></div></div><p>
307 Classes <code class="classname">wfilebuf</code> and
308 <code class="classname">wstringstream</code> are not supported.
309 </p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.second.thread_safety"></a>Thread safety issues</h4></div></div></div><p>
310 Earlier GCC releases had a somewhat different approach to
311 threading configuration and proper compilation. Before GCC 3.0,
312 configuration of the threading model was dictated by compiler
313 command-line options and macros (both of which were somewhat
314 thread-implementation and port-specific). There were no
315 guarantees related to being able to link code compiled with one
316 set of options and macro setting with another set.
318 For GCC 3.0, configuration of the threading model used with
319 libraries and user-code is performed when GCC is configured and
320 built using the --enable-threads and --disable-threads options.
321 The ABI is stable for symbol name-mangling and limited functional
322 compatibility exists between code compiled under different
325 The libstdc++ library has been designed so that it can be used in
326 multithreaded applications (with libstdc++-v2 this was only true
327 of the STL parts.) The first problem is finding a
328 <span class="emphasis"><em>fast</em></span> method of implementation portable to
329 all platforms. Due to historical reasons, some of the library is
330 written against per-CPU-architecture spinlocks and other parts
331 against the gthr.h abstraction layer which is provided by gcc. A
332 minor problem that pops up every so often is different
333 interpretations of what "thread-safe" means for a
334 library (not a general program). We currently use the <a class="link" href="http://www.sgi.com/tech/stl/thread_safety.html" target="_top">same
335 definition that SGI</a> uses for their STL subset. However,
336 the exception for read-only containers only applies to the STL
337 components. This definition is widely-used and something similar
338 will be used in the next version of the C++ standard library.
340 Here is a small link farm to threads (no pun) in the mail
341 archives that discuss the threading problem. Each link is to the
342 first relevant message in the thread; from there you can use
343 "Thread Next" to move down the thread. This farm is in
344 latest-to-oldest order.
345 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
346 Our threading expert Loren gives a breakdown of <a class="link" href="http://gcc.gnu.org/ml/libstdc++/2001-10/msg00024.html" target="_top">the
347 six situations involving threads</a> for the 3.0
349 </p></li><li class="listitem"><p>
350 <a class="link" href="http://gcc.gnu.org/ml/libstdc++/2001-05/msg00384.html" target="_top">
351 This message</a> inspired a recent updating of issues with
352 threading and the SGI STL library. It also contains some
353 example POSIX-multithreaded STL code.
354 </p></li></ul></div><p>
355 (A large selection of links to older messages has been removed;
356 many of the messages from 1999 were lost in a disk crash, and the
357 few people with access to the backup tapes have been too swamped
358 with work to restore them. Many of the points have been
360 </p></div></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
362 </p><p>The subset commonly known as the Standard Template Library
363 (chapters 23 through 25, mostly) is adapted from the final release
364 of the SGI STL (version 3.3), with extensive changes.
365 </p><p>A more formal description of the V3 goals can be found in the
366 official <a class="link" href="source_design_notes.html" title="Design Notes">design document</a>.
367 </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 moved to backwards or removed</h4></div></div></div><p> The pre-ISO C++ headers
368 (<code class="filename"><iostream.h></code>,
369 <code class="filename"><defalloc.h></code> etc.) are
370 available, unlike previous libstdc++ versions, but inclusion
371 generates a warning that you are using deprecated headers.
372 </p><p>This compatibility layer is constructed by including the
373 standard C++ headers, and injecting any items in
374 <code class="code">std::</code> into the global namespace.
375 </p><p>For those of you new to ISO C++ (welcome, time travelers!), no,
376 that isn't a typo. Yes, the headers really have new names.
377 Marshall Cline's C++ FAQ Lite has a good explanation in <a class="link" href="http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4" target="_top">item
379 </p><p> Some include adjustment may be required. What follows is an
380 autoconf test that defines <code class="code">PRE_STDCXX_HEADERS</code> when they
381 exist.</p><pre class="programlisting">
382 # AC_HEADER_PRE_STDCXX
383 AC_DEFUN([AC_HEADER_PRE_STDCXX], [
384 AC_CACHE_CHECK(for pre-ISO C++ include files,
385 ac_cv_cxx_pre_stdcxx,
388 ac_save_CXXFLAGS="$CXXFLAGS"
389 CXXFLAGS="$CXXFLAGS -Wno-deprecated"
391 # Omit defalloc.h, as compilation with newer compilers is problematic.
393 #include <new.h>
394 #include <iterator.h>
395 #include <alloc.h>
396 #include <set.h>
397 #include <hashtable.h>
398 #include <hash_set.h>
399 #include <fstream.h>
400 #include <tempbuf.h>
401 #include <istream.h>
402 #include <bvector.h>
403 #include <stack.h>
404 #include <rope.h>
405 #include <complex.h>
406 #include <ostream.h>
407 #include <heap.h>
408 #include <iostream.h>
409 #include <function.h>
410 #include <multimap.h>
411 #include <pair.h>
412 #include <stream.h>
413 #include <iomanip.h>
414 #include <slist.h>
415 #include <tree.h>
416 #include <vector.h>
417 #include <deque.h>
418 #include <multiset.h>
419 #include <list.h>
420 #include <map.h>
421 #include <algobase.h>
422 #include <hash_map.h>
423 #include <algo.h>
424 #include <queue.h>
425 #include <streambuf.h>
427 ac_cv_cxx_pre_stdcxx=yes, ac_cv_cxx_pre_stdcxx=no)
428 CXXFLAGS="$ac_save_CXXFLAGS"
431 if test "$ac_cv_cxx_pre_stdcxx" = yes; then
432 AC_DEFINE(PRE_STDCXX_HEADERS,,[Define if pre-ISO C++ header files are present. ])
435 </pre><p>Porting between pre-ISO headers and ISO headers is simple: headers
436 like <code class="filename"><vector.h></code> can be replaced with <code class="filename"><vector></code> and a using
437 directive <code class="code">using namespace std;</code> can be put at the global
438 scope. This should be enough to get this code compiling, assuming the
439 other usage is correct.
440 </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
441 replaced by standardized libraries.
442 In particular, the <code class="classname">unordered_map</code> and
443 <code class="classname">unordered_set</code> containers of TR1 and C++ 2011
444 are suitable replacements for the non-standard
445 <code class="classname">hash_map</code> and <code class="classname">hash_set</code>
446 containers in the SGI STL.
447 </p><p> Header files <code class="filename"><hash_map></code> and <code class="filename"><hash_set></code> moved
448 to <code class="filename"><ext/hash_map></code> and <code class="filename"><ext/hash_set></code>,
449 respectively. At the same time, all types in these files are enclosed
450 in <code class="code">namespace __gnu_cxx</code>. Later versions deprecate
451 these files, and suggest using TR1's <code class="filename"><unordered_map></code>
452 and <code class="filename"><unordered_set></code> instead.
453 </p><p>The extensions are no longer in the global or <code class="code">std</code>
454 namespaces, instead they are declared in the <code class="code">__gnu_cxx</code>
455 namespace. For maximum portability, consider defining a namespace
456 alias to use to talk about extensions, e.g.:
457 </p><pre class="programlisting">
460 #include <hash_map.h>
461 namespace extension { using ::hash_map; }; // inherit globals
463 #include <backward/hash_map>
464 #if __GNUC__ == 3 && __GNUC_MINOR__ == 0
465 namespace extension = std; // GCC 3.0
467 namespace extension = ::__gnu_cxx; // GCC 3.1 and later
470 #else // ... there are other compilers, right?
471 namespace extension = std;
474 extension::hash_map<int,int> my_map;
475 </pre><p>This is a bit cleaner than defining typedefs for all the
476 instantiations you might need.
477 </p><p>The following autoconf tests check for working HP/SGI hash containers.
478 </p><pre class="programlisting">
479 # AC_HEADER_EXT_HASH_MAP
480 AC_DEFUN([AC_HEADER_EXT_HASH_MAP], [
481 AC_CACHE_CHECK(for ext/hash_map,
482 ac_cv_cxx_ext_hash_map,
485 ac_save_CXXFLAGS="$CXXFLAGS"
486 CXXFLAGS="$CXXFLAGS -Werror"
487 AC_TRY_COMPILE([#include <ext/hash_map>], [using __gnu_cxx::hash_map;],
488 ac_cv_cxx_ext_hash_map=yes, ac_cv_cxx_ext_hash_map=no)
489 CXXFLAGS="$ac_save_CXXFLAGS"
492 if test "$ac_cv_cxx_ext_hash_map" = yes; then
493 AC_DEFINE(HAVE_EXT_HASH_MAP,,[Define if ext/hash_map is present. ])
496 </pre><pre class="programlisting">
497 # AC_HEADER_EXT_HASH_SET
498 AC_DEFUN([AC_HEADER_EXT_HASH_SET], [
499 AC_CACHE_CHECK(for ext/hash_set,
500 ac_cv_cxx_ext_hash_set,
503 ac_save_CXXFLAGS="$CXXFLAGS"
504 CXXFLAGS="$CXXFLAGS -Werror"
505 AC_TRY_COMPILE([#include <ext/hash_set>], [using __gnu_cxx::hash_set;],
506 ac_cv_cxx_ext_hash_set=yes, ac_cv_cxx_ext_hash_set=no)
507 CXXFLAGS="$ac_save_CXXFLAGS"
510 if test "$ac_cv_cxx_ext_hash_set" = yes; then
511 AC_DEFINE(HAVE_EXT_HASH_SET,,[Define if ext/hash_set is present. ])
514 </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>.
515 </h4></div></div></div><p> The existence of <code class="code">ios::nocreate</code> being used for
516 input-streams has been confirmed, most probably because the author
517 thought it would be more correct to specify nocreate explicitly. So
518 it can be left out for input-streams.
519 </p><p>For output streams, <span class="quote">“<span class="quote">nocreate</span>”</span> is probably the default,
520 unless you specify <code class="code">std::ios::trunc</code> ? To be safe, you can
521 open the file for reading, check if it has been opened, and then
522 decide whether you want to create/replace or not. To my knowledge,
523 even older implementations support <code class="code">app</code>, <code class="code">ate</code>
524 and <code class="code">trunc</code> (except for <code class="code">app</code> ?).
525 </p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.third.streamattach"></a>
526 No <code class="code">stream::attach(int fd)</code>
527 </h4></div></div></div><p>
528 Phil Edwards writes: It was considered and rejected for the ISO
529 standard. Not all environments use file descriptors. Of those
530 that do, not all of them use integers to represent them.
532 For a portable solution (among systems which use
533 file descriptors), you need to implement a subclass of
534 <code class="code">std::streambuf</code> (or
535 <code class="code">std::basic_streambuf<..></code>) which opens a file
536 given a descriptor, and then pass an instance of this to the
539 An extension is available that implements this.
540 <code class="filename"><ext/stdio_filebuf.h></code> contains a derived class called
541 <a class="link" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00074.html" target="_top"><code class="code">__gnu_cxx::stdio_filebuf</code></a>.
542 This class can be constructed from a C <code class="code">FILE*</code> or a file
543 descriptor, and provides the <code class="code">fd()</code> function.
545 For another example of this, refer to
546 <a class="link" href="http://www.josuttis.com/cppcode/fdstream.html" target="_top">fdstream example</a>
548 </p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.third.support_cxx98"></a>
549 Support for C++98 dialect.
550 </h4></div></div></div><p>Check for complete library coverage of the C++1998/2003 standard.
551 </p><pre class="programlisting">
552 # AC_HEADER_STDCXX_98
553 AC_DEFUN([AC_HEADER_STDCXX_98], [
554 AC_CACHE_CHECK(for ISO C++ 98 include files,
559 #include <cassert>
560 #include <cctype>
561 #include <cerrno>
562 #include <cfloat>
563 #include <ciso646>
564 #include <climits>
565 #include <clocale>
566 #include <cmath>
567 #include <csetjmp>
568 #include <csignal>
569 #include <cstdarg>
570 #include <cstddef>
571 #include <cstdio>
572 #include <cstdlib>
573 #include <cstring>
574 #include <ctime>
576 #include <algorithm>
577 #include <bitset>
578 #include <complex>
579 #include <deque>
580 #include <exception>
581 #include <fstream>
582 #include <functional>
583 #include <iomanip>
585 #include <iosfwd>
586 #include <iostream>
587 #include <istream>
588 #include <iterator>
589 #include <limits>
590 #include <list>
591 #include <locale>
593 #include <memory>
595 #include <numeric>
596 #include <ostream>
597 #include <queue>
599 #include <sstream>
600 #include <stack>
601 #include <stdexcept>
602 #include <streambuf>
603 #include <string>
604 #include <typeinfo>
605 #include <utility>
606 #include <valarray>
607 #include <vector>
609 ac_cv_cxx_stdcxx_98=yes, ac_cv_cxx_stdcxx_98=no)
612 if test "$ac_cv_cxx_stdcxx_98" = yes; then
613 AC_DEFINE(STDCXX_98_HEADERS,,[Define if ISO C++ 1998 header files are present. ])
616 </pre></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.third.support_tr1"></a>
617 Support for C++TR1 dialect.
618 </h4></div></div></div><p>Check for library coverage of the TR1 standard.
619 </p><pre class="programlisting">
620 # AC_HEADER_STDCXX_TR1
621 AC_DEFUN([AC_HEADER_STDCXX_TR1], [
622 AC_CACHE_CHECK(for ISO C++ TR1 include files,
623 ac_cv_cxx_stdcxx_tr1,
627 #include <tr1/array>
628 #include <tr1/ccomplex>
629 #include <tr1/cctype>
630 #include <tr1/cfenv>
631 #include <tr1/cfloat>
632 #include <tr1/cinttypes>
633 #include <tr1/climits>
634 #include <tr1/cmath>
635 #include <tr1/complex>
636 #include <tr1/cstdarg>
637 #include <tr1/cstdbool>
638 #include <tr1/cstdint>
639 #include <tr1/cstdio>
640 #include <tr1/cstdlib>
641 #include <tr1/ctgmath>
642 #include <tr1/ctime>
643 #include <tr1/cwchar>
644 #include <tr1/cwctype>
645 #include <tr1/functional>
646 #include <tr1/memory>
647 #include <tr1/random>
648 #include <tr1/regex>
649 #include <tr1/tuple>
650 #include <tr1/type_traits>
651 #include <tr1/unordered_set>
652 #include <tr1/unordered_map>
653 #include <tr1/utility>
655 ac_cv_cxx_stdcxx_tr1=yes, ac_cv_cxx_stdcxx_tr1=no)
658 if test "$ac_cv_cxx_stdcxx_tr1" = yes; then
659 AC_DEFINE(STDCXX_TR1_HEADERS,,[Define if ISO C++ TR1 header files are present. ])
662 </pre><p>An alternative is to check just for specific TR1 includes, such as <unordered_map> and <unordered_set>.
663 </p><pre class="programlisting">
664 # AC_HEADER_TR1_UNORDERED_MAP
665 AC_DEFUN([AC_HEADER_TR1_UNORDERED_MAP], [
666 AC_CACHE_CHECK(for tr1/unordered_map,
667 ac_cv_cxx_tr1_unordered_map,
670 AC_TRY_COMPILE([#include <tr1/unordered_map>], [using std::tr1::unordered_map;],
671 ac_cv_cxx_tr1_unordered_map=yes, ac_cv_cxx_tr1_unordered_map=no)
674 if test "$ac_cv_cxx_tr1_unordered_map" = yes; then
675 AC_DEFINE(HAVE_TR1_UNORDERED_MAP,,[Define if tr1/unordered_map is present. ])
678 </pre><pre class="programlisting">
679 # AC_HEADER_TR1_UNORDERED_SET
680 AC_DEFUN([AC_HEADER_TR1_UNORDERED_SET], [
681 AC_CACHE_CHECK(for tr1/unordered_set,
682 ac_cv_cxx_tr1_unordered_set,
685 AC_TRY_COMPILE([#include <tr1/unordered_set>], [using std::tr1::unordered_set;],
686 ac_cv_cxx_tr1_unordered_set=yes, ac_cv_cxx_tr1_unordered_set=no)
689 if test "$ac_cv_cxx_tr1_unordered_set" = yes; then
690 AC_DEFINE(HAVE_TR1_UNORDERED_SET,,[Define if tr1/unordered_set is present. ])
693 </pre></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.third.support_cxx11"></a>
694 Support for C++11 dialect.
695 </h4></div></div></div><p>Check for baseline language coverage in the compiler for the C++11 standard.
696 </p><pre class="programlisting">
697 # AC_COMPILE_STDCXX_11
698 AC_DEFUN([AC_COMPILE_STDCXX_11], [
699 AC_CACHE_CHECK(if g++ supports C++11 features without additional flags,
700 ac_cv_cxx_compile_cxx11_native,
704 template <typename T>
707 static constexpr T value{ __cplusplus };
710 typedef check<check<bool>> right_angle_brackets;
715 typedef check<int> check_type;
717 check_type&& cr = static_cast<check_type&&>(c);
719 static_assert(check_type::value == 201103L, "C++11 compiler");],,
720 ac_cv_cxx_compile_cxx11_native=yes, ac_cv_cxx_compile_cxx11_native=no)
724 AC_CACHE_CHECK(if g++ supports C++11 features with -std=c++11,
725 ac_cv_cxx_compile_cxx11_cxx,
728 ac_save_CXXFLAGS="$CXXFLAGS"
729 CXXFLAGS="$CXXFLAGS -std=c++11"
731 template <typename T>
734 static constexpr T value{ __cplusplus };
737 typedef check<check<bool>> right_angle_brackets;
742 typedef check<int> check_type;
744 check_type&& cr = static_cast<check_type&&>(c);
746 static_assert(check_type::value == 201103L, "C++11 compiler");],,
747 ac_cv_cxx_compile_cxx11_cxx=yes, ac_cv_cxx_compile_cxx11_cxx=no)
748 CXXFLAGS="$ac_save_CXXFLAGS"
752 AC_CACHE_CHECK(if g++ supports C++11 features with -std=gnu++11,
753 ac_cv_cxx_compile_cxx11_gxx,
756 ac_save_CXXFLAGS="$CXXFLAGS"
757 CXXFLAGS="$CXXFLAGS -std=gnu++11"
759 template <typename T>
762 static constexpr T value{ __cplusplus };
765 typedef check<check<bool>> right_angle_brackets;
770 typedef check<int> check_type;
772 check_type&& cr = static_cast<check_type&&>(c);
774 static_assert(check_type::value == 201103L, "C++11 compiler");],,
775 ac_cv_cxx_compile_cxx11_gxx=yes, ac_cv_cxx_compile_cxx11_gxx=no)
776 CXXFLAGS="$ac_save_CXXFLAGS"
780 if test "$ac_cv_cxx_compile_cxx11_native" = yes ||
781 test "$ac_cv_cxx_compile_cxx11_cxx" = yes ||
782 test "$ac_cv_cxx_compile_cxx11_gxx" = yes; then
783 AC_DEFINE(HAVE_STDCXX_11,,[Define if g++ supports C++11 features. ])
786 </pre><p>Check for library coverage of the C++2011 standard.
787 (Some library headers are commented out in this check, they are
788 not currently provided by libstdc++).
789 </p><pre class="programlisting">
790 # AC_HEADER_STDCXX_11
791 AC_DEFUN([AC_HEADER_STDCXX_11], [
792 AC_CACHE_CHECK(for ISO C++11 include files,
794 [AC_REQUIRE([AC_COMPILE_STDCXX_11])
797 ac_save_CXXFLAGS="$CXXFLAGS"
798 CXXFLAGS="$CXXFLAGS -std=gnu++11"
801 #include <cassert>
802 #include <ccomplex>
803 #include <cctype>
804 #include <cerrno>
805 #include <cfenv>
806 #include <cfloat>
807 #include <cinttypes>
808 #include <ciso646>
809 #include <climits>
810 #include <clocale>
811 #include <cmath>
812 #include <csetjmp>
813 #include <csignal>
814 #include <cstdalign>
815 #include <cstdarg>
816 #include <cstdbool>
817 #include <cstddef>
818 #include <cstdint>
819 #include <cstdio>
820 #include <cstdlib>
821 #include <cstring>
822 #include <ctgmath>
823 #include <ctime>
824 // #include <cuchar>
825 #include <cwchar>
826 #include <cwctype>
828 #include <algorithm>
829 #include <array>
830 #include <atomic>
831 #include <bitset>
832 #include <chrono>
833 // #include <codecvt>
834 #include <complex>
835 #include <condition_variable>
836 #include <deque>
837 #include <exception>
838 #include <forward_list>
839 #include <fstream>
840 #include <functional>
841 #include <future>
842 #include <initializer_list>
843 #include <iomanip>
845 #include <iosfwd>
846 #include <iostream>
847 #include <istream>
848 #include <iterator>
849 #include <limits>
850 #include <list>
851 #include <locale>
853 #include <memory>
854 #include <mutex>
856 #include <numeric>
857 #include <ostream>
858 #include <queue>
859 #include <random>
860 #include <ratio>
861 #include <regex>
862 #include <scoped_allocator>
864 #include <sstream>
865 #include <stack>
866 #include <stdexcept>
867 #include <streambuf>
868 #include <string>
869 #include <system_error>
870 #include <thread>
871 #include <tuple>
872 #include <typeindex>
873 #include <typeinfo>
874 #include <type_traits>
875 #include <unordered_map>
876 #include <unordered_set>
877 #include <utility>
878 #include <valarray>
879 #include <vector>
881 ac_cv_cxx_stdcxx_11=yes, ac_cv_cxx_stdcxx_11=no)
883 CXXFLAGS="$ac_save_CXXFLAGS"
885 if test "$ac_cv_cxx_stdcxx_11" = yes; then
886 AC_DEFINE(STDCXX_11_HEADERS,,[Define if ISO C++11 header files are present. ])
889 </pre><p>As is the case for TR1 support, these autoconf macros can be made for a finer-grained, per-header-file check. For
890 <code class="filename"><unordered_map></code>
891 </p><pre class="programlisting">
892 # AC_HEADER_UNORDERED_MAP
893 AC_DEFUN([AC_HEADER_UNORDERED_MAP], [
894 AC_CACHE_CHECK(for unordered_map,
895 ac_cv_cxx_unordered_map,
896 [AC_REQUIRE([AC_COMPILE_STDCXX_11])
899 ac_save_CXXFLAGS="$CXXFLAGS"
900 CXXFLAGS="$CXXFLAGS -std=gnu++11"
901 AC_TRY_COMPILE([#include <unordered_map>], [using std::unordered_map;],
902 ac_cv_cxx_unordered_map=yes, ac_cv_cxx_unordered_map=no)
903 CXXFLAGS="$ac_save_CXXFLAGS"
906 if test "$ac_cv_cxx_unordered_map" = yes; then
907 AC_DEFINE(HAVE_UNORDERED_MAP,,[Define if unordered_map is present. ])
910 </pre><pre class="programlisting">
911 # AC_HEADER_UNORDERED_SET
912 AC_DEFUN([AC_HEADER_UNORDERED_SET], [
913 AC_CACHE_CHECK(for unordered_set,
914 ac_cv_cxx_unordered_set,
915 [AC_REQUIRE([AC_COMPILE_STDCXX_11])
918 ac_save_CXXFLAGS="$CXXFLAGS"
919 CXXFLAGS="$CXXFLAGS -std=gnu++11"
920 AC_TRY_COMPILE([#include <unordered_set>], [using std::unordered_set;],
921 ac_cv_cxx_unordered_set=yes, ac_cv_cxx_unordered_set=no)
922 CXXFLAGS="$ac_save_CXXFLAGS"
925 if test "$ac_cv_cxx_unordered_set" = yes; then
926 AC_DEFINE(HAVE_UNORDERED_SET,,[Define if unordered_set is present. ])
930 Some C++11 features first appeared in GCC 4.3 and could be enabled by
931 <code class="option">-std=c++0x</code> and <code class="option">-std=gnu++0x</code> for GCC
932 releases which pre-date the 2011 standard. Those C++11 features and GCC's
933 support for them were still changing until the 2011 standard was finished,
934 but the autoconf checks above could be extended to test for incomplete
935 C++11 support with <code class="option">-std=c++0x</code> and
936 <code class="option">-std=gnu++0x</code>.
937 </p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="backwards.third.iterator_type"></a>
938 <code class="code">Container::iterator_type</code> is not necessarily <code class="code">Container::value_type*</code>
939 </h4></div></div></div><p>
940 This is a change in behavior from older versions. Now, most
941 <span class="type">iterator_type</span> typedefs in container classes are POD
942 objects, not <span class="type">value_type</span> pointers.
943 </p></div></div><div class="bibliography"><div class="titlepage"><div><div><h3 class="title"><a id="backwards.biblio"></a>Bibliography</h3></div></div></div><div class="biblioentry"><a id="idp23415104"></a><p><span class="title"><em>
944 <a class="link" href="http://www.kegel.com/gcc/gcc4.html" target="_top">
947 </em>. </span><span class="author"><span class="firstname">Dan</span> <span class="surname">Kegel</span>. </span></p></div><div class="biblioentry"><a id="idp23417888"></a><p><span class="title"><em>
948 <a class="link" href="http://lists.debian.org/debian-gcc/2006/03/msg00405.html" target="_top">
949 Building the Whole Debian Archive with GCC 4.1: A Summary
951 </em>. </span><span class="author"><span class="firstname">Martin</span> <span class="surname">Michlmayr</span>. </span></p></div><div class="biblioentry"><a id="idp23420736"></a><p><span class="title"><em>
952 <a class="link" href="http://annwm.lbl.gov/~leggett/Atlas/gcc-3.2.html" target="_top">
953 Migration guide for GCC-3.2
955 </em>. </span></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.
956 Free Software Needs Free Documentation
958 </td></tr></table></div></body></html>