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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [libstdc++-v3/] [doc/] [xml/] [manual/] [extensions.xml] - Blame information for rev 424

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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