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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc4/] [libstdc++-v3/] [doc/] [xml/] [manual/] [algorithms.xml] - Blame information for rev 519

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
      algorithm
19
    
20
  
21
22
 
23
</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>24</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  Algorithms</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>25</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  <indexterm><primary>Algorithms</primary></indexterm></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>26</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>
27
 
28
29
  The neatest accomplishment of the algorithms sect1 is that all the
30
  work is done via iterators, not containers directly.  This means two
31
  important things:
32
33
34
  
35
    
36
      Anything that behaves like an iterator can be used in one of
37
      these algorithms.  Raw pointers make great candidates, thus
38
      built-in arrays are fine containers, as well as your own
39
      iterators.
40
    
41
  
42
  
43
    
44
      The algorithms do not (and cannot) affect the container as a
45
      whole; only the things between the two iterator endpoints.  If
46
      you pass a range of iterators only enclosing the middle third of
47
      a container, then anything outside that range is inviolate.
48
    
49
  
50
51
52
  Even strings can be fed through the algorithms here, although the
53
  string class has specialized versions of many of these functions
54
  (for example, string::find()).  Most of the examples
55
  on this page will use simple arrays of integers as a playground
56
  for algorithms, just to keep things simple.  The use of
57
  N as a size in the examples is to keep things
58
  easy to read but probably won't be valid code.  You can use wrappers
59
  such as those described in
60
  the containers sect1 to keep
61
  real code readable.
62
63
64
  The single thing that trips people up the most is the definition
65
  of range used with iterators; the famous
66
  "past-the-end" rule that everybody loves to hate.  The
67
  iterators sect1 of this
68
    document has a complete explanation of this simple rule that seems
69
    to cause so much confusion.  Once you
70
    get range into your head (it's not that hard,
71
    honest!), then the algorithms are a cakewalk.
72
73
 
74
75
 
76
77
78
  Mutating
79
 
80
  
81
    <function>swap</function>
82
 
83
    
84
    Specializations
85
 
86
   If you call  std::swap(x,y);  where x and y are standard
87
      containers, then the call will automatically be replaced by a call to
88
       x.swap(y);  instead.
89
   
90
   This allows member functions of each container class to take over, and
91
      containers' swap functions should have O(1) complexity according to
92
      the standard.  (And while "should" allows implementations to
93
      behave otherwise and remain compliant, this implementation does in
94
      fact use constant-time swaps.)  This should not be surprising, since
95
      for two containers of the same type to swap contents, only some
96
      internal pointers to storage need to be exchanged.
97
   
98
 
99
    
100
  
101
102
 
103
104
 
105

powered by: WebSVN 2.1.0

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