OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [doc/] [xml/] [manual/] [extensions.xml] - Blame information for rev 742

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
2
      xml:id="manual.ext" xreflabel="Extensions">
3
4
 
5
</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>6</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  Extensions</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>7</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  <indexterm><primary>Extensions</primary></indexterm></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>8</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>
9
  
10
    
11
      ISO C++
12
    
13
    
14
      library
15
    
16
  
17
18
 
19
 
20
</info></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>21</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code><para></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>22</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  Here we will make an attempt at describing the non-Standard</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>23</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  extensions to the library.  Some of these are from older versions of</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>24</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  standard library components, namely SGI's STL, and some of these are</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>25</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  GNU's.</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>26</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code></para></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>27</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code><para><emphasis>Before</emphasis> you leap in and use any of these</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>28</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>extensions, be aware of two things:</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>29</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code></para></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>30</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code><orderedlist inheritnum="ignore" continuation="restarts"></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>31</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>   <listitem></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>32</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>     <para></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>33</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>     Non-Standard means exactly that.</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>34</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>     </para></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>35</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>     <para></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>36</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>       The behavior, and the very</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>37</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>       existence, of these extensions may change with little or no</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>38</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>       warning.  (Ideally, the really good ones will appear in the next</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>39</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>       revision of C++.)  Also, other platforms, other compilers, other</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>40</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>       versions of g++ or libstdc++ may not recognize these names, or</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>41</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>       treat them differently, or...</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>42</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>     </para></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>43</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>   </listitem></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>44</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>   <listitem></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>45</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>     <para></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>46</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>       You should know how to access these headers properly.</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>47</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>     </para></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>48</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>   </listitem></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>49</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code></orderedlist></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>50</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code></preface></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>51</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code> </code></pre></td>
      </tr>
      <tr valign="middle">
         <td>52</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code><!-- Chapter 01 : Compile Time Checks --></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>53</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code><chapter xml:id="manual.ext.compile_checks" xreflabel="Compile Time Checks"><info><title>Compile Time Checks
54
55
 
56
  
57
    Also known as concept checking.
58
  
59
   In 1999, SGI added concept checkers to their implementation
60
      of the STL:  code which checked the template parameters of
61
      instantiated pieces of the STL, in order to insure that the parameters
62
      being used met the requirements of the standard.  For example,
63
      the Standard requires that types passed as template parameters to
64
      vector be Assignable (which means what you think
65
      it means).  The checking was done during compilation, and none of
66
      the code was executed at runtime.
67
   
68
   Unfortunately, the size of the compiler files grew significantly
69
      as a result.  The checking code itself was cumbersome.  And bugs
70
      were found in it on more than one occasion.
71
   
72
   The primary author of the checking code, Jeremy Siek, had already
73
      started work on a replacement implementation.  The new code has been
74
      formally reviewed and accepted into
75
      the
76
      Boost libraries, and we are pleased to incorporate it into the
77
      GNU C++ library.
78
   
79
   The new version imposes a much smaller space overhead on the generated
80
      object file.  The checks are also cleaner and easier to read and
81
      understand.
82
   
83
   They are off by default for all versions of GCC from 3.0 to 3.4 (the
84
      latest release at the time of writing).
85
      They can be enabled at configure time with
86
      --enable-concept-checks.
87
      You can enable them on a per-translation-unit basis with
88
      #define _GLIBCXX_CONCEPT_CHECKS for GCC 3.4 and higher
89
      (or with #define _GLIBCPP_CONCEPT_CHECKS for versions
90
      3.1, 3.2 and 3.3).
91
   
92
 
93
   Please note that the upcoming C++ standard has first-class
94
   support for template parameter constraints based on concepts in the core
95
   language. This will obviate the need for the library-simulated concept
96
   checking described above.
97
   
98
 
99
100
 
101
102
103
            href="debug_mode.xml">
104
105
 
106
107
108
            href="parallel_mode.xml">
109
110
 
111
112
113
            href="profile_mode.xml">
114
115
 
116
 
117
118
119
120
121
            href="mt_allocator.xml">
122
123
 
124
125
126
            href="bitmap_allocator.xml">
127
128
 
129
130
131
132
            href="policy_data_structures.xml">
133
134
 
135
136
137
  HP/SGI Extensions
138
139
 
140
  
141
    Backwards Compatibility
142
 
143
    A few extensions and nods to backwards-compatibility have
144
    been made with containers.  Those dealing with older SGI-style
145
    allocators are dealt with elsewhere.  The remaining ones all deal
