| 1 | <HTML> |
|---|
| 2 | <!-- |
|---|
| 3 | -- Copyright (c) Jeremy Siek 2000 |
|---|
| 4 | -- |
|---|
| 5 | -- Permission to use, copy, modify, distribute and sell this software |
|---|
| 6 | -- and its documentation for any purpose is hereby granted without fee, |
|---|
| 7 | -- provided that the above copyright notice appears in all copies and |
|---|
| 8 | -- that both that copyright notice and this permission notice appear |
|---|
| 9 | -- in supporting documentation. Silicon Graphics makes no |
|---|
| 10 | -- representations about the suitability of this software for any |
|---|
| 11 | -- purpose. It is provided "as is" without express or implied warranty. |
|---|
| 12 | --> |
|---|
| 13 | <!-- |
|---|
| 14 | -- Copyright (c) 1996-1999 |
|---|
| 15 | -- Silicon Graphics Computer Systems, Inc. |
|---|
| 16 | -- |
|---|
| 17 | -- Permission to use, copy, modify, distribute and sell this software |
|---|
| 18 | -- and its documentation for any purpose is hereby granted without fee, |
|---|
| 19 | -- provided that the above copyright notice appears in all copies and |
|---|
| 20 | -- that both that copyright notice and this permission notice appear |
|---|
| 21 | -- in supporting documentation. Silicon Graphics makes no |
|---|
| 22 | -- representations about the suitability of this software for any |
|---|
| 23 | -- purpose. It is provided "as is" without express or implied warranty. |
|---|
| 24 | -- |
|---|
| 25 | -- Copyright (c) 1994 |
|---|
| 26 | -- Hewlett-Packard Company |
|---|
| 27 | -- |
|---|
| 28 | -- Permission to use, copy, modify, distribute and sell this software |
|---|
| 29 | -- and its documentation for any purpose is hereby granted without fee, |
|---|
| 30 | -- provided that the above copyright notice appears in all copies and |
|---|
| 31 | -- that both that copyright notice and this permission notice appear |
|---|
| 32 | -- in supporting documentation. Hewlett-Packard Company makes no |
|---|
| 33 | -- representations about the suitability of this software for any |
|---|
| 34 | -- purpose. It is provided "as is" without express or implied warranty. |
|---|
| 35 | -- |
|---|
| 36 | --> |
|---|
| 37 | <Head> |
|---|
| 38 | <Title>LessThanComparable</Title> |
|---|
| 39 | </Head> |
|---|
| 40 | <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" |
|---|
| 41 | ALINK="#ff0000"> |
|---|
| 42 | <IMG SRC="../../boost.png" |
|---|
| 43 | ALT="C++ Boost" width="277" height="86"> |
|---|
| 44 | <!--end header--> |
|---|
| 45 | <BR Clear> |
|---|
| 46 | <H1>LessThanComparable</H1> |
|---|
| 47 | |
|---|
| 48 | <h3>Description</h3> |
|---|
| 49 | A type is LessThanComparable if it is ordered: it must |
|---|
| 50 | be possible to compare two objects of that type using <tt>operator<</tt>, and |
|---|
| 51 | <tt>operator<</tt> must be a strict weak ordering relation. |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | <h3>Refinement of</h3> |
|---|
| 55 | <h3>Associated types</h3> |
|---|
| 56 | <h3>Notation</h3> |
|---|
| 57 | <Table> |
|---|
| 58 | <TR> |
|---|
| 59 | <TD VAlign=top> |
|---|
| 60 | <tt>X</tt> |
|---|
| 61 | </TD> |
|---|
| 62 | <TD VAlign=top> |
|---|
| 63 | A type that is a model of LessThanComparable |
|---|
| 64 | </TD> |
|---|
| 65 | </TR> |
|---|
| 66 | <TR> |
|---|
| 67 | <TD VAlign=top> |
|---|
| 68 | <tt>x</tt>, <tt>y</tt>, <tt>z</tt> |
|---|
| 69 | </TD> |
|---|
| 70 | <TD VAlign=top> |
|---|
| 71 | Object of type <tt>X</tt> |
|---|
| 72 | </TD> |
|---|
| 73 | </tr> |
|---|
| 74 | </table> |
|---|
| 75 | <h3>Definitions</h3> |
|---|
| 76 | Consider the relation <tt>!(x < y) && !(y < x)</tt>. If this relation is |
|---|
| 77 | transitive (that is, if <tt>!(x < y) && !(y < x) && !(y < z) && !(z < y)</tt> |
|---|
| 78 | implies <tt>!(x < z) && !(z < x)</tt>), then it satisfies the mathematical |
|---|
| 79 | definition of an equivalence relation. In this case, <tt>operator<</tt> |
|---|
| 80 | is a <i>strict weak ordering</i>. |
|---|
| 81 | <P> |
|---|
| 82 | If <tt>operator<</tt> is a strict weak ordering, and if each equivalence class |
|---|
| 83 | has only a single element, then <tt>operator<</tt> is a <i>total ordering</i>. |
|---|
| 84 | <h3>Valid expressions</h3> |
|---|
| 85 | <Table border> |
|---|
| 86 | <TR> |
|---|
| 87 | <TH> |
|---|
| 88 | Name |
|---|
| 89 | </TH> |
|---|
| 90 | <TH> |
|---|
| 91 | Expression |
|---|
| 92 | </TH> |
|---|
| 93 | <TH> |
|---|
| 94 | Type requirements |
|---|
| 95 | </TH> |
|---|
| 96 | <TH> |
|---|
| 97 | Return type |
|---|
| 98 | </TH> |
|---|
| 99 | </TR> |
|---|
| 100 | <TR> |
|---|
| 101 | <TD VAlign=top> |
|---|
| 102 | Less |
|---|
| 103 | </TD> |
|---|
| 104 | <TD VAlign=top> |
|---|
| 105 | <tt>x < y</tt> |
|---|
| 106 | </TD> |
|---|
| 107 | <TD VAlign=top> |
|---|
| 108 | |
|---|
| 109 | </TD> |
|---|
| 110 | <TD VAlign=top> |
|---|
| 111 | Convertible to <tt>bool</tt> |
|---|
| 112 | </TD> |
|---|
| 113 | </TR> |
|---|
| 114 | </table> |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | <h3>Expression semantics</h3> |
|---|
| 119 | <Table border> |
|---|
| 120 | <TR> |
|---|
| 121 | <TH> |
|---|
| 122 | Name |
|---|
| 123 | </TH> |
|---|
| 124 | <TH> |
|---|
| 125 | Expression |
|---|
| 126 | </TH> |
|---|
| 127 | <TH> |
|---|
| 128 | Precondition |
|---|
| 129 | </TH> |
|---|
| 130 | <TH> |
|---|
| 131 | Semantics |
|---|
| 132 | </TH> |
|---|
| 133 | <TH> |
|---|
| 134 | Postcondition |
|---|
| 135 | </TH> |
|---|
| 136 | </TR> |
|---|
| 137 | <TR> |
|---|
| 138 | <TD VAlign=top> |
|---|
| 139 | Less |
|---|
| 140 | </TD> |
|---|
| 141 | <TD VAlign=top> |
|---|
| 142 | <tt>x < y</tt> |
|---|
| 143 | </TD> |
|---|
| 144 | <TD VAlign=top> |
|---|
| 145 | <tt>x</tt> and <tt>y</tt> are in the domain of <tt><</tt> |
|---|
| 146 | </TD> |
|---|
| 147 | <TD VAlign=top> |
|---|
| 148 | |
|---|
| 149 | </TD> |
|---|
| 150 | </table> |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | <h3>Complexity guarantees</h3> |
|---|
| 154 | <h3>Invariants</h3> |
|---|
| 155 | <Table border> |
|---|
| 156 | <TR> |
|---|
| 157 | <TD VAlign=top> |
|---|
| 158 | Irreflexivity |
|---|
| 159 | </TD> |
|---|
| 160 | <TD VAlign=top> |
|---|
| 161 | <tt>x < x</tt> must be false. |
|---|
| 162 | </TD> |
|---|
| 163 | </TR> |
|---|
| 164 | <TR> |
|---|
| 165 | <TD VAlign=top> |
|---|
| 166 | Antisymmetry |
|---|
| 167 | </TD> |
|---|
| 168 | <TD VAlign=top> |
|---|
| 169 | <tt>x < y</tt> implies !(y < x) <A href="#2">[2]</A> |
|---|
| 170 | </TD> |
|---|
| 171 | </TR> |
|---|
| 172 | <TR> |
|---|
| 173 | <TD VAlign=top> |
|---|
| 174 | Transitivity |
|---|
| 175 | </TD> |
|---|
| 176 | <TD VAlign=top> |
|---|
| 177 | <tt>x < y</tt> and <tt>y < z</tt> implies <tt>x < z</tt> <A href="#3">[3]</A> |
|---|
| 178 | </TD> |
|---|
| 179 | </tr> |
|---|
| 180 | </table> |
|---|
| 181 | <h3>Models</h3> |
|---|
| 182 | <UL> |
|---|
| 183 | <LI> |
|---|
| 184 | int |
|---|
| 185 | </UL> |
|---|
| 186 | <h3>Notes</h3> |
|---|
| 187 | <P><A name="1">[1]</A> |
|---|
| 188 | Only <tt>operator<</tt> is fundamental; the other inequality operators |
|---|
| 189 | are essentially syntactic sugar. |
|---|
| 190 | <P><A name="2">[2]</A> |
|---|
| 191 | Antisymmetry is a theorem, not an axiom: it follows from |
|---|
| 192 | irreflexivity and transitivity. |
|---|
| 193 | <P><A name="3">[3]</A> |
|---|
| 194 | Because of irreflexivity and transitivity, <tt>operator<</tt> always |
|---|
| 195 | satisfies the definition of a <i>partial ordering</i>. The definition of |
|---|
| 196 | a <i>strict weak ordering</i> is stricter, and the definition of a |
|---|
| 197 | <i>total ordering</i> is stricter still. |
|---|
| 198 | <h3>See also</h3> |
|---|
| 199 | <A href="http://www.sgi.com/tech/stl/EqualityComparable.html">EqualityComparable</A>, <A href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">StrictWeakOrdering</A> |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | <br> |
|---|
| 204 | <HR> |
|---|
| 205 | <TABLE> |
|---|
| 206 | <TR valign=top> |
|---|
| 207 | <TD nowrap>Copyright © 2000</TD><TD> |
|---|
| 208 | <A HREF=http://www.lsc.nd.edu/~jsiek>Jeremy Siek</A>, Univ.of Notre Dame (<A HREF="mailto:jsiek@lsc.nd.edu">jsiek@lsc.nd.edu</A>) |
|---|
| 209 | </TD></TR></TABLE> |
|---|
| 210 | |
|---|
| 211 | </BODY> |
|---|
| 212 | </HTML> |
|---|