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