146
    with bits:
147
    
148
    The old pre-standard bit_vector class is
149
    present for backwards compatibility.  It is simply a typedef for
150
    the vector<bool> specialization.
151
    
152
 
153
The bitset class has a number of extensions, described in the
154
   rest of this item.  First, we'll mention that this implementation of
155
   bitset<N> is specialized for cases where N number of
156
   bits will fit into a single word of storage.  If your choice of N is
157
   within that range (<=32 on i686-pc-linux-gnu, for example), then all
158
   of the operations will be faster.
159
160
There are
161
   versions of single-bit test, set, reset, and flip member functions which
162
   do no range-checking.  If we call them member functions of an instantiation
163
   of bitset<N>, then their names and signatures are:
164
165
   
166
   bitset<N>&   _Unchecked_set   (size_t pos);
167
   bitset<N>&   _Unchecked_set   (size_t pos, int val);
168
   bitset<N>&   _Unchecked_reset (size_t pos);
169
   bitset<N>&   _Unchecked_flip  (size_t pos);
170
   bool         _Unchecked_test  (size_t pos);
171
   
172
   Note that these may in fact be removed in the future, although we have
173
   no present plans to do so (and there doesn't seem to be any immediate
174
   reason to).
175
176
The member function operator[] on a const bitset returns
177
   a bool, and for a non-const bitset returns a reference (a
178
   nested type).  No range-checking is done on the index argument, in keeping
179
   with other containers' operator[] requirements.
180
181
Finally, two additional searching functions have been added.  They return
182
   the index of the first "on" bit, and the index of the first
183
   "on" bit that is after prev, respectively:
184
185
   
186
   size_t _Find_first() const;
187
   size_t _Find_next (size_t prev) const;
188
The same caveat given for the _Unchecked_* functions applies here also.
189
190
  
191
 
192
 
193
  
Deprecated
194
 
195
 
196
   
197
     The SGI hashing classes hash_set and
198
     hash_set have been deprecated by the
199
     unordered_set, unordered_multiset, unordered_map,
200
     unordered_multimap containers in TR1 and C++11, and
201
     may be removed in future releases.
202
   
203
 
204
   The SGI headers
205
   
206
     <hash_map>
207
     <hash_set>
208
     <rope>
209
     <slist>
210
     <rb_tree>
211
   
212
   are all here;
213
      <backwards/hash_map> and
214
      <backwards/hash_set>
215
      are deprecated but available as backwards-compatible extensions,
216
      as discussed further below.
217
      <ext/rope> is the SGI
218
      specialization for large strings ("rope," "large strings," get it? Love
219
      that geeky humor.)
220
      <ext/slist> (superseded in
221
      C++11 by <forward_list>)
222
      is a singly-linked list, for when the doubly-linked list<>
223
      is too much space overhead, and
224
      <ext/rb_tree> exposes the
225
      red-black tree classes used in the implementation of the standard maps
226
      and sets.
227
   
228
   Each of the associative containers map, multimap, set, and multiset
229
      have a counterpart which uses a
230
      hashing
231
      function to do the arranging, instead of a strict weak ordering
232
      function.  The classes take as one of their template parameters a
233
      function object that will return the hash value; by default, an
234
      instantiation of
235
      hash.
236
      You should specialize this functor for your class, or define your own,
237
      before trying to use one of the hashing classes.
238
   
239
   The hashing classes support all the usual associative container
240
      functions, as well as some extra constructors specifying the number
241
      of buckets, etc.
242
   
243
   Why would you want to use a hashing class instead of the
244
      normalimplementations?  Matt Austern writes:
245
   
246
   
247
     
248
       [W]ith a well chosen hash function, hash tables
249
       generally provide much better average-case performance than
250
       binary search trees, and much worse worst-case performance.  So
251
       if your implementation has hash_map, if you don't mind using
252
       nonstandard components, and if you aren't scared about the
253
       possibility of pathological cases, you'll probably get better
254
       performance from hash_map.
255
     
256
     
257
   
258
 
259
   
260
      The deprecated hash tables are superseded by the standard unordered
261
      associative containers defined in the ISO C++ 2011 standard in the
262
      headers <unordered_map>
263
      and <unordered_set>.
264
   
265
 
266
  
267
268
 
269
270
Utilities
271
272
 
273
  
274
    The <functional> header
275
    contains many additional functors
276
    and helper functions, extending section 20.3.  They are
277
    implemented in the file stl_function.h:
278
  
279
  
280
  
281
  identity_element for addition and multiplication.
