1 | <HTML> |
---|
2 | <!-- |
---|
3 | -- Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 2001 |
---|
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. We make 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 | <Head> |
---|
14 | <Title>Monoid</Title> |
---|
15 | <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" |
---|
16 | ALINK="#ff0000"> |
---|
17 | <IMG SRC="../../../boost.png" |
---|
18 | ALT="C++ Boost" width="277" height="86"> |
---|
19 | |
---|
20 | <BR Clear> |
---|
21 | |
---|
22 | <H1><A NAME="concept:Monoid"></A> |
---|
23 | Monoid |
---|
24 | </H1> |
---|
25 | |
---|
26 | A <i>Monoid</i> is a concept that describes a simple kind of algebraic |
---|
27 | system. A <b>monoid</b> consists of a set of elements <i>S</i>, a |
---|
28 | binary operation, and an identity element. The C++ representation of a |
---|
29 | monoid consists of a function object that implements the binary |
---|
30 | operation, a set of objects that represent the elements of <i>S</i>, |
---|
31 | and an object that represents the identity element. |
---|
32 | |
---|
33 | |
---|
34 | <H3>Refinement of</H3> |
---|
35 | |
---|
36 | The element type must be a model of <a |
---|
37 | href="../../utility/Assignable.html">Assignable</a> and <a |
---|
38 | href="../../utility/CopyConstructible.html">CopyConstructible</a>. |
---|
39 | The function object type must be a model of <a |
---|
40 | href="http://www.sgi.com/tech/stl/BinaryFunction.html">BinaryFunction</a>. |
---|
41 | |
---|
42 | <h3>Notation</h3> |
---|
43 | |
---|
44 | <Table> |
---|
45 | <TR> |
---|
46 | <TD><tt>X</tt></TD> |
---|
47 | <TD>Is the element type of the Monoid.</TD> |
---|
48 | </TR> |
---|
49 | |
---|
50 | <TR> |
---|
51 | <TD><tt>a, b</tt></TD> |
---|
52 | <TD>are objects of type <tt>X</tt>.</TD> |
---|
53 | </TR> |
---|
54 | |
---|
55 | <TR> |
---|
56 | <TD><tt>op</tt></TD> |
---|
57 | <TD>Is the function object implementing the Monoid operation.</TD> |
---|
58 | </TR> |
---|
59 | |
---|
60 | <TR> |
---|
61 | <TD><tt>i</tt></TD> |
---|
62 | <TD>is an object of type <tt>X</tt> and is the identity element |
---|
63 | for the Monoid.</TD> |
---|
64 | </TR> |
---|
65 | |
---|
66 | |
---|
67 | </table> |
---|
68 | |
---|
69 | <h3>Valid Expressions</h3> |
---|
70 | |
---|
71 | <Table border> |
---|
72 | |
---|
73 | <tr> |
---|
74 | <td><a name="sec:source"><TT>op(a, b)</TT></a></TD> |
---|
75 | <TD>See below for semantics.<br> |
---|
76 | Return type: <TT>X</TT> |
---|
77 | </TD> |
---|
78 | </TR> |
---|
79 | |
---|
80 | <tr> |
---|
81 | <TD><TT>a == b</TT></TD> |
---|
82 | <TD>Returns true if <tt>a</tt> and <tt>b</tt> represent |
---|
83 | the same element of <i>S</i>.<br> |
---|
84 | Return type: <TT>bool</TT> |
---|
85 | </TD> |
---|
86 | </TR> |
---|
87 | |
---|
88 | <tr> |
---|
89 | <TD><TT>a != b</TT></TD> |
---|
90 | <TD>Returns true if <tt>a</tt> and <tt>b</tt> represent |
---|
91 | different elements of <i>S</i>.<br> |
---|
92 | Return type: <TT>bool</TT> |
---|
93 | </TD> |
---|
94 | </TR> |
---|
95 | |
---|
96 | </TABLE> |
---|
97 | |
---|
98 | <P> |
---|
99 | |
---|
100 | <H3>Invariants</H3> |
---|
101 | |
---|
102 | <UL> |
---|
103 | <li>Closure<br> |
---|
104 | The result of <tt>op(a, b)</tt> is also an element of <i>S</i>. |
---|
105 | <li>Associativity<br> |
---|
106 | <tt>op(op(a, b), c) == op(a, op(b, c))</tt> |
---|
107 | <li>Definition of Identity Element<br> |
---|
108 | <tt>op(a, i) == a</tt> |
---|
109 | </UL> |
---|
110 | |
---|
111 | <br> |
---|
112 | <HR> |
---|
113 | <TABLE> |
---|
114 | <TR valign=top> |
---|
115 | <TD nowrap>Copyright © 2000-2001</TD><TD> |
---|
116 | <A HREF="../../../people/jeremy_siek.htm">Jeremy Siek</A>, |
---|
117 | Indiana University (<A |
---|
118 | HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br> |
---|
119 | <A HREF="../../../people/liequan_lee.htm">Lie-Quan Lee</A>, Indiana University (<A HREF="mailto:llee@cs.indiana.edu">llee@cs.indiana.edu</A>)<br> |
---|
120 | <A HREF=http://www.osl.iu.edu/~lums>Andrew Lumsdaine</A>, |
---|
121 | Indiana University (<A |
---|
122 | HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>) |
---|
123 | </TD></TR></TABLE> |
---|
124 | |
---|
125 | </BODY> |
---|
126 | </HTML> |
---|