4312e020f1
2008-01-18 Benjamin Kosnik <bkoz@redhat.com> * docs/*: To... * doc/*: ...here. * testsuite/Makefile.am: Move doc-performance to... * Makefile.am: Add doc to SUBDIRS, move doxygen-* rules to... * doc/Makefile.am: Consolidate documentation creation here. (doc-doxygen-html): New. (doc-doxygen-man): New. (doc-performance): New. * doc/Makefile.in: New. * acinclude.m4 (glibcxx_SUBDIRS): Add doc directory. * doc/doxygen/guide.html: Edit for unified html configuration. * doc/doxygen/mainpage.html: Same. * doc/doxygen/run_doxygen: Same, more namespace fixups for man generation. * doc/doxygen/user.cfg.in: Update for doxygen 1.5.4. * include/tr1_impl/random: Remove maint from doxygen markup. * include/tr1_impl/functional: Same. * include/std/tuple: Same. * include/std/streambuf: Same. * include/std/bitset: Same. * include/std/limits: Same. * include/std/fstream: Same. * include/std/istream: Same. * include/std/sstream: Same. * include/ext/pool_allocator.h: Same. * include/ext/rc_string_base.h: Same. * include/bits/basic_ios.h: Same. * include/bits/stl_list.h: Same. * include/bits/stl_map.h: Same. * include/bits/locale_classes.h: Same. * include/bits/stl_set.h: Same. * include/bits/stl_iterator_base_types.h: Same. * include/bits/basic_string.h: Same. * include/bits/stl_multimap.h: Same. * include/bits/stl_vector.h: Same. * include/bits/ios_base.h: Same. * include/bits/stl_deque.h: Same. * include/bits/postypes.h: Same. * include/bits/stl_multiset.h: Same. * include/bits/stl_algo.h: Same. * include/bits/stl_iterator.h: Same. * include/bits/stl_tempbuf.h: Same. * include/bits/stl_construct.h: Same. * include/bits/stl_relops.h: Same. * include/tr1/tuple: Same. * include/backward/auto_ptr.h: Same. * testsuite/23_containers/vector/requirements/dr438/assign_neg.cc: Fixups for line number changes. * testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: Same. * testsuite/23_containers/vector/requirements/dr438/ constructor_1_neg.cc: Same. * testsuite/23_containers/vector/requirements/dr438/ constructor_2_neg.cc: Same. * testsuite/23_containers/deque/requirements/dr438/assign_neg.cc: Same. * testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: Same. * testsuite/23_containers/deque/requirements/dr438/ constructor_1_neg.cc: Same. * testsuite/23_containers/deque/requirements/dr438/ constructor_2_neg.cc: Same. * testsuite/23_containers/list/requirements/dr438/assign_neg.cc: Same. * testsuite/23_containers/list/requirements/dr438/insert_neg.cc: Same. * testsuite/23_containers/list/requirements/dr438/ constructor_1_neg.cc: Same. * testsuite/23_containers/list/requirements/dr438/ constructor_2_neg.cc: Same. * testsuite/20_util/auto_ptr/assign_neg.cc: Same. * aclocal.m4: Regenerate. * config.h.in: Regenerate. * configure: Regenerate. * Makefile.in: Regenerate. * src/Makefile.in: Regenerate. * po/Makefile.in: Regenerate. * libmath/Makefile.in: Regenerate. * include/Makefile.in: Regenerate. * libsupc++/Makefile.in: Regenerate. * testsuite/Makefile.in: Regenerate. * scripts/make_graphs.py: Correct paths for new layout. 2008-01-17 Benjamin Kosnik <bkoz@redhat.com> * acinclude.m4 (AC_LC_MESSAGES): Remove serial. * linkage.m4 (AC_REPLACE_MATHFUNCS): Same. * configure: Regenerate. * aclocal.m4: Regenerate. From-SVN: r131625
1074 lines
30 KiB
HTML
1074 lines
30 KiB
HTML
<?xml version="1.0" encoding="ISO-8859-1"?>
|
|
<!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" xml:lang="en" lang="en">
|
|
<head>
|
|
<meta name="AUTHOR" content="bkoz@gcc.gnu.org (Benjamin Kosnik), Felix Natter" />
|
|
<meta name="KEYWORDS" content="C++, libstdc++, API, backward, compatibility" />
|
|
<meta name="DESCRIPTION" content="Backwards Compatibility" />
|
|
<meta name="GENERATOR" content="emacs and ten fingers" />
|
|
<title>Backwards Compatibility</title>
|
|
<link rel="StyleSheet" href="lib3styles.css" type="text/css" />
|
|
<link rel="Start" href="documentation.html" type="text/html"
|
|
title="GNU C++ Standard Library" />
|
|
<link rel="Copyright" href="17_intro/license.html" type="text/html" />
|
|
</head>
|
|
<body>
|
|
|
|
<h1 class="centered"><a name="top">Backwards Compatibility</a></h1>
|
|
|
|
<p class="fineprint"><em>
|
|
The latest version of this document is always available at
|
|
<a href="http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/backwards_compatibility.html">
|
|
http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/backwards_compatibility.html</a>.
|
|
</em></p>
|
|
|
|
<p><em>
|
|
To the <a href="http://gcc.gnu.org/libstdc++/">libstdc++ homepage</a>.
|
|
</em></p>
|
|
|
|
<!-- ####################################################### -->
|
|
<hr />
|
|
<h3 class="left">
|
|
<a name="v1">First.</a>
|
|
</h3>
|
|
|
|
<p> The first generation GNU C++ library was called libg++. It was a
|
|
separate GNU project, although reliably paired with GCC. Rumors imply
|
|
that it had a working relationship with at least two kinds of
|
|
dinosaur.
|
|
</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>
|
|
|
|
<h5>No <code>ios_base</code></h5>
|
|
|
|
<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>.
|
|
</p>
|
|
|
|
<h5>No <code>cout</code> in <code>ostream.h</code>, no <code>cin</code> in <code>istream.h</code></h5>
|
|
|
|
<p>
|
|
In earlier versions of the standard,
|
|
<tt><fstream.h></tt>,
|
|
<tt><ostream.h></tt>
|
|
and <tt><istream.h></tt>
|
|
used to define
|
|
<code>cout</code>, <code>cin</code> and so on. ISO C++ specifies that one needs to include
|
|
<tt><iostream></tt>
|
|
explicitly to get the required definitions.
|
|
</p>
|
|
<p> Some include adjustment may be required.</p>
|
|
|
|
|
|
<p>This project is no longer maintained or supported, and the sources
|
|
archived. The code is considered replaced and rewritten.
|
|
</p>
|
|
|
|
<hr />
|
|
<h3 class="left">
|
|
<a name="v2">Second.</a>
|
|
</h3>
|
|
<p> The second generation GNU C++ library was called libstdc++, or
|
|
libstdc++-v2. It spans the time between libg++ and pre-ISO C++
|
|
standardization and is usually associated with the following GCC
|
|
releases: egcs 1.x, gcc 2.95, and gcc 2.96.
|
|
</p>
|
|
|
|
<p> The STL portions of this library are based on SGI/HP STL release 3.11.
|
|
</p>
|
|
|
|
<p>Portability notes and known implementation limitations are as follows.</p>
|
|
|
|
<h5>Namespace <code>std::</code> not supported</h5>
|
|
|
|
<p>
|
|
Some care is required to support C++ compiler and or library
|
|
implementation that do not have the standard library in
|
|
<code>namespace std</code>.
|
|
</p>
|
|
<p>
|
|
The following sections list some possible solutions to support compilers
|
|
that cannot ignore <code>std::</code>-qualified names.
|
|
</p>
|
|
|
|
<p> First, see if the compiler has a flag for this. Namespace
|
|
back-portability-issues are generally not a problem for g++
|
|
compilers that do not have libstdc++ in <code>std::</code>, as
|
|
the compilers use <code>-fno-honor-std</code> (ignore
|
|
<code>std::</code>, <code>:: = std::</code>) by default. That
|
|
is, the responsibility for enabling or disabling
|
|
<code>std::</code> is on the user; the maintainer does not have
|
|
to care about it. This probably applies to some other compilers
|
|
as well.
|
|
</p>
|
|
|
|
<p>Second, experiment with a variety of pre-processor tricks.</p>
|
|
|
|
<p> By defining <code>std</code> as a macro, fully-qualified namespace calls become global. Volia. </p>
|
|
|
|
<pre>
|
|
#ifdef WICKEDLY_OLD_COMPILER
|
|
# define std
|
|
#endif
|
|
</pre>
|
|
(thanks to Juergen Heinzl who posted this solution on gnu.gcc.help)
|
|
|
|
<p>Another pre-processor based approach is to define a
|
|
macro <code>NAMESPACE_STD</code>, which is defined to either
|
|
"" or "std" based on a compile-type test. On GNU
|
|
systems, this can be done with autotools by means of an autoconf test
|
|
(see below) for <code>HAVE_NAMESPACE_STD</code>, then using that to
|
|
set a value for the <code>NAMESPACE_STD</code> macro. At that point,
|
|
one is able to use <code>NAMESPACE_STD::string</code>, which will
|
|
evaluate to <code>std::string</code> or
|
|
<code>::string</code> (ie, in the global namespace on systems that do
|
|
not put <code>string</code> in <code>std::</code>). </p>
|
|
|
|
<pre style="background: #c0c0c0">
|
|
dnl @synopsis AC_CXX_NAMESPACE_STD
|
|
dnl
|
|
dnl If the compiler supports namespace std, define
|
|
dnl HAVE_NAMESPACE_STD.
|
|
dnl
|
|
dnl @category Cxx
|
|
dnl @author Todd Veldhuizen
|
|
dnl @author Luc Maisonobe <luc@spaceroots.org>
|
|
dnl @version 2004-02-04
|
|
dnl @license AllPermissive
|
|
AC_DEFUN([AC_CXX_NAMESPACE_STD], [
|
|
AC_CACHE_CHECK(if g++ supports namespace std,
|
|
ac_cv_cxx_have_std_namespace,
|
|
[AC_LANG_SAVE
|
|
AC_LANG_CPLUSPLUS
|
|
AC_TRY_COMPILE([#include <iostream>
|
|
std::istream& is = std::cin;],,
|
|
ac_cv_cxx_have_std_namespace=yes, ac_cv_cxx_have_std_namespace=no)
|
|
AC_LANG_RESTORE
|
|
])
|
|
if test "$ac_cv_cxx_have_std_namespace" = yes; then
|
|
AC_DEFINE(HAVE_NAMESPACE_STD,,[Define if g++ supports namespace std. ])
|
|
fi
|
|
])
|
|
</pre>
|
|
|
|
<h5>Illegal iterator usage</h5>
|
|
<p>
|
|
The following illustrate implementation-allowed illegal iterator
|
|
use, and then correct use.
|
|
</p>
|
|
|
|
<ul> <li><p>you cannot do
|
|
<code>ostream::operator<<(iterator)</code> to print the
|
|
address of the iterator => use <code>operator<<
|
|
&*iterator</code> instead
|
|
</p></li>
|
|
<li><p>you cannot clear an iterator's reference
|
|
(<code>iterator = 0</code>) => use
|
|
<code>iterator = iterator_type();</code>
|
|
</p></li>
|
|
<li><p>
|
|
<code>if (iterator)</code> won't work any
|
|
more => use <code>if (iterator != iterator_type())</code>
|
|
</p></li>
|
|
</ul>
|
|
|
|
<h5><code>isspace</code> from <tt><cctype></tt> is a macro
|
|
</h5>
|
|
|
|
<p> Glibc 2.0.x and 2.1.x define <tt><ctype.h></tt>
|
|
functionality as macros (isspace, isalpha etc.).
|
|
</p>
|
|
|
|
<p>
|
|
This implementations of libstdc++, however, keep these functions as
|
|
macros, and so it is not back-portable to use fully qualified
|
|
names. For example:
|
|
</p>
|
|
|
|
<pre>
|
|
#include <cctype>
|
|
int main() { std::isspace('X'); }
|
|
</pre>
|
|
|
|
<p>Results in something like this:
|
|
</p>
|
|
|
|
<pre>
|
|
std:: (__ctype_b[(int) ( ( 'X' ) )] & (unsigned short int) _ISspace ) ;
|
|
</pre>
|
|
|
|
|
|
<p> A solution is to modify a header-file so that the compiler tells
|
|
<tt><ctype.h></tt> to define functions instead of macros:
|
|
</p>
|
|
|
|
<pre>
|
|
// This keeps isalnum, et al from being propagated as macros.
|
|
#if __linux__
|
|
# define __NO_CTYPE 1
|
|
#endif
|
|
</pre>
|
|
|
|
<p>Then, include <ctype.h>
|
|
</p>
|
|
|
|
<p>
|
|
Another problem arises if you put a <code>using namespace std;</code>
|
|
declaration at the top, and include <tt><ctype.h></tt>. This
|
|
will result in ambiguities between the definitions in the global
|
|
namespace (<tt><ctype.h></tt>) and the definitions in namespace
|
|
<code>std::</code> (<code><cctype></code>).
|
|
</p>
|
|
|
|
<h5>No <code>vector::at</code>, <code>deque::at</code>, <code>string::at</code></h5>
|
|
|
|
<p>
|
|
One solution is to add an autoconf-test for this:
|
|
</p>
|
|
<pre style="background: #c0c0c0">
|
|
AC_MSG_CHECKING(for container::at)
|
|
AC_TRY_COMPILE(
|
|
[
|
|
#include <vector>
|
|
#include <deque>
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
],
|
|
[
|
|
deque<int> test_deque(3);
|
|
test_deque.at(2);
|
|
vector<int> test_vector(2);
|
|
test_vector.at(1);
|
|
string test_string("test_string");
|
|
test_string.at(3);
|
|
],
|
|
[AC_MSG_RESULT(yes)
|
|
AC_DEFINE(HAVE_CONTAINER_AT)],
|
|
[AC_MSG_RESULT(no)])
|
|
</pre>
|
|
|
|
<p>
|
|
If you are using other (non-GNU) compilers it might be a good idea
|
|
to check for <code>string::at</code> separately.
|
|
</p>
|
|
|
|
<h5>No <code>std::char_traits<char>::eof</code></h5>
|
|
|
|
<p>
|
|
Use some kind of autoconf test, plus this:
|
|
</p>
|
|
<pre>
|
|
#ifdef HAVE_CHAR_TRAITS
|
|
#define CPP_EOF std::char_traits<char>::eof()
|
|
#else
|
|
#define CPP_EOF EOF
|
|
#endif
|
|
</pre>
|
|
|
|
<h5>No <code>string::clear</code></h5>
|
|
|
|
<p>
|
|
There are two functions for deleting the contents of a string:
|
|
<code>clear</code> and <code>erase</code> (the latter
|
|
returns the string).
|
|
</p>
|
|
|
|
<pre>
|
|
void
|
|
clear() { _M_mutate(0, this->size(), 0); }
|
|
</pre>
|
|
<pre>
|
|
basic_string&
|
|
erase(size_type __pos = 0, size_type __n = npos)
|
|
{
|
|
return this->replace(_M_check(__pos), _M_fold(__pos, __n),
|
|
_M_data(), _M_data());
|
|
}
|
|
</pre>
|
|
|
|
<p>
|
|
Unfortunately, ut <code>clear</code> is not
|
|
implemented in this version, so you should use
|
|
<code>erase</code> (which is probably faster than
|
|
<code>operator=(charT*)</code>).
|
|
</p>
|
|
|
|
<h5>Removal of <code>ostream::form</code> and
|
|
<code>istream::scan</code> extensions</h5>
|
|
|
|
<p> These are no longer supported. Please use
|
|
<a href="#sec-stringstream" title="Using stringstreams">
|
|
stringstreams</a> instead.
|
|
</p>
|
|
|
|
<h5>No <code>basic_stringbuf</code>, <code>basic_stringstream</code></h5>
|
|
|
|
<p>
|
|
Although the ISO standard
|
|
<code>i/ostringstream</code>-classes are provided, (<tt><sstream></tt>), for compatibility with older implementations the pre-ISO <code>i/ostrstream</code> (<tt><strstream></tt>) interface is also provided, with these caveats:
|
|
</p>
|
|
|
|
<div class="itemizedlist"><ul type="disc">
|
|
<li><p> <code>strstream</code> is considered to be
|
|
deprecated
|
|
</p></li>
|
|
<li><p> <code>strstream</code> is limited to
|
|
<code>char</code>
|
|
</p></li>
|
|
<li><p> with <code>ostringstream</code> you don't
|
|
have to take care of terminating the string or freeing its
|
|
memory
|
|
</p></li>
|
|
<li><p> <code>istringstream</code> can be re-filled
|
|
(clear(); str(input);)
|
|
</p></li>
|
|
</ul></div>
|
|
<p>
|
|
You can then use output-stringstreams like this:
|
|
</p>
|
|
|
|
<pre>
|
|
#ifdef HAVE_SSTREAM
|
|
# include <sstream>
|
|
#else
|
|
# include <strstream>
|
|
#endif
|
|
|
|
#ifdef HAVE_SSTREAM
|
|
std::ostringstream oss;
|
|
#else
|
|
std::ostrstream oss;
|
|
#endif
|
|
|
|
oss << "Name=" << m_name << ", number=" << m_number << std::endl;
|
|
...
|
|
#ifndef HAVE_SSTREAM
|
|
oss << std::ends; // terminate the char*-string
|
|
#endif
|
|
|
|
// str() returns char* for ostrstream and a string for ostringstream
|
|
// this also causes ostrstream to think that the buffer's memory
|
|
// is yours
|
|
m_label.set_text(oss.str());
|
|
#ifndef HAVE_SSTREAM
|
|
// let the ostrstream take care of freeing the memory
|
|
oss.freeze(false);
|
|
#endif
|
|
</pre>
|
|
|
|
<p>
|
|
Input-stringstreams can be used similarly:
|
|
</p>
|
|
|
|
<pre>
|
|
std::string input;
|
|
...
|
|
#ifdef HAVE_SSTREAM
|
|
std::istringstream iss(input);
|
|
#else
|
|
std::istrstream iss(input.c_str());
|
|
#endif
|
|
|
|
int i;
|
|
iss >> i;
|
|
</pre>
|
|
|
|
<p> One (the only?) restriction is that an istrstream cannot be re-filled:
|
|
</p>
|
|
|
|
<pre>
|
|
std::istringstream iss(numerator);
|
|
iss >> m_num;
|
|
// this is not possible with istrstream
|
|
iss.clear();
|
|
iss.str(denominator);
|
|
iss >> m_den;
|
|
</pre>
|
|
|
|
<p>
|
|
If you don't care about speed, you can put these conversions in
|
|
a template-function:
|
|
</p>
|
|
<pre>
|
|
template <class X>
|
|
void fromString(const string& input, X& any)
|
|
{
|
|
#ifdef HAVE_SSTREAM
|
|
std::istringstream iss(input);
|
|
#else
|
|
std::istrstream iss(input.c_str());
|
|
#endif
|
|
X temp;
|
|
iss >> temp;
|
|
if (iss.fail())
|
|
throw runtime_error(..)
|
|
any = temp;
|
|
}
|
|
</pre>
|
|
|
|
<p> Another example of using stringstreams is in <a href="../21_strings/howto.html" target="_top">this howto</a>.
|
|
</p>
|
|
|
|
<p> There is additional information in the libstdc++-v2 info files, in
|
|
particular "info iostream".
|
|
</p>
|
|
|
|
<h5>Little or no wide character support</h5>
|
|
|
|
<h5>No templatized iostreams</h5>
|
|
|
|
<h5>Thread safety issues</h5>
|
|
|
|
<p>This project is no longer maintained or supported, and the sources
|
|
archived. The code is considered replaced and rewritten.
|
|
</p>
|
|
|
|
|
|
<hr />
|
|
<h3 class="left">
|
|
<a name="v3">Third.</a>
|
|
</h3>
|
|
<p> The third generation GNU C++ library is called libstdc++, or
|
|
libstdc++-v3.
|
|
</p>
|
|
|
|
<p>The subset commonly known as the Standard Template Library
|
|
(chapters 23 through 25, mostly) is adapted from the final release
|
|
of the SGI STL (version 3.3), with extensive changes.
|
|
</p>
|
|
|
|
<p>A more formal description of the V3 goals can be found in the
|
|
official <a href="../17_intro/DESIGN">design document</a>.
|
|
</p>
|
|
|
|
<p>Portability notes and known implementation limitations are as follows.</p>
|
|
|
|
<h5>Pre-ISO headers moved to backwards or removed</h5>
|
|
|
|
<p> The pre-ISO C++ headers
|
|
(<code>iostream.h</code>, <code>defalloc.h</code> etc.) are
|
|
available, unlike previous libstdc++ versions, but inclusion
|
|
generates a warning that you are using deprecated headers.
|
|
</p>
|
|
|
|
<p>This compatibility layer is constructed by including the
|
|
standard C++ headers, and injecting any items in
|
|
<code>std::</code> into the global namespace.
|
|
</p>
|
|
<p>For those of you new to ISO C++ (welcome, time travelers!), no,
|
|
that isn't a typo. Yes, the headers really have new names.
|
|
Marshall Cline's C++ FAQ Lite has a good explanation in <a
|
|
href="http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4">item
|
|
[27.4]</a>.
|
|
</p>
|
|
|
|
<p> Some include adjustment may be required. What follows is an
|
|
autoconf test that defines <code>PRE_STDCXX_HEADERS</code> when they
|
|
exist.</p>
|
|
|
|
<pre style="background: #c0c0c0">
|
|
# AC_HEADER_PRE_STDCXX
|
|
AC_DEFUN([AC_HEADER_PRE_STDCXX], [
|
|
AC_CACHE_CHECK(for pre-ISO C++ include files,
|
|
ac_cv_cxx_pre_stdcxx,
|
|
[AC_LANG_SAVE
|
|
AC_LANG_CPLUSPLUS
|
|
ac_save_CXXFLAGS="$CXXFLAGS"
|
|
CXXFLAGS="$CXXFLAGS -Wno-deprecated"
|
|
|
|
# Omit defalloc.h, as compilation with newer compilers is problematic.
|
|
AC_TRY_COMPILE([
|
|
#include <new.h>
|
|
#include <iterator.h>
|
|
#include <alloc.h>
|
|
#include <set.h>
|
|
#include <hashtable.h>
|
|
#include <hash_set.h>
|
|
#include <fstream.h>
|
|
#include <tempbuf.h>
|
|
#include <istream.h>
|
|
#include <bvector.h>
|
|
#include <stack.h>
|
|
#include <rope.h>
|
|
#include <complex.h>
|
|
#include <ostream.h>
|
|
#include <heap.h>
|
|
#include <iostream.h>
|
|
#include <function.h>
|
|
#include <multimap.h>
|
|
#include <pair.h>
|
|
#include <stream.h>
|
|
#include <iomanip.h>
|
|
#include <slist.h>
|
|
#include <tree.h>
|
|
#include <vector.h>
|
|
#include <deque.h>
|
|
#include <multiset.h>
|
|
#include <list.h>
|
|
#include <map.h>
|
|
#include <algobase.h>
|
|
#include <hash_map.h>
|
|
#include <algo.h>
|
|
#include <queue.h>
|
|
#include <streambuf.h>
|
|
],,
|
|
ac_cv_cxx_pre_stdcxx=yes, ac_cv_cxx_pre_stdcxx=no)
|
|
CXXFLAGS="$ac_save_CXXFLAGS"
|
|
AC_LANG_RESTORE
|
|
])
|
|
if test "$ac_cv_cxx_pre_stdcxx" = yes; then
|
|
AC_DEFINE(PRE_STDCXX_HEADERS,,[Define if pre-ISO C++ header files are present. ])
|
|
fi
|
|
])
|
|
</pre>
|
|
|
|
<p>Porting between pre-ISO headers and ISO headers is simple: headers
|
|
like <vector.h> can be replaced with <vector> and a using
|
|
directive <code>using namespace std;</code> can be put at the global
|
|
scope. This should be enough to get this code compiling, assuming the
|
|
other usage is correct.
|
|
</p>
|
|
|
|
<h5>Extension headers hash_map, hash_set moved to ext or backwards</h5>
|
|
|
|
<p> Header files <code>hash_map</code> and <code>hash_set</code> moved
|
|
to <code>ext/hash_map</code> and <code>ext/hash_set</code>,
|
|
respectively. At the same time, all types in these files are enclosed
|
|
in <code>namespace __gnu_cxx</code>. Later versions move deprecate
|
|
these files, and suggest using TR1's <code>unordered_map</code>
|
|
and <code>unordered_set</code> instead.
|
|
</p>
|
|
|
|
<p>The following autoconf tests check for working HP/SGI hash containers.
|
|
</p>
|
|
|
|
<pre style="background: #c0c0c0">
|
|
# AC_HEADER_EXT_HASH_MAP
|
|
AC_DEFUN([AC_HEADER_EXT_HASH_MAP], [
|
|
AC_CACHE_CHECK(for ext/hash_map,
|
|
ac_cv_cxx_ext_hash_map,
|
|
[AC_LANG_SAVE
|
|
AC_LANG_CPLUSPLUS
|
|
ac_save_CXXFLAGS="$CXXFLAGS"
|
|
CXXFLAGS="$CXXFLAGS -Werror"
|
|
AC_TRY_COMPILE([#include <ext/hash_map>], [using __gnu_cxx::hash_map;],
|
|
ac_cv_cxx_ext_hash_map=yes, ac_cv_cxx_ext_hash_map=no)
|
|
CXXFLAGS="$ac_save_CXXFLAGS"
|
|
AC_LANG_RESTORE
|
|
])
|
|
if test "$ac_cv_cxx_ext_hash_map" = yes; then
|
|
AC_DEFINE(HAVE_EXT_HASH_MAP,,[Define if ext/hash_map is present. ])
|
|
fi
|
|
])
|
|
</pre>
|
|
|
|
<pre style="background: #c0c0c0">
|
|
# AC_HEADER_EXT_HASH_SET
|
|
AC_DEFUN([AC_HEADER_EXT_HASH_SET], [
|
|
AC_CACHE_CHECK(for ext/hash_set,
|
|
ac_cv_cxx_ext_hash_set,
|
|
[AC_LANG_SAVE
|
|
AC_LANG_CPLUSPLUS
|
|
ac_save_CXXFLAGS="$CXXFLAGS"
|
|
CXXFLAGS="$CXXFLAGS -Werror"
|
|
AC_TRY_COMPILE([#include <ext/hash_set>], [using __gnu_cxx::hash_set;],
|
|
ac_cv_cxx_ext_hash_set=yes, ac_cv_cxx_ext_hash_set=no)
|
|
CXXFLAGS="$ac_save_CXXFLAGS"
|
|
AC_LANG_RESTORE
|
|
])
|
|
if test "$ac_cv_cxx_ext_hash_set" = yes; then
|
|
AC_DEFINE(HAVE_EXT_HASH_SET,,[Define if ext/hash_set is present. ])
|
|
fi
|
|
])
|
|
</pre>
|
|
|
|
|
|
<h5>
|
|
No <code>ios::nocreate/ios::noreplace</code>.
|
|
</h5>
|
|
|
|
<p> The existence of <code>ios::nocreate</code> being used for
|
|
input-streams has been confirmed, most probably because the author
|
|
thought it would be more correct to specify nocreate explicitly. So
|
|
it can be left out for input-streams.
|
|
</p>
|
|
|
|
<p>For output streams, "nocreate" is probably the default,
|
|
unless you specify <code>std::ios::trunc</code> ? To be safe, you can
|
|
open the file for reading, check if it has been opened, and then
|
|
decide whether you want to create/replace or not. To my knowledge,
|
|
even older implementations support <code>app</code>, <code>ate</code>
|
|
and <code>trunc</code> (except for <code>app</code> ?).
|
|
</p>
|
|
|
|
|
|
<h5>
|
|
No <code>stream::attach(int fd)</code>
|
|
</h5>
|
|
|
|
<p>
|
|
Phil Edwards writes: It was considered and rejected for the ISO
|
|
standard. Not all environments use file descriptors. Of those
|
|
that do, not all of them use integers to represent them.
|
|
</p>
|
|
|
|
<p>
|
|
For a portable solution (among systems which use
|
|
filedescriptors), you need to implement a subclass of
|
|
<code>std::streambuf</code> (or
|
|
<code>std::basic_streambuf<..></code>) which opens a file
|
|
given a descriptor, and then pass an instance of this to the
|
|
stream-constructor.
|
|
</p>
|
|
|
|
<p>
|
|
An extension is available that implements this.
|
|
<code><ext/stdio_filebuf.h></code> contains a derived class called
|
|
<a href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/class____gnu__cxx_1_1stdio__filebuf.html"><code>__gnu_cxx::stdio_filebuf</code></a>.
|
|
This class can be constructed from a C <code>FILE*</code> or a file
|
|
descriptor, and provides the <code>fd()</code> function.
|
|
</p>
|
|
|
|
<p>
|
|
For another example of this, refer to
|
|
<a href="http://www.josuttis.com/cppcode/fdstream.html" target="_top">fdstream example</a>
|
|
by Nicolai Josuttis.
|
|
</p>
|
|
|
|
<h5>
|
|
Support for C++98 dialect.
|
|
</h5>
|
|
|
|
<p>Check for complete library coverage of the C++1998/2003 standard.
|
|
</p>
|
|
|
|
<pre style="background: #c0c0c0">
|
|
|
|
# AC_HEADER_STDCXX_98
|
|
AC_DEFUN([AC_HEADER_STDCXX_98], [
|
|
AC_CACHE_CHECK(for ISO C++ 98 include files,
|
|
ac_cv_cxx_stdcxx_98,
|
|
[AC_LANG_SAVE
|
|
AC_LANG_CPLUSPLUS
|
|
AC_TRY_COMPILE([
|
|
#include <cassert>
|
|
#include <cctype>
|
|
#include <cerrno>
|
|
#include <cfloat>
|
|
#include <ciso646>
|
|
#include <climits>
|
|
#include <clocale>
|
|
#include <cmath>
|
|
#include <csetjmp>
|
|
#include <csignal>
|
|
#include <cstdarg>
|
|
#include <cstddef>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <ctime>
|
|
|
|
#include <algorithm>
|
|
#include <bitset>
|
|
#include <complex>
|
|
#include <deque>
|
|
#include <exception>
|
|
#include <fstream>
|
|
#include <functional>
|
|
#include <iomanip>
|
|
#include <ios>
|
|
#include <iosfwd>
|
|
#include <iostream>
|
|
#include <istream>
|
|
#include <iterator>
|
|
#include <limits>
|
|
#include <list>
|
|
#include <locale>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <new>
|
|
#include <numeric>
|
|
#include <ostream>
|
|
#include <queue>
|
|
#include <set>
|
|
#include <sstream>
|
|
#include <stack>
|
|
#include <stdexcept>
|
|
#include <streambuf>
|
|
#include <string>
|
|
#include <typeinfo>
|
|
#include <utility>
|
|
#include <valarray>
|
|
#include <vector>
|
|
],,
|
|
ac_cv_cxx_stdcxx_98=yes, ac_cv_cxx_stdcxx_98=no)
|
|
AC_LANG_RESTORE
|
|
])
|
|
if test "$ac_cv_cxx_stdcxx_98" = yes; then
|
|
AC_DEFINE(STDCXX_98_HEADERS,,[Define if ISO C++ 1998 header files are present. ])
|
|
fi
|
|
])
|
|
</pre>
|
|
|
|
|
|
<h5>
|
|
Support for C++TR1 dialect.
|
|
</h5>
|
|
|
|
<p>Check for library coverage of the TR1 standard.
|
|
</p>
|
|
|
|
<pre style="background: #c0c0c0">
|
|
|
|
# AC_HEADER_STDCXX_TR1
|
|
AC_DEFUN([AC_HEADER_STDCXX_TR1], [
|
|
AC_CACHE_CHECK(for ISO C++ TR1 include files,
|
|
ac_cv_cxx_stdcxx_tr1,
|
|
[AC_LANG_SAVE
|
|
AC_LANG_CPLUSPLUS
|
|
AC_TRY_COMPILE([
|
|
#include <tr1/array>
|
|
#include <tr1/ccomplex>
|
|
#include <tr1/cctype>
|
|
#include <tr1/cfenv>
|
|
#include <tr1/cfloat>
|
|
#include <tr1/cinttypes>
|
|
#include <tr1/climits>
|
|
#include <tr1/cmath>
|
|
#include <tr1/complex>
|
|
#include <tr1/cstdarg>
|
|
#include <tr1/cstdbool>
|
|
#include <tr1/cstdint>
|
|
#include <tr1/cstdio>
|
|
#include <tr1/cstdlib>
|
|
#include <tr1/ctgmath>
|
|
#include <tr1/ctime>
|
|
#include <tr1/cwchar>
|
|
#include <tr1/cwctype>
|
|
#include <tr1/functional>
|
|
#include <tr1/memory>
|
|
#include <tr1/random>
|
|
#include <tr1/regex>
|
|
#include <tr1/tuple>
|
|
#include <tr1/type_traits>
|
|
#include <tr1/unordered_set>
|
|
#include <tr1/unordered_map>
|
|
#include <tr1/utility>
|
|
],,
|
|
ac_cv_cxx_stdcxx_tr1=yes, ac_cv_cxx_stdcxx_tr1=no)
|
|
AC_LANG_RESTORE
|
|
])
|
|
if test "$ac_cv_cxx_stdcxx_tr1" = yes; then
|
|
AC_DEFINE(STDCXX_TR1_HEADERS,,[Define if ISO C++ TR1 header files are present. ])
|
|
fi
|
|
])
|
|
</pre>
|
|
|
|
<p>An alternative is to check just for specific TR1 includes, such as <unordered_map> and <unordered_set>.
|
|
</p>
|
|
|
|
<pre style="background: #c0c0c0">
|
|
# AC_HEADER_TR1_UNORDERED_MAP
|
|
AC_DEFUN([AC_HEADER_TR1_UNORDERED_MAP], [
|
|
AC_CACHE_CHECK(for tr1/unordered_map,
|
|
ac_cv_cxx_tr1_unordered_map,
|
|
[AC_LANG_SAVE
|
|
AC_LANG_CPLUSPLUS
|
|
AC_TRY_COMPILE([#include <tr1/unordered_map>], [using std::tr1::unordered_map;],
|
|
ac_cv_cxx_tr1_unordered_map=yes, ac_cv_cxx_tr1_unordered_map=no)
|
|
AC_LANG_RESTORE
|
|
])
|
|
if test "$ac_cv_cxx_tr1_unordered_map" = yes; then
|
|
AC_DEFINE(HAVE_TR1_UNORDERED_MAP,,[Define if tr1/unordered_map is present. ])
|
|
fi
|
|
])
|
|
</pre>
|
|
|
|
<pre style="background: #c0c0c0">
|
|
# AC_HEADER_TR1_UNORDERED_SET
|
|
AC_DEFUN([AC_HEADER_TR1_UNORDERED_SET], [
|
|
AC_CACHE_CHECK(for tr1/unordered_set,
|
|
ac_cv_cxx_tr1_unordered_set,
|
|
[AC_LANG_SAVE
|
|
AC_LANG_CPLUSPLUS
|
|
AC_TRY_COMPILE([#include <tr1/unordered_set>], [using std::tr1::unordered_set;],
|
|
ac_cv_cxx_tr1_unordered_set=yes, ac_cv_cxx_tr1_unordered_set=no)
|
|
AC_LANG_RESTORE
|
|
])
|
|
if test "$ac_cv_cxx_tr1_unordered_set" = yes; then
|
|
AC_DEFINE(HAVE_TR1_UNORDERED_SET,,[Define if tr1/unordered_set is present. ])
|
|
fi
|
|
])
|
|
</pre>
|
|
|
|
|
|
|
|
<h5>
|
|
Support for C++0x dialect.
|
|
</h5>
|
|
|
|
<p>Check for baseline language coverage in the compiler for the C++0xstandard.
|
|
</p>
|
|
|
|
<pre style="background: #c0c0c0">
|
|
# AC_COMPILE_STDCXX_OX
|
|
AC_DEFUN([AC_COMPILE_STDCXX_0X], [
|
|
AC_CACHE_CHECK(if g++ supports C++0x features without additional flags,
|
|
ac_cv_cxx_compile_cxx0x_native,
|
|
[AC_LANG_SAVE
|
|
AC_LANG_CPLUSPLUS
|
|
AC_TRY_COMPILE([
|
|
template <typename T>
|
|
struct check
|
|
{
|
|
static_assert(sizeof(int) <= sizeof(T), "not big enough");
|
|
};
|
|
|
|
typedef check<check<bool>> right_angle_brackets;
|
|
|
|
int a;
|
|
decltype(a) b;
|
|
|
|
typedef check<int> check_type;
|
|
check_type c;
|
|
check_type&& cr = c;],,
|
|
ac_cv_cxx_compile_cxx0x_native=yes, ac_cv_cxx_compile_cxx0x_native=no)
|
|
AC_LANG_RESTORE
|
|
])
|
|
|
|
AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x,
|
|
ac_cv_cxx_compile_cxx0x_cxx,
|
|
[AC_LANG_SAVE
|
|
AC_LANG_CPLUSPLUS
|
|
ac_save_CXXFLAGS="$CXXFLAGS"
|
|
CXXFLAGS="$CXXFLAGS -std=c++0x"
|
|
AC_TRY_COMPILE([
|
|
template <typename T>
|
|
struct check
|
|
{
|
|
static_assert(sizeof(int) <= sizeof(T), "not big enough");
|
|
};
|
|
|
|
typedef check<check<bool>> right_angle_brackets;
|
|
|
|
int a;
|
|
decltype(a) b;
|
|
|
|
typedef check<int> check_type;
|
|
check_type c;
|
|
check_type&& cr = c;],,
|
|
ac_cv_cxx_compile_cxx0x_cxx=yes, ac_cv_cxx_compile_cxx0x_cxx=no)
|
|
CXXFLAGS="$ac_save_CXXFLAGS"
|
|
AC_LANG_RESTORE
|
|
])
|
|
|
|
AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x,
|
|
ac_cv_cxx_compile_cxx0x_gxx,
|
|
[AC_LANG_SAVE
|
|
AC_LANG_CPLUSPLUS
|
|
ac_save_CXXFLAGS="$CXXFLAGS"
|
|
CXXFLAGS="$CXXFLAGS -std=gnu++0x"
|
|
AC_TRY_COMPILE([
|
|
template <typename T>
|
|
struct check
|
|
{
|
|
static_assert(sizeof(int) <= sizeof(T), "not big enough");
|
|
};
|
|
|
|
typedef check<check<bool>> right_angle_brackets;
|
|
|
|
int a;
|
|
decltype(a) b;
|
|
|
|
typedef check<int> check_type;
|
|
check_type c;
|
|
check_type&& cr = c;],,
|
|
ac_cv_cxx_compile_cxx0x_gxx=yes, ac_cv_cxx_compile_cxx0x_gxx=no)
|
|
CXXFLAGS="$ac_save_CXXFLAGS"
|
|
AC_LANG_RESTORE
|
|
])
|
|
|
|
if test "$ac_cv_cxx_compile_cxx0x_native" = yes ||
|
|
test "$ac_cv_cxx_compile_cxx0x_cxx" = yes ||
|
|
test "$ac_cv_cxx_compile_cxx0x_gxx" = yes; then
|
|
AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ])
|
|
fi
|
|
])
|
|
</pre>
|
|
|
|
|
|
<p>Check for library coverage of the C++0xstandard.
|
|
</p>
|
|
|
|
<pre style="background: #c0c0c0">
|
|
|
|
# AC_HEADER_STDCXX_0X
|
|
AC_DEFUN([AC_HEADER_STDCXX_0X], [
|
|
AC_CACHE_CHECK(for ISO C++ 0x include files,
|
|
ac_cv_cxx_stdcxx_0x,
|
|
[AC_REQUIRE([AC_COMPILE_STDCXX_0X])
|
|
AC_LANG_SAVE
|
|
AC_LANG_CPLUSPLUS
|
|
ac_save_CXXFLAGS="$CXXFLAGS"
|
|
CXXFLAGS="$CXXFLAGS -std=gnu++0x"
|
|
|
|
AC_TRY_COMPILE([
|
|
#include <cassert>
|
|
#include <ccomplex>
|
|
#include <cctype>
|
|
#include <cerrno>
|
|
#include <cfenv>
|
|
#include <cfloat>
|
|
#include <cinttypes>
|
|
#include <ciso646>
|
|
#include <climits>
|
|
#include <clocale>
|
|
#include <cmath>
|
|
#include <csetjmp>
|
|
#include <csignal>
|
|
#include <cstdarg>
|
|
#include <cstdbool>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <ctgmath>
|
|
#include <ctime>
|
|
#include <cwchar>
|
|
#include <cwctype>
|
|
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <bitset>
|
|
#include <complex>
|
|
#include <deque>
|
|
#include <exception>
|
|
#include <fstream>
|
|
#include <functional>
|
|
#include <iomanip>
|
|
#include <ios>
|
|
#include <iosfwd>
|
|
#include <iostream>
|
|
#include <istream>
|
|
#include <iterator>
|
|
#include <limits>
|
|
#include <list>
|
|
#include <locale>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <new>
|
|
#include <numeric>
|
|
#include <ostream>
|
|
#include <queue>
|
|
#include <random>
|
|
#include <regex>
|
|
#include <set>
|
|
#include <sstream>
|
|
#include <stack>
|
|
#include <stdexcept>
|
|
#include <streambuf>
|
|
#include <string>
|
|
#include <tuple>
|
|
#include <typeinfo>
|
|
#include <type_traits>
|
|
#include <unordered_map>
|
|
#include <unordered_set>
|
|
#include <utility>
|
|
#include <valarray>
|
|
#include <vector>
|
|
],,
|
|
ac_cv_cxx_stdcxx_0x=yes, ac_cv_cxx_stdcxx_0x=no)
|
|
AC_LANG_RESTORE
|
|
CXXFLAGS="$ac_save_CXXFLAGS"
|
|
])
|
|
if test "$ac_cv_cxx_stdcxx_0x" = yes; then
|
|
AC_DEFINE(STDCXX_0X_HEADERS,,[Define if ISO C++ 0x header files are present. ])
|
|
fi
|
|
])
|
|
</pre>
|
|
|
|
<p>As is the case for TR1 support, these autoconf macros can be made for a finer-grained, per-header-file check. For <unordered_map>
|
|
</p>
|
|
|
|
<pre style="background: #c0c0c0">
|
|
|
|
# AC_HEADER_UNORDERED_MAP
|
|
AC_DEFUN([AC_HEADER_UNORDERED_MAP], [
|
|
AC_CACHE_CHECK(for unordered_map,
|
|
ac_cv_cxx_unordered_map,
|
|
[AC_REQUIRE([AC_COMPILE_STDCXX_0X])
|
|
AC_LANG_SAVE
|
|
AC_LANG_CPLUSPLUS
|
|
ac_save_CXXFLAGS="$CXXFLAGS"
|
|
CXXFLAGS="$CXXFLAGS -std=gnu++0x"
|
|
AC_TRY_COMPILE([#include <unordered_map>], [using std::unordered_map;],
|
|
ac_cv_cxx_unordered_map=yes, ac_cv_cxx_unordered_map=no)
|
|
CXXFLAGS="$ac_save_CXXFLAGS"
|
|
AC_LANG_RESTORE
|
|
])
|
|
if test "$ac_cv_cxx_unordered_map" = yes; then
|
|
AC_DEFINE(HAVE_UNORDERED_MAP,,[Define if unordered_map is present. ])
|
|
fi
|
|
])
|
|
</pre>
|
|
|
|
<pre style="background: #c0c0c0">
|
|
# AC_HEADER_UNORDERED_SET
|
|
AC_DEFUN([AC_HEADER_UNORDERED_SET], [
|
|
AC_CACHE_CHECK(for unordered_set,
|
|
ac_cv_cxx_unordered_set,
|
|
[AC_REQUIRE([AC_COMPILE_STDCXX_0X])
|
|
AC_LANG_SAVE
|
|
AC_LANG_CPLUSPLUS
|
|
ac_save_CXXFLAGS="$CXXFLAGS"
|
|
CXXFLAGS="$CXXFLAGS -std=gnu++0x"
|
|
AC_TRY_COMPILE([#include <unordered_set>], [using std::unordered_set;],
|
|
ac_cv_cxx_unordered_set=yes, ac_cv_cxx_unordered_set=no)
|
|
CXXFLAGS="$ac_save_CXXFLAGS"
|
|
AC_LANG_RESTORE
|
|
])
|
|
if test "$ac_cv_cxx_unordered_set" = yes; then
|
|
AC_DEFINE(HAVE_UNORDERED_SET,,[Define if unordered_set is present. ])
|
|
fi
|
|
])
|
|
</pre>
|
|
|
|
|
|
<h5>
|
|
Container iterator_type is not necessarily container value_type*
|
|
</h5>
|
|
|
|
|
|
<hr />
|
|
<h3 class="left">
|
|
<a name="v4">Fourth, and future</a>
|
|
</h3>
|
|
|
|
<hr />
|
|
<h3 class="left">
|
|
<a name="Links">Links</a>
|
|
</h3>
|
|
|
|
<p>
|
|
<a href="http://www.kegel.com/gcc/gcc4.html">Migrating to gcc-4.1</a>, by Dan Kegel.
|
|
</p>
|
|
|
|
<p>
|
|
<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
|
|
</p>
|
|
|
|
<p>
|
|
<a href="http://annwm.lbl.gov/~leggett/Atlas/gcc-3.2.html">Migration guide for GCC-3.2</a>
|
|
</p>
|
|
|
|
</body>
|
|
</html>
|
|
|