282
  
283
  
284
  
285
    The functor identity, whose operator()
286
      returns the argument unchanged.
287
  
288
  
289
  
290
    Composition functors unary_function and
291
      binary_function, and their helpers compose1
292
      and compose2.
293
    
294
  
295
  
296
  select1st and select2nd, to strip pairs.
297
  
298
  
299
  project1st and project2nd. 
300
  A set of functors/functions which always return the same result.  They
301
      are constant_void_fun, constant_binary_fun,
302
      constant_unary_fun, constant0,
303
      constant1, and constant2. 
304
  The class subtractive_rng. 
305
  mem_fun adaptor helpers mem_fun1 and
306
      mem_fun1_ref are provided for backwards compatibility. 
307
308
309
  20.4.1 can use several different allocators; they are described on the
310
   main extensions page.
311
312
313
  20.4.3 is extended with a special version of
314
  get_temporary_buffer taking a second argument.  The
315
  argument is a pointer, which is ignored, but can be used to specify
316
  the template type (instead of using explicit function template
317
  arguments like the standard version does).  That is, in addition to
318
319
320
get_temporary_buffer<int>(5);
321
322
 
323
324
you can also use
325
326
 
327
328
get_temporary_buffer(5, (int*)0);
329
330
331
  A class temporary_buffer is given in stl_tempbuf.h.
332
333
334
  The specialized algorithms of section 20.4.4 are extended with
335
  uninitialized_copy_n.
336
337
 
338
339
 
340
341
Algorithms
342
343
 
344
25.1.6 (count, count_if) is extended with two more versions of count
345
   and count_if.  The standard versions return their results.  The
346
   additional signatures return void, but take a final parameter by
347
   reference to which they assign their results, e.g.,
348
349
   
350
   void count (first, last, value, n);
351
25.2 (mutating algorithms) is extended with two families of signatures,
352
   random_sample and random_sample_n.
353
354
25.2.1 (copy) is extended with
355
356
   
357
   copy_n (_InputIter first, _Size count, _OutputIter result);
358
which copies the first 'count' elements at 'first' into 'result'.
359
360
25.3 (sorting 'n' heaps 'n' stuff) is extended with some helper
361
   predicates.  Look in the doxygen-generated pages for notes on these.
362
363
   
364
    is_heap tests whether or not a range is a heap.
365
    is_sorted tests whether or not a range is sorted in
366
        nondescending order.
367
   
368
25.3.8 (lexicographical_compare) is extended with
369
370
   
371
   lexicographical_compare_3way(_InputIter1 first1, _InputIter1 last1,
372
                                 _InputIter2 first2, _InputIter2 last2)
373
which does... what?
374
375
 
376
377
 
378
379
Numerics
380
381
 
382
26.4, the generalized numeric operations such as accumulate,
383
   are extended with the following functions:
384
385
   
386
   power (x, n);
387
   power (x, n, monoid_operation);
388
Returns, in FORTRAN syntax, "x ** n" where
389
   n >= 0.  In the
390
   case of n == 0, returns the identity element for the
391
   monoid operation.  The two-argument signature uses multiplication (for
392
   a true "power" implementation), but addition is supported as well.
393
   The operation functor must be associative.
