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

Subversion Repositories openrisc

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

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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