summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/docs/html/17_intro/api.html
blob: 50c8604405aec0a8ad47d686f0bbb6ffea932ca1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
<?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, deprecate backward" />
   <meta name="DESCRIPTION" content="API evolution and deprecation history" />
   <meta name="GENERATOR" content="emacs and ten fingers" />
   <title>API Evolution and Deprecation History</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">API Evolution and Deprecation History</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/api.html">
   http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/abi.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="C++ API v1">First.</a>
</h3>

<p>2.72</p>
<p> The first generation GNU C++ library was called libg++. It had a
working relationship with at least two kinds of dinosaur. Sadly, the
details were not pried away from the estate.
</p>

<p>

</p>

<p>Known Issues include many of the limitations of its immediate ancestor.</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>&lt;fstream.h&gt;</tt>,
	<tt>&lt;ostream.h&gt;</tt>
	and <tt>&lt;istream.h&gt;</tt>
	used to define
	<code>cout</code>, <code>cin</code> and so on. ISO C++ specifies that one needs to include
	<tt>&lt;iostream&gt;</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="C++ API v1">Second.</a>
</h3>
<p> The second generation GNU C++ library was called libstdc++, or
libstdc++-v2. It was a separate GNU project, although reliably paired
with GCC. It spans the time between libg++ and pre-ISO C++.
</p>

<p>egcs 1.x</p>
<p>2.95</p>
<p>2.96</p>

<p>Portability Notes</p>
<p>Implementation Limitations</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. 
	      
<pre class="programlisting">
#ifdef WICKEDLY_OLD_COMPILER
# define std
#endif
</pre>
(thanks to Juergen Heinzl who posted this solution on gnu.gcc.help)

<p>Define a macro <code>NAMESPACE_STD</code>, which is defined to
either &quot;&quot; or &quot;std&quot; 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>

<p> 	
<pre>
dnl @synopsis AC_CXX_HAVE_STD_NAMESPACE
dnl
dnl If the compiler supports the std namespace, define
dnl HAVE_STD_NAMESPACE.
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_HAVE_STD_NAMESPACE],
[AC_CACHE_CHECK(whether the compiler supports the std namespace,
ac_cv_cxx_have_std_namespace,
[AC_LANG_SAVE
 AC_LANG_CPLUSPLUS
 AC_TRY_COMPILE([#include <iostream>
	std::istream& is = std::cin;
	],[return 0;],
 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_STD_NAMESPACE,,[define if the compiler supports the std namespace])
fi
])
</pre>

<h5>Illegal iterator usage.</h5>
<p>
      The following illustrate implementation-allowed illegal iterator
      use, and then correct use.  <div class="itemizedlist"><ul
      type="disc"> <li><p>you cannot do
      <code>ostream::operator&lt;&lt;(iterator)</code> to print the
      address of the iterator =&gt; use <code>operator&lt;&lt;
      &amp;*iterator</code> instead ?
	  </p></li>
<li><p>you cannot clear an iterator's reference
	    (<code>iterator = 0</code>) =&gt; use
	    <code>iterator = iterator_type();</code> ?
	  </p></li>
<li><p>
<code>if (iterator)</code> won't work any
	    more =&gt; use <code>if (iterator != iterator_type())</code>
	    ?</p></li>
</ul>

<h5><code>isspace</code> from <tt>&lt;cctype&gt;</tt> is a macro
</h5>

<p> Glibc 2.0.x and 2.1.x define <tt>&lt;ctype.h&gt;</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 &lt;cctype&gt; 
int main() { std::isspace('X'); } 
</pre> 

<p>Results in something like this:
</p>

<pre> 
std:: (__ctype_b[(int) ( ( 'X' ) )] &amp; (unsigned short int) _ISspace ) ; 
</pre>


<p> A solution is to modify a header-file so that the compiler tells
<tt>&lt;ctype.h&gt;</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 &lt;ctype.h&gt;
</p>

<p>
Another problem arises if you put a <code>using namespace std;</code>
declaration at the top, and include <tt>&lt;ctype.h&gt;</tt>. This
will result in ambiguities between the definitions in the global
namespace (<tt>&lt;ctype.h&gt;</tt>) and the definitions in namespace
<code>std::</code> (<code>&lt;cctype&gt;</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>
AC_MSG_CHECKING(for container::at)
AC_TRY_COMPILE(
[
#include &lt;vector&gt;
#include &lt;deque&gt;
#include &lt;string&gt;
	
using namespace std;
],
[
deque&lt;int&gt; test_deque(3);
test_deque.at(2);
vector&lt;int&gt; test_vector(2);
test_vector.at(1);
string test_string(&quot;test_string&quot;);
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&lt;char&gt;::eof</code></h5>

<p>
Use some kind of autoconf test, plus this:
</p>      
<pre> 
#ifdef HAVE_CHAR_TRAITS
#define CPP_EOF std::char_traits&lt;char&gt;::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).
      <pre class="programlisting">
	void 
	clear() { _M_mutate(0, this-&gt;size(), 0); }
      </pre>
      <pre class="programlisting">
	basic_string&amp; 
	erase(size_type __pos = 0, size_type __n = npos)
	{ 
	return this-&gt;replace(_M_check(__pos), _M_fold(__pos, __n),
	_M_data(), _M_data()); 
	}
      </pre>
      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>
      Libstdc++ provides the new
      <code>i/ostringstream</code>-classes, (<tt>&lt;sstream&gt;</tt>), but for compatibility
      with older implementations you still have to use
      <code>i/ostrstream</code> (<tt>&lt;strstream&gt;</tt>):
      <pre >
	#ifdef HAVE_SSTREAM
	#include &lt;sstream&gt;
	#else
	#include &lt;strstream&gt;
	#endif
      </pre>
      <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:
      <pre >
	#ifdef HAVE_SSTREAM
	std::ostringstream oss;
	#else
	std::ostrstream oss;
	#endif
	oss &lt;&lt; &quot;Name=&quot; &lt;&lt; m_name &lt;&lt; &quot;, number=&quot; &lt;&lt; m_number &lt;&lt; std::endl;
	...
	#ifndef HAVE_SSTREAM
	oss &lt;&lt; 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 &gt;&gt; i; 
</pre>

<p> One (the only?) restriction is that an istrstream cannot be re-filled:
</p>
      
<pre >
std::istringstream iss(numerator);
iss &gt;&gt; m_num;
// this is not possible with istrstream
iss.clear();
iss.str(denominator);
iss &gt;&gt; m_den;
 </pre>
 
<p>
If you don't care about speed, you can put these conversions in
      a template-function:
</p>      
<pre >
template &lt;class X&gt;
void fromString(const string&amp; input, X&amp; any)
{
#ifdef HAVE_SSTREAM
std::istringstream iss(input);
#else
std::istrstream iss(input.c_str());
#endif
X temp;
iss &gt;&gt; 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 &quot;info iostream&quot;.
</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="C++ API v1">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, 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</p>

<h5>Pre-ISO headers moved to backwards</h5>
<p> The pre-ISO C++ headers (iostream.h etc.) are available, 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.</p>

<h5>Extension headers hash_map, hash_set moved to ext</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>.
</p>


<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, &quot;nocreate&quot; 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&lt;..&gt;</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>&lt;ext/stdio_filebuf.h&gt;</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>

<p><a href="http://gcc.gnu.org/bugzilla/buglist.cgi?cmdtype=runnamed&namedcmd=libstdc%2B%2B">Known Issues</a></p>

<h5>
container iterator types are not necessarily container value_type*
</h5>

<p>API History, User Visible Changes</p>

<p>3.0.0</p>


<p>3.1.0</p>
<p>3.2.0</p>
<p>3.3.0</p>


<p>3.4.0</p>

Macro guard for libstdc++ changed, from _GLIBCPP_ to _GLIBCXX_, to
accomodate a request from the C Pre Processor maintainer.

<p>4.0.0</p>
<p>4.1.0</p>

<cassert> how has to be explicitly included for <code>std::assert</code> calls.

<p>4.2.0</p>

<p>4.3.0</p>

Header streamlining.

Backward include edit.

PCH files built but not installed. 

Namespace pb_ds moved to __gnu_pb_ds.

C++OX features appear.

<hr />
<h3 class="left">
  <a name="C++ API v1">Fourth, and future</a>
</h3>

<hr />
<h3 class="left">
  <a name="Deprecation">Deprecation and Backwards Compatibility</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>

OpenPOWER on IntegriCloud