Merge -r 127928:132243 from trunk
[official-gcc.git] / libstdc++-v3 / doc / html / 17_intro / backwards_compatibility.html
blobc9af980f0fc2b9d881f33db966e65348a92dd514
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html
3 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7 <head>
8 <meta name="AUTHOR" content="bkoz@gcc.gnu.org (Benjamin Kosnik), Felix Natter" />
9 <meta name="KEYWORDS" content="C++, libstdc++, API, backward, compatibility" />
10 <meta name="DESCRIPTION" content="Backwards Compatibility" />
11 <meta name="GENERATOR" content="emacs and ten fingers" />
12 <title>Backwards Compatibility</title>
13 <link rel="StyleSheet" href="lib3styles.css" type="text/css" />
14 <link rel="Start" href="documentation.html" type="text/html"
15 title="GNU C++ Standard Library" />
16 <link rel="Copyright" href="17_intro/license.html" type="text/html" />
17 </head>
18 <body>
20 <h1 class="centered"><a name="top">Backwards Compatibility</a></h1>
22 <p class="fineprint"><em>
23 The latest version of this document is always available at
24 <a href="http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/backwards_compatibility.html">
25 http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/backwards_compatibility.html</a>.
26 </em></p>
28 <p><em>
29 To the <a href="http://gcc.gnu.org/libstdc++/">libstdc++ homepage</a>.
30 </em></p>
32 <!-- ####################################################### -->
33 <hr />
34 <h3 class="left">
35 <a name="v1">First.</a>
36 </h3>
38 <p> The first generation GNU C++ library was called libg++. It was a
39 separate GNU project, although reliably paired with GCC. Rumors imply
40 that it had a working relationship with at least two kinds of
41 dinosaur.
42 </p>
44 <p>Known Issues include many of the limitations of its immediate ancestor.</p>
46 <p>Portability notes and known implementation limitations are as follows.</p>
48 <h5>No <code>ios_base</code></h5>
50 <p> 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>.
51 </p>
53 <h5>No <code>cout</code> in <code>ostream.h</code>, no <code>cin</code> in <code>istream.h</code></h5>
55 <p>
56 In earlier versions of the standard,
57 <tt>&lt;fstream.h&gt;</tt>,
58 <tt>&lt;ostream.h&gt;</tt>
59 and <tt>&lt;istream.h&gt;</tt>
60 used to define
61 <code>cout</code>, <code>cin</code> and so on. ISO C++ specifies that one needs to include
62 <tt>&lt;iostream&gt;</tt>
63 explicitly to get the required definitions.
64 </p>
65 <p> Some include adjustment may be required.</p>
68 <p>This project is no longer maintained or supported, and the sources
69 archived. The code is considered replaced and rewritten.
70 </p>
72 <hr />
73 <h3 class="left">
74 <a name="v2">Second.</a>
75 </h3>
76 <p> The second generation GNU C++ library was called libstdc++, or
77 libstdc++-v2. It spans the time between libg++ and pre-ISO C++
78 standardization and is usually associated with the following GCC
79 releases: egcs 1.x, gcc 2.95, and gcc 2.96.
80 </p>
82 <p> The STL portions of this library are based on SGI/HP STL release 3.11.
83 </p>
85 <p>Portability notes and known implementation limitations are as follows.</p>
87 <h5>Namespace <code>std::</code> not supported</h5>
89 <p>
90 Some care is required to support C++ compiler and or library
91 implementation that do not have the standard library in
92 <code>namespace std</code>.
93 </p>
94 <p>
95 The following sections list some possible solutions to support compilers
96 that cannot ignore <code>std::</code>-qualified names.
97 </p>
99 <p> First, see if the compiler has a flag for this. Namespace
100 back-portability-issues are generally not a problem for g++
101 compilers that do not have libstdc++ in <code>std::</code>, as
102 the compilers use <code>-fno-honor-std</code> (ignore
103 <code>std::</code>, <code>:: = std::</code>) by default. That
104 is, the responsibility for enabling or disabling
105 <code>std::</code> is on the user; the maintainer does not have
106 to care about it. This probably applies to some other compilers
107 as well.
108 </p>
110 <p>Second, experiment with a variety of pre-processor tricks.</p>
112 <p> By defining <code>std</code> as a macro, fully-qualified namespace calls become global. Volia. </p>
114 <pre>
115 #ifdef WICKEDLY_OLD_COMPILER
116 # define std
117 #endif
118 </pre>
119 (thanks to Juergen Heinzl who posted this solution on gnu.gcc.help)
121 <p>Another pre-processor based approach is to define a
122 macro <code>NAMESPACE_STD</code>, which is defined to either
123 &quot;&quot; or &quot;std&quot; based on a compile-type test. On GNU
124 systems, this can be done with autotools by means of an autoconf test
125 (see below) for <code>HAVE_NAMESPACE_STD</code>, then using that to
126 set a value for the <code>NAMESPACE_STD</code> macro. At that point,
127 one is able to use <code>NAMESPACE_STD::string</code>, which will
128 evaluate to <code>std::string</code> or
129 <code>::string</code> (ie, in the global namespace on systems that do
130 not put <code>string</code> in <code>std::</code>). </p>
132 <pre style="background: #c0c0c0">
133 dnl @synopsis AC_CXX_NAMESPACE_STD
135 dnl If the compiler supports namespace std, define
136 dnl HAVE_NAMESPACE_STD.
138 dnl @category Cxx
139 dnl @author Todd Veldhuizen
140 dnl @author Luc Maisonobe &lt;luc@spaceroots.org&gt;
141 dnl @version 2004-02-04
142 dnl @license AllPermissive
143 AC_DEFUN([AC_CXX_NAMESPACE_STD], [
144 AC_CACHE_CHECK(if g++ supports namespace std,
145 ac_cv_cxx_have_std_namespace,
146 [AC_LANG_SAVE
147 AC_LANG_CPLUSPLUS
148 AC_TRY_COMPILE([#include &lt;iostream&gt;
149 std::istream&amp; is = std::cin;],,
150 ac_cv_cxx_have_std_namespace=yes, ac_cv_cxx_have_std_namespace=no)
151 AC_LANG_RESTORE
153 if test "$ac_cv_cxx_have_std_namespace" = yes; then
154 AC_DEFINE(HAVE_NAMESPACE_STD,,[Define if g++ supports namespace std. ])
157 </pre>
159 <h5>Illegal iterator usage</h5>
161 The following illustrate implementation-allowed illegal iterator
162 use, and then correct use.
163 </p>
165 <ul> <li><p>you cannot do
166 <code>ostream::operator&lt;&lt;(iterator)</code> to print the
167 address of the iterator =&gt; use <code>operator&lt;&lt;
168 &amp;*iterator</code> instead
169 </p></li>
170 <li><p>you cannot clear an iterator's reference
171 (<code>iterator = 0</code>) =&gt; use
172 <code>iterator = iterator_type();</code>
173 </p></li>
174 <li><p>
175 <code>if (iterator)</code> won't work any
176 more =&gt; use <code>if (iterator != iterator_type())</code>
177 </p></li>
178 </ul>
180 <h5><code>isspace</code> from <tt>&lt;cctype&gt;</tt> is a macro
181 </h5>
183 <p> Glibc 2.0.x and 2.1.x define <tt>&lt;ctype.h&gt;</tt>
184 functionality as macros (isspace, isalpha etc.).
185 </p>
188 This implementations of libstdc++, however, keep these functions as
189 macros, and so it is not back-portable to use fully qualified
190 names. For example:
191 </p>
193 <pre>
194 #include &lt;cctype&gt;
195 int main() { std::isspace('X'); }
196 </pre>
198 <p>Results in something like this:
199 </p>
201 <pre>
202 std:: (__ctype_b[(int) ( ( 'X' ) )] &amp; (unsigned short int) _ISspace ) ;
203 </pre>
206 <p> A solution is to modify a header-file so that the compiler tells
207 <tt>&lt;ctype.h&gt;</tt> to define functions instead of macros:
208 </p>
210 <pre>
211 // This keeps isalnum, et al from being propagated as macros.
212 #if __linux__
213 # define __NO_CTYPE 1
214 #endif
215 </pre>
217 <p>Then, include &lt;ctype.h&gt;
218 </p>
221 Another problem arises if you put a <code>using namespace std;</code>
222 declaration at the top, and include <tt>&lt;ctype.h&gt;</tt>. This
223 will result in ambiguities between the definitions in the global
224 namespace (<tt>&lt;ctype.h&gt;</tt>) and the definitions in namespace
225 <code>std::</code> (<code>&lt;cctype&gt;</code>).
226 </p>
228 <h5>No <code>vector::at</code>, <code>deque::at</code>, <code>string::at</code></h5>
231 One solution is to add an autoconf-test for this:
232 </p>
233 <pre style="background: #c0c0c0">
234 AC_MSG_CHECKING(for container::at)
235 AC_TRY_COMPILE(
237 #include &lt;vector&gt;
238 #include &lt;deque&gt;
239 #include &lt;string&gt;
241 using namespace std;
244 deque&lt;int&gt; test_deque(3);
245 test_deque.at(2);
246 vector&lt;int&gt; test_vector(2);
247 test_vector.at(1);
248 string test_string(&quot;test_string&quot;);
249 test_string.at(3);
251 [AC_MSG_RESULT(yes)
252 AC_DEFINE(HAVE_CONTAINER_AT)],
253 [AC_MSG_RESULT(no)])
254 </pre>
257 If you are using other (non-GNU) compilers it might be a good idea
258 to check for <code>string::at</code> separately.
259 </p>
261 <h5>No <code>std::char_traits&lt;char&gt;::eof</code></h5>
264 Use some kind of autoconf test, plus this:
265 </p>
266 <pre>
267 #ifdef HAVE_CHAR_TRAITS
268 #define CPP_EOF std::char_traits&lt;char&gt;::eof()
269 #else
270 #define CPP_EOF EOF
271 #endif
272 </pre>
274 <h5>No <code>string::clear</code></h5>
277 There are two functions for deleting the contents of a string:
278 <code>clear</code> and <code>erase</code> (the latter
279 returns the string).
280 </p>
282 <pre>
283 void
284 clear() { _M_mutate(0, this-&gt;size(), 0); }
285 </pre>
286 <pre>
287 basic_string&amp;
288 erase(size_type __pos = 0, size_type __n = npos)
290 return this-&gt;replace(_M_check(__pos), _M_fold(__pos, __n),
291 _M_data(), _M_data());
293 </pre>
296 Unfortunately, ut <code>clear</code> is not
297 implemented in this version, so you should use
298 <code>erase</code> (which is probably faster than
299 <code>operator=(charT*)</code>).
300 </p>
302 <h5>Removal of <code>ostream::form</code> and
303 <code>istream::scan</code> extensions</h5>
305 <p> These are no longer supported. Please use
306 <a href="#sec-stringstream" title="Using stringstreams">
307 stringstreams</a> instead.
308 </p>
310 <h5>No <code>basic_stringbuf</code>, <code>basic_stringstream</code></h5>
313 Although the ISO standard
314 <code>i/ostringstream</code>-classes are provided, (<tt>&lt;sstream&gt;</tt>), for compatibility with older implementations the pre-ISO <code>i/ostrstream</code> (<tt>&lt;strstream&gt;</tt>) interface is also provided, with these caveats:
315 </p>
317 <div class="itemizedlist"><ul type="disc">
318 <li><p> <code>strstream</code> is considered to be
319 deprecated
320 </p></li>
321 <li><p> <code>strstream</code> is limited to
322 <code>char</code>
323 </p></li>
324 <li><p> with <code>ostringstream</code> you don't
325 have to take care of terminating the string or freeing its
326 memory
327 </p></li>
328 <li><p> <code>istringstream</code> can be re-filled
329 (clear(); str(input);)
330 </p></li>
331 </ul></div>
333 You can then use output-stringstreams like this:
334 </p>
336 <pre>
337 #ifdef HAVE_SSTREAM
338 # include &lt;sstream&gt;
339 #else
340 # include &lt;strstream&gt;
341 #endif
343 #ifdef HAVE_SSTREAM
344 std::ostringstream oss;
345 #else
346 std::ostrstream oss;
347 #endif
349 oss &lt;&lt; &quot;Name=&quot; &lt;&lt; m_name &lt;&lt; &quot;, number=&quot; &lt;&lt; m_number &lt;&lt; std::endl;
351 #ifndef HAVE_SSTREAM
352 oss &lt;&lt; std::ends; // terminate the char*-string
353 #endif
355 // str() returns char* for ostrstream and a string for ostringstream
356 // this also causes ostrstream to think that the buffer's memory
357 // is yours
358 m_label.set_text(oss.str());
359 #ifndef HAVE_SSTREAM
360 // let the ostrstream take care of freeing the memory
361 oss.freeze(false);
362 #endif
363 </pre>
366 Input-stringstreams can be used similarly:
367 </p>
369 <pre>
370 std::string input;
372 #ifdef HAVE_SSTREAM
373 std::istringstream iss(input);
374 #else
375 std::istrstream iss(input.c_str());
376 #endif
378 int i;
379 iss &gt;&gt; i;
380 </pre>
382 <p> One (the only?) restriction is that an istrstream cannot be re-filled:
383 </p>
385 <pre>
386 std::istringstream iss(numerator);
387 iss &gt;&gt; m_num;
388 // this is not possible with istrstream
389 iss.clear();
390 iss.str(denominator);
391 iss &gt;&gt; m_den;
392 </pre>
395 If you don't care about speed, you can put these conversions in
396 a template-function:
397 </p>
398 <pre>
399 template &lt;class X&gt;
400 void fromString(const string&amp; input, X&amp; any)
402 #ifdef HAVE_SSTREAM
403 std::istringstream iss(input);
404 #else
405 std::istrstream iss(input.c_str());
406 #endif
407 X temp;
408 iss &gt;&gt; temp;
409 if (iss.fail())
410 throw runtime_error(..)
411 any = temp;
413 </pre>
415 <p> Another example of using stringstreams is in <a href="../21_strings/howto.html" target="_top">this howto</a>.
416 </p>
418 <p> There is additional information in the libstdc++-v2 info files, in
419 particular &quot;info iostream&quot;.
420 </p>
422 <h5>Little or no wide character support</h5>
424 <h5>No templatized iostreams</h5>
426 <h5>Thread safety issues</h5>
428 <p>This project is no longer maintained or supported, and the sources
429 archived. The code is considered replaced and rewritten.
430 </p>
433 <hr />
434 <h3 class="left">
435 <a name="v3">Third.</a>
436 </h3>
437 <p> The third generation GNU C++ library is called libstdc++, or
438 libstdc++-v3.
439 </p>
441 <p>The subset commonly known as the Standard Template Library
442 (chapters 23 through 25, mostly) is adapted from the final release
443 of the SGI STL (version 3.3), with extensive changes.
444 </p>
446 <p>A more formal description of the V3 goals can be found in the
447 official <a href="../17_intro/DESIGN">design document</a>.
448 </p>
450 <p>Portability notes and known implementation limitations are as follows.</p>
452 <h5>Pre-ISO headers moved to backwards or removed</h5>
454 <p> The pre-ISO C++ headers
455 (<code>iostream.h</code>, <code>defalloc.h</code> etc.) are
456 available, unlike previous libstdc++ versions, but inclusion
457 generates a warning that you are using deprecated headers.
458 </p>
460 <p>This compatibility layer is constructed by including the
461 standard C++ headers, and injecting any items in
462 <code>std::</code> into the global namespace.
463 </p>
464 <p>For those of you new to ISO C++ (welcome, time travelers!), no,
465 that isn't a typo. Yes, the headers really have new names.
466 Marshall Cline's C++ FAQ Lite has a good explanation in <a
467 href="http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4">item
468 [27.4]</a>.
469 </p>
471 <p> Some include adjustment may be required. What follows is an
472 autoconf test that defines <code>PRE_STDCXX_HEADERS</code> when they
473 exist.</p>
475 <pre style="background: #c0c0c0">
476 # AC_HEADER_PRE_STDCXX
477 AC_DEFUN([AC_HEADER_PRE_STDCXX], [
478 AC_CACHE_CHECK(for pre-ISO C++ include files,
479 ac_cv_cxx_pre_stdcxx,
480 [AC_LANG_SAVE
481 AC_LANG_CPLUSPLUS
482 ac_save_CXXFLAGS="$CXXFLAGS"
483 CXXFLAGS="$CXXFLAGS -Wno-deprecated"
485 # Omit defalloc.h, as compilation with newer compilers is problematic.
486 AC_TRY_COMPILE([
487 #include &lt;new.h&gt;
488 #include &lt;iterator.h&gt;
489 #include &lt;alloc.h&gt;
490 #include &lt;set.h&gt;
491 #include &lt;hashtable.h&gt;
492 #include &lt;hash_set.h&gt;
493 #include &lt;fstream.h&gt;
494 #include &lt;tempbuf.h&gt;
495 #include &lt;istream.h&gt;
496 #include &lt;bvector.h&gt;
497 #include &lt;stack.h&gt;
498 #include &lt;rope.h&gt;
499 #include &lt;complex.h&gt;
500 #include &lt;ostream.h&gt;
501 #include &lt;heap.h&gt;
502 #include &lt;iostream.h&gt;
503 #include &lt;function.h&gt;
504 #include &lt;multimap.h&gt;
505 #include &lt;pair.h&gt;
506 #include &lt;stream.h&gt;
507 #include &lt;iomanip.h&gt;
508 #include &lt;slist.h&gt;
509 #include &lt;tree.h&gt;
510 #include &lt;vector.h&gt;
511 #include &lt;deque.h&gt;
512 #include &lt;multiset.h&gt;
513 #include &lt;list.h&gt;
514 #include &lt;map.h&gt;
515 #include &lt;algobase.h&gt;
516 #include &lt;hash_map.h&gt;
517 #include &lt;algo.h&gt;
518 #include &lt;queue.h&gt;
519 #include &lt;streambuf.h&gt;
521 ac_cv_cxx_pre_stdcxx=yes, ac_cv_cxx_pre_stdcxx=no)
522 CXXFLAGS="$ac_save_CXXFLAGS"
523 AC_LANG_RESTORE
525 if test "$ac_cv_cxx_pre_stdcxx" = yes; then
526 AC_DEFINE(PRE_STDCXX_HEADERS,,[Define if pre-ISO C++ header files are present. ])
529 </pre>
531 <p>Porting between pre-ISO headers and ISO headers is simple: headers
532 like &lt;vector.h&gt; can be replaced with &lt;vector&gt; and a using
533 directive <code>using namespace std;</code> can be put at the global
534 scope. This should be enough to get this code compiling, assuming the
535 other usage is correct.
536 </p>
538 <h5>Extension headers hash_map, hash_set moved to ext or backwards</h5>
540 <p> Header files <code>hash_map</code> and <code>hash_set</code> moved
541 to <code>ext/hash_map</code> and <code>ext/hash_set</code>,
542 respectively. At the same time, all types in these files are enclosed
543 in <code>namespace __gnu_cxx</code>. Later versions move deprecate
544 these files, and suggest using TR1's <code>unordered_map</code>
545 and <code>unordered_set</code> instead.
546 </p>
548 <p>The following autoconf tests check for working HP/SGI hash containers.
549 </p>
551 <pre style="background: #c0c0c0">
552 # AC_HEADER_EXT_HASH_MAP
553 AC_DEFUN([AC_HEADER_EXT_HASH_MAP], [
554 AC_CACHE_CHECK(for ext/hash_map,
555 ac_cv_cxx_ext_hash_map,
556 [AC_LANG_SAVE
557 AC_LANG_CPLUSPLUS
558 ac_save_CXXFLAGS="$CXXFLAGS"
559 CXXFLAGS="$CXXFLAGS -Werror"
560 AC_TRY_COMPILE([#include &lt;ext/hash_map&gt;], [using __gnu_cxx::hash_map;],
561 ac_cv_cxx_ext_hash_map=yes, ac_cv_cxx_ext_hash_map=no)
562 CXXFLAGS="$ac_save_CXXFLAGS"
563 AC_LANG_RESTORE
565 if test "$ac_cv_cxx_ext_hash_map" = yes; then
566 AC_DEFINE(HAVE_EXT_HASH_MAP,,[Define if ext/hash_map is present. ])
569 </pre>
571 <pre style="background: #c0c0c0">
572 # AC_HEADER_EXT_HASH_SET
573 AC_DEFUN([AC_HEADER_EXT_HASH_SET], [
574 AC_CACHE_CHECK(for ext/hash_set,
575 ac_cv_cxx_ext_hash_set,
576 [AC_LANG_SAVE
577 AC_LANG_CPLUSPLUS
578 ac_save_CXXFLAGS="$CXXFLAGS"
579 CXXFLAGS="$CXXFLAGS -Werror"
580 AC_TRY_COMPILE([#include &lt;ext/hash_set&gt;], [using __gnu_cxx::hash_set;],
581 ac_cv_cxx_ext_hash_set=yes, ac_cv_cxx_ext_hash_set=no)
582 CXXFLAGS="$ac_save_CXXFLAGS"
583 AC_LANG_RESTORE
585 if test "$ac_cv_cxx_ext_hash_set" = yes; then
586 AC_DEFINE(HAVE_EXT_HASH_SET,,[Define if ext/hash_set is present. ])
589 </pre>
592 <h5>
593 No <code>ios::nocreate/ios::noreplace</code>.
594 </h5>
596 <p> The existence of <code>ios::nocreate</code> being used for
597 input-streams has been confirmed, most probably because the author
598 thought it would be more correct to specify nocreate explicitly. So
599 it can be left out for input-streams.
600 </p>
602 <p>For output streams, &quot;nocreate&quot; is probably the default,
603 unless you specify <code>std::ios::trunc</code> ? To be safe, you can
604 open the file for reading, check if it has been opened, and then
605 decide whether you want to create/replace or not. To my knowledge,
606 even older implementations support <code>app</code>, <code>ate</code>
607 and <code>trunc</code> (except for <code>app</code> ?).
608 </p>
611 <h5>
612 No <code>stream::attach(int fd)</code>
613 </h5>
616 Phil Edwards writes: It was considered and rejected for the ISO
617 standard. Not all environments use file descriptors. Of those
618 that do, not all of them use integers to represent them.
619 </p>
622 For a portable solution (among systems which use
623 filedescriptors), you need to implement a subclass of
624 <code>std::streambuf</code> (or
625 <code>std::basic_streambuf&lt;..&gt;</code>) which opens a file
626 given a descriptor, and then pass an instance of this to the
627 stream-constructor.
628 </p>
631 An extension is available that implements this.
632 <code>&lt;ext/stdio_filebuf.h&gt;</code> contains a derived class called
633 <a href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/class____gnu__cxx_1_1stdio__filebuf.html"><code>__gnu_cxx::stdio_filebuf</code></a>.
634 This class can be constructed from a C <code>FILE*</code> or a file
635 descriptor, and provides the <code>fd()</code> function.
636 </p>
639 For another example of this, refer to
640 <a href="http://www.josuttis.com/cppcode/fdstream.html" target="_top">fdstream example</a>
641 by Nicolai Josuttis.
642 </p>
644 <h5>
645 Support for C++98 dialect.
646 </h5>
648 <p>Check for complete library coverage of the C++1998/2003 standard.
649 </p>
651 <pre style="background: #c0c0c0">
653 # AC_HEADER_STDCXX_98
654 AC_DEFUN([AC_HEADER_STDCXX_98], [
655 AC_CACHE_CHECK(for ISO C++ 98 include files,
656 ac_cv_cxx_stdcxx_98,
657 [AC_LANG_SAVE
658 AC_LANG_CPLUSPLUS
659 AC_TRY_COMPILE([
660 #include &lt;cassert&gt;
661 #include &lt;cctype&gt;
662 #include &lt;cerrno&gt;
663 #include &lt;cfloat&gt;
664 #include &lt;ciso646&gt;
665 #include &lt;climits&gt;
666 #include &lt;clocale&gt;
667 #include &lt;cmath&gt;
668 #include &lt;csetjmp&gt;
669 #include &lt;csignal&gt;
670 #include &lt;cstdarg&gt;
671 #include &lt;cstddef&gt;
672 #include &lt;cstdio&gt;
673 #include &lt;cstdlib&gt;
674 #include &lt;cstring&gt;
675 #include &lt;ctime&gt;
677 #include &lt;algorithm&gt;
678 #include &lt;bitset&gt;
679 #include &lt;complex&gt;
680 #include &lt;deque&gt;
681 #include &lt;exception&gt;
682 #include &lt;fstream&gt;
683 #include &lt;functional&gt;
684 #include &lt;iomanip&gt;
685 #include &lt;ios&gt;
686 #include &lt;iosfwd&gt;
687 #include &lt;iostream&gt;
688 #include &lt;istream&gt;
689 #include &lt;iterator&gt;
690 #include &lt;limits&gt;
691 #include &lt;list&gt;
692 #include &lt;locale&gt;
693 #include &lt;map&gt;
694 #include &lt;memory&gt;
695 #include &lt;new&gt;
696 #include &lt;numeric&gt;
697 #include &lt;ostream&gt;
698 #include &lt;queue&gt;
699 #include &lt;set&gt;
700 #include &lt;sstream&gt;
701 #include &lt;stack&gt;
702 #include &lt;stdexcept&gt;
703 #include &lt;streambuf&gt;
704 #include &lt;string&gt;
705 #include &lt;typeinfo&gt;
706 #include &lt;utility&gt;
707 #include &lt;valarray&gt;
708 #include &lt;vector&gt;
710 ac_cv_cxx_stdcxx_98=yes, ac_cv_cxx_stdcxx_98=no)
711 AC_LANG_RESTORE
713 if test "$ac_cv_cxx_stdcxx_98" = yes; then
714 AC_DEFINE(STDCXX_98_HEADERS,,[Define if ISO C++ 1998 header files are present. ])
717 </pre>
720 <h5>
721 Support for C++TR1 dialect.
722 </h5>
724 <p>Check for library coverage of the TR1 standard.
725 </p>
727 <pre style="background: #c0c0c0">
729 # AC_HEADER_STDCXX_TR1
730 AC_DEFUN([AC_HEADER_STDCXX_TR1], [
731 AC_CACHE_CHECK(for ISO C++ TR1 include files,
732 ac_cv_cxx_stdcxx_tr1,
733 [AC_LANG_SAVE
734 AC_LANG_CPLUSPLUS
735 AC_TRY_COMPILE([
736 #include &lt;tr1/array&gt;
737 #include &lt;tr1/ccomplex&gt;
738 #include &lt;tr1/cctype&gt;
739 #include &lt;tr1/cfenv&gt;
740 #include &lt;tr1/cfloat&gt;
741 #include &lt;tr1/cinttypes&gt;
742 #include &lt;tr1/climits&gt;
743 #include &lt;tr1/cmath&gt;
744 #include &lt;tr1/complex&gt;
745 #include &lt;tr1/cstdarg&gt;
746 #include &lt;tr1/cstdbool&gt;
747 #include &lt;tr1/cstdint&gt;
748 #include &lt;tr1/cstdio&gt;
749 #include &lt;tr1/cstdlib&gt;
750 #include &lt;tr1/ctgmath&gt;
751 #include &lt;tr1/ctime&gt;
752 #include &lt;tr1/cwchar&gt;
753 #include &lt;tr1/cwctype&gt;
754 #include &lt;tr1/functional&gt;
755 #include &lt;tr1/memory&gt;
756 #include &lt;tr1/random&gt;
757 #include &lt;tr1/regex&gt;
758 #include &lt;tr1/tuple&gt;
759 #include &lt;tr1/type_traits&gt;
760 #include &lt;tr1/unordered_set&gt;
761 #include &lt;tr1/unordered_map&gt;
762 #include &lt;tr1/utility&gt;
764 ac_cv_cxx_stdcxx_tr1=yes, ac_cv_cxx_stdcxx_tr1=no)
765 AC_LANG_RESTORE
767 if test "$ac_cv_cxx_stdcxx_tr1" = yes; then
768 AC_DEFINE(STDCXX_TR1_HEADERS,,[Define if ISO C++ TR1 header files are present. ])
771 </pre>
773 <p>An alternative is to check just for specific TR1 includes, such as &lt;unordered_map&gt; and &lt;unordered_set&gt;.
774 </p>
776 <pre style="background: #c0c0c0">
777 # AC_HEADER_TR1_UNORDERED_MAP
778 AC_DEFUN([AC_HEADER_TR1_UNORDERED_MAP], [
779 AC_CACHE_CHECK(for tr1/unordered_map,
780 ac_cv_cxx_tr1_unordered_map,
781 [AC_LANG_SAVE
782 AC_LANG_CPLUSPLUS
783 AC_TRY_COMPILE([#include &lt;tr1/unordered_map&gt;], [using std::tr1::unordered_map;],
784 ac_cv_cxx_tr1_unordered_map=yes, ac_cv_cxx_tr1_unordered_map=no)
785 AC_LANG_RESTORE
787 if test "$ac_cv_cxx_tr1_unordered_map" = yes; then
788 AC_DEFINE(HAVE_TR1_UNORDERED_MAP,,[Define if tr1/unordered_map is present. ])
791 </pre>
793 <pre style="background: #c0c0c0">
794 # AC_HEADER_TR1_UNORDERED_SET
795 AC_DEFUN([AC_HEADER_TR1_UNORDERED_SET], [
796 AC_CACHE_CHECK(for tr1/unordered_set,
797 ac_cv_cxx_tr1_unordered_set,
798 [AC_LANG_SAVE
799 AC_LANG_CPLUSPLUS
800 AC_TRY_COMPILE([#include &lt;tr1/unordered_set&gt;], [using std::tr1::unordered_set;],
801 ac_cv_cxx_tr1_unordered_set=yes, ac_cv_cxx_tr1_unordered_set=no)
802 AC_LANG_RESTORE
804 if test "$ac_cv_cxx_tr1_unordered_set" = yes; then
805 AC_DEFINE(HAVE_TR1_UNORDERED_SET,,[Define if tr1/unordered_set is present. ])
808 </pre>
812 <h5>
813 Support for C++0x dialect.
814 </h5>
816 <p>Check for baseline language coverage in the compiler for the C++0xstandard.
817 </p>
819 <pre style="background: #c0c0c0">
820 # AC_COMPILE_STDCXX_OX
821 AC_DEFUN([AC_COMPILE_STDCXX_0X], [
822 AC_CACHE_CHECK(if g++ supports C++0x features without additional flags,
823 ac_cv_cxx_compile_cxx0x_native,
824 [AC_LANG_SAVE
825 AC_LANG_CPLUSPLUS
826 AC_TRY_COMPILE([
827 template &lt;typename T&gt;
828 struct check
830 static_assert(sizeof(int) &lt;= sizeof(T), "not big enough");
833 typedef check&lt;check&lt;bool&gt;&gt; right_angle_brackets;
835 int a;
836 decltype(a) b;
838 typedef check&lt;int&gt; check_type;
839 check_type c;
840 check_type&amp;&amp; cr = c;],,
841 ac_cv_cxx_compile_cxx0x_native=yes, ac_cv_cxx_compile_cxx0x_native=no)
842 AC_LANG_RESTORE
845 AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x,
846 ac_cv_cxx_compile_cxx0x_cxx,
847 [AC_LANG_SAVE
848 AC_LANG_CPLUSPLUS
849 ac_save_CXXFLAGS="$CXXFLAGS"
850 CXXFLAGS="$CXXFLAGS -std=c++0x"
851 AC_TRY_COMPILE([
852 template &lt;typename T&gt;
853 struct check
855 static_assert(sizeof(int) &lt;= sizeof(T), "not big enough");
858 typedef check&lt;check&lt;bool&gt;&gt; right_angle_brackets;
860 int a;
861 decltype(a) b;
863 typedef check&lt;int&gt; check_type;
864 check_type c;
865 check_type&amp;&amp; cr = c;],,
866 ac_cv_cxx_compile_cxx0x_cxx=yes, ac_cv_cxx_compile_cxx0x_cxx=no)
867 CXXFLAGS="$ac_save_CXXFLAGS"
868 AC_LANG_RESTORE
871 AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x,
872 ac_cv_cxx_compile_cxx0x_gxx,
873 [AC_LANG_SAVE
874 AC_LANG_CPLUSPLUS
875 ac_save_CXXFLAGS="$CXXFLAGS"
876 CXXFLAGS="$CXXFLAGS -std=gnu++0x"
877 AC_TRY_COMPILE([
878 template &lt;typename T&gt;
879 struct check
881 static_assert(sizeof(int) &lt;= sizeof(T), "not big enough");
884 typedef check&lt;check&lt;bool&gt;&gt; right_angle_brackets;
886 int a;
887 decltype(a) b;
889 typedef check&lt;int&gt; check_type;
890 check_type c;
891 check_type&amp;&amp; cr = c;],,
892 ac_cv_cxx_compile_cxx0x_gxx=yes, ac_cv_cxx_compile_cxx0x_gxx=no)
893 CXXFLAGS="$ac_save_CXXFLAGS"
894 AC_LANG_RESTORE
897 if test "$ac_cv_cxx_compile_cxx0x_native" = yes ||
898 test "$ac_cv_cxx_compile_cxx0x_cxx" = yes ||
899 test "$ac_cv_cxx_compile_cxx0x_gxx" = yes; then
900 AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ])
903 </pre>
906 <p>Check for library coverage of the C++0xstandard.
907 </p>
909 <pre style="background: #c0c0c0">
911 # AC_HEADER_STDCXX_0X
912 AC_DEFUN([AC_HEADER_STDCXX_0X], [
913 AC_CACHE_CHECK(for ISO C++ 0x include files,
914 ac_cv_cxx_stdcxx_0x,
915 [AC_REQUIRE([AC_COMPILE_STDCXX_0X])
916 AC_LANG_SAVE
917 AC_LANG_CPLUSPLUS
918 ac_save_CXXFLAGS="$CXXFLAGS"
919 CXXFLAGS="$CXXFLAGS -std=gnu++0x"
921 AC_TRY_COMPILE([
922 #include &lt;cassert&gt;
923 #include &lt;ccomplex&gt;
924 #include &lt;cctype&gt;
925 #include &lt;cerrno&gt;
926 #include &lt;cfenv&gt;
927 #include &lt;cfloat&gt;
928 #include &lt;cinttypes&gt;
929 #include &lt;ciso646&gt;
930 #include &lt;climits&gt;
931 #include &lt;clocale&gt;
932 #include &lt;cmath&gt;
933 #include &lt;csetjmp&gt;
934 #include &lt;csignal&gt;
935 #include &lt;cstdarg&gt;
936 #include &lt;cstdbool&gt;
937 #include &lt;cstddef&gt;
938 #include &lt;cstdint&gt;
939 #include &lt;cstdio&gt;
940 #include &lt;cstdlib&gt;
941 #include &lt;cstring&gt;
942 #include &lt;ctgmath&gt;
943 #include &lt;ctime&gt;
944 #include &lt;cwchar&gt;
945 #include &lt;cwctype&gt;
947 #include &lt;algorithm&gt;
948 #include &lt;array&gt;
949 #include &lt;bitset&gt;
950 #include &lt;complex&gt;
951 #include &lt;deque&gt;
952 #include &lt;exception&gt;
953 #include &lt;fstream&gt;
954 #include &lt;functional&gt;
955 #include &lt;iomanip&gt;
956 #include &lt;ios&gt;
957 #include &lt;iosfwd&gt;
958 #include &lt;iostream&gt;
959 #include &lt;istream&gt;
960 #include &lt;iterator&gt;
961 #include &lt;limits&gt;
962 #include &lt;list&gt;
963 #include &lt;locale&gt;
964 #include &lt;map&gt;
965 #include &lt;memory&gt;
966 #include &lt;new&gt;
967 #include &lt;numeric&gt;
968 #include &lt;ostream&gt;
969 #include &lt;queue&gt;
970 #include &lt;random&gt;
971 #include &lt;regex&gt;
972 #include &lt;set&gt;
973 #include &lt;sstream&gt;
974 #include &lt;stack&gt;
975 #include &lt;stdexcept&gt;
976 #include &lt;streambuf&gt;
977 #include &lt;string&gt;
978 #include &lt;tuple&gt;
979 #include &lt;typeinfo&gt;
980 #include &lt;type_traits&gt;
981 #include &lt;unordered_map&gt;
982 #include &lt;unordered_set&gt;
983 #include &lt;utility&gt;
984 #include &lt;valarray&gt;
985 #include &lt;vector&gt;
987 ac_cv_cxx_stdcxx_0x=yes, ac_cv_cxx_stdcxx_0x=no)
988 AC_LANG_RESTORE
989 CXXFLAGS="$ac_save_CXXFLAGS"
991 if test "$ac_cv_cxx_stdcxx_0x" = yes; then
992 AC_DEFINE(STDCXX_0X_HEADERS,,[Define if ISO C++ 0x header files are present. ])
995 </pre>
997 <p>As is the case for TR1 support, these autoconf macros can be made for a finer-grained, per-header-file check. For &lt;unordered_map&gt;
998 </p>
1000 <pre style="background: #c0c0c0">
1002 # AC_HEADER_UNORDERED_MAP
1003 AC_DEFUN([AC_HEADER_UNORDERED_MAP], [
1004 AC_CACHE_CHECK(for unordered_map,
1005 ac_cv_cxx_unordered_map,
1006 [AC_REQUIRE([AC_COMPILE_STDCXX_0X])
1007 AC_LANG_SAVE
1008 AC_LANG_CPLUSPLUS
1009 ac_save_CXXFLAGS="$CXXFLAGS"
1010 CXXFLAGS="$CXXFLAGS -std=gnu++0x"
1011 AC_TRY_COMPILE([#include &lt;unordered_map&gt;], [using std::unordered_map;],
1012 ac_cv_cxx_unordered_map=yes, ac_cv_cxx_unordered_map=no)
1013 CXXFLAGS="$ac_save_CXXFLAGS"
1014 AC_LANG_RESTORE
1016 if test "$ac_cv_cxx_unordered_map" = yes; then
1017 AC_DEFINE(HAVE_UNORDERED_MAP,,[Define if unordered_map is present. ])
1020 </pre>
1022 <pre style="background: #c0c0c0">
1023 # AC_HEADER_UNORDERED_SET
1024 AC_DEFUN([AC_HEADER_UNORDERED_SET], [
1025 AC_CACHE_CHECK(for unordered_set,
1026 ac_cv_cxx_unordered_set,
1027 [AC_REQUIRE([AC_COMPILE_STDCXX_0X])
1028 AC_LANG_SAVE
1029 AC_LANG_CPLUSPLUS
1030 ac_save_CXXFLAGS="$CXXFLAGS"
1031 CXXFLAGS="$CXXFLAGS -std=gnu++0x"
1032 AC_TRY_COMPILE([#include &lt;unordered_set&gt;], [using std::unordered_set;],
1033 ac_cv_cxx_unordered_set=yes, ac_cv_cxx_unordered_set=no)
1034 CXXFLAGS="$ac_save_CXXFLAGS"
1035 AC_LANG_RESTORE
1037 if test "$ac_cv_cxx_unordered_set" = yes; then
1038 AC_DEFINE(HAVE_UNORDERED_SET,,[Define if unordered_set is present. ])
1041 </pre>
1044 <h5>
1045 Container iterator_type is not necessarily container value_type*
1046 </h5>
1049 <hr />
1050 <h3 class="left">
1051 <a name="v4">Fourth, and future</a>
1052 </h3>
1054 <hr />
1055 <h3 class="left">
1056 <a name="Links">Links</a>
1057 </h3>
1060 <a href="http://www.kegel.com/gcc/gcc4.html">Migrating to gcc-4.1</a>, by Dan Kegel.
1061 </p>
1064 <a href="http://lists.debian.org/debian-gcc/2006/03/msg00405.html">Building the whole Debian archive with GCC 4.1: a summary</a>, by Martin Michlmayr
1065 </p>
1068 <a href="http://annwm.lbl.gov/~leggett/Atlas/gcc-3.2.html">Migration guide for GCC-3.2</a>
1069 </p>
1071 </body>
1072 </html>