394
395
The iota function wins the award for Extension With the
396
   Coolest Name (the name comes from Ken Iverson's APL language.)  As
397
   described in the SGI
398
   documentation, it "assigns sequentially increasing values to a range.
399
   That is, it assigns value to *first,
400
   value + 1 to *(first + 1) and so on."
401
402
   
403
   void iota(_ForwardIter first, _ForwardIter last, _Tp value);
404
The iota function is included in the ISO C++ 2011 standard.
405
406
407
 
408
409
Iterators
410
411
 
412
24.3.2 describes struct iterator, which didn't exist in the
413
   original HP STL implementation (the language wasn't rich enough at the
414
   time).  For backwards compatibility, base classes are provided which
415
   declare the same nested typedefs:
416
417
   
418
    input_iterator
419
    output_iterator
420
    forward_iterator
421
    bidirectional_iterator
422
    random_access_iterator
423
   
424
24.3.4 describes iterator operation distance, which takes
425
   two iterators and returns a result.  It is extended by another signature
426
   which takes two iterators and a reference to a result.  The result is
427
   modified, and the function returns nothing.
428
429
 
430
431
 
432
433
Input and Output
434
435
 
436
 
437
  
438
    Extensions allowing filebufs to be constructed from
439
    "C" types like  FILE*s and file descriptors.
440
  
441
 
442
  
Derived filebufs
443
 
444
 
445
   The v2 library included non-standard extensions to construct
446
      std::filebufs from C stdio types such as
447
      FILE*s and POSIX file descriptors.
448
      Today the recommended way to use stdio types with libstdc++
449
      IOStreams is via the stdio_filebuf class (see below),
450
      but earlier releases provided slightly different mechanisms.
451
   
452
   
453
     3.0.x filebufs have another ctor with this signature:
454
        basic_filebuf(__c_file_type*, ios_base::openmode, int_type);
455
        
456
         This comes in very handy in a number of places, such as
457
         attaching Unix sockets, pipes, and anything else which uses file
458
         descriptors, into the IOStream buffering classes.  The three
459
         arguments are as follows:
460
         
461
          __c_file_type*      F   
462
              // the __c_file_type typedef usually boils down to stdio's FILE
463
          
464
          ios_base::openmode  M   
465
              // same as all the other uses of openmode
466
          
467
          int_type            B   
468
              // buffer size, defaults to BUFSIZ if not specified
469
          
470
         
471
         For those wanting to use file descriptors instead of FILE*'s, I
472
         invite you to contemplate the mysteries of C's fdopen().
473
     
474
     In library snapshot 3.0.95 and later, filebufs bring
475
         back an old extension:  the fd() member function.  The
476
         integer returned from this function can be used for whatever file
477
         descriptors can be used for on your platform.  Naturally, the
478
         library cannot track what you do on your own with a file descriptor,
479
         so if you perform any I/O directly, don't expect the library to be
480
         aware of it.
481
     
482
     Beginning with 3.1, the extra filebuf constructor and
483
         the fd() function were removed from the standard
484
         filebuf.  Instead, <ext/stdio_filebuf.h> contains
485
         a derived class called
486
         __gnu_cxx::stdio_filebuf.
487
         This class can be constructed from a C FILE* or a file
488
         descriptor, and provides the fd() function.
489
     
490
   
491
 
492
  
493
494
 
495
496
Demangling
497
498
 
499
  
500
    Transforming C++ ABI identifiers (like RTTI symbols) into the
501
    original C++ source identifiers is called
502
    demangling.
503
  
504
  
505
    If you have read the source
506
    documentation for namespace abi then you are
507
    aware of the cross-vendor C++ ABI in use by GCC.  One of the
508
    exposed functions is used for demangling,
509
    abi::__cxa_demangle.
510
  
511
  
512
    In programs like c++filt, the linker, and other tools
513
    have the ability to decode C++ ABI names, and now so can you.
514
  
515
  
516
    (The function itself might use different demanglers, but that's the
517
    whole point of abstract interfaces.  If we change the implementation,
518
    you won't notice.)
519
  
520
  
521
    Probably the only times you'll be interested in demangling at runtime
522
    are when you're seeing typeid strings in RTTI, or when
523
    you're handling the runtime-support exception classes.  For example:
524
  
525
   
526
#include <exception>
527
#include <iostream>
528
#include <cxxabi.h>
529
 
530
struct empty { };
531
 
532
template <typename T, int N>
533
  struct bar { };
534
 
535
 
536
int main()
537
{
538
  int     status;
539
  char   *realname;
540
 
541
  // exception classes not in <stdexcept>, thrown by the implementation
542
  // instead of the user
543
  std::bad_exception  e;
544
  realname = abi::__cxa_demangle(e.what(), 0, 0, &status);
545
  std::cout << e.what() << "\t=> " << realname << "\t: " << status << '\n';
546
  free(realname);
547
 
548
 
549
  // typeid
550
  bar<empty,17>          u;
551
  const std::type_info  &ti = typeid(u);
552
 
553
  realname = abi::__cxa_demangle(ti.name(), 0, 0, &status);
554
  std::cout << ti.name() << "\t=> " << realname << "\t: " << status << '\n';
555
  free(realname);
556
 
557
  return 0;
558
}
559
   
560
   
561
     This prints
562
   
563
 
564
   
565
   
566
      St13bad_exception       => std::bad_exception   : 0
567
      3barI5emptyLi17EE       => bar<empty, 17>       : 0
568
   
569
   
570
 
571
   
572
     The demangler interface is described in the source documentation
573
     linked to above.  It is actually written in C, so you don't need to
574
     be writing C++ in order to demangle C++.  (That also means we have to
575
     use crummy memory management facilities, so don't forget to free()
576
     the returned char array.)
577
   
578
579
 
580
581
582
583
 
584

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.