1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<link href="../pool.css" rel="stylesheet" type="text/css">
<title>ct_gcd_lcm - Compile-Time GCD and LCM</title>
</head>
<body>
<img src="../../../../boost.png" width="276" height="86" alt="C++ Boost">
<h1 align="center">ct_gcd_lcm - Compile-Time GCD and LCM</h1>
<h2>Introduction</h2>
<p>detail/ct_gcd_lcm.hpp provides two compile-time algorithms: greatest
common divisor and least common multiple.</p>
<h2>Synopsis</h2>
<pre class="code">
namespace details {
namespace pool {
template <unsigned A, unsigned B>
struct ct_gcd
{
static const unsigned value = ...;
};
template <unsigned A, unsigned B>
struct ct_lcm
{
static const unsigned value = ...;
};
} // namespace pool
} // namespace details
</pre>
<h2>Semantics</h2>
<table align="center" border summary="">
<caption>
<em>Symbol Table</em>
</caption>
<tr>
<th>Symbol</th>
<th>Meaning</th>
</tr>
<tr>
<td class="code">A, B</td>
<td>compile-time unsigned integer constants<a href=
"#s519p1"><sup>[5.19/1]</sup></a></td>
</tr>
</table><br>
<table align="center" border summary="">
<caption>
<em>Semantics</em>
</caption>
<tr>
<th>Expression</th>
<th>Result Type</th>
<th>Value</th>
<th>Precondition</th>
</tr>
<tr>
<td class="code">ct_gcd<A, B>::value</td>
<td>compile-time unsigned integer constant</td>
<td>The greatest common divisor of <span class="code">A</span> and
<span class="code">B</span></td>
<td class="code">A != 0 && B != 0</td>
</tr>
<tr>
<td class="code">ct_lcm<A, B>::value</td>
<td>compile-time unsigned integer constant</td>
<td>The least common multiple of <span class="code">A</span> and
<span class="code">B</span></td>
<td class="code">A != 0 && B != 0</td>
</tr>
</table>
<h2>Notes</h2>
<p>Since these are compile-time algorithms, violation of the preconditions
will result in a compile-time error.</p>
<h2>Dependencies</h2>
<ul>
<li><boost/static_assert.hpp> (see <a href=
"../../../static_assert/static_assert.htm">Boost.Static_Assert</a>), to
ensure preconditions are met.</li>
<li><boost/type_traits/ice.hpp> (see <a href=
"../../../../more/int_const_guidelines.htm">Coding Guidelines for
Integral Constant Expressions</a>), to help with portability.</li>
</ul>
<h2>Selected Quotations from the Standard</h2>
<p><a name="s519p1" id="s519p1"></a><strong>5.19/1: Expressions: Constant
Expressions:</strong> ". . . An <em>integral constant expression</em> can
involve only literals (2.13), enumerators, <span class="code">const</span>
variables or static data members of integral or enumeration types
initialized with constant expressions (8.5), non-type template parameters
of integral or enumeration types, and <span class="code">sizeof</span>
expressions. Floating literals (2.13.3) can appear only if they are cast to
integral or enumeration types. Only type conversions to integral or
enumeration types can be used. In particular, except in <span class=
"code">sizeof</span> expressions, functions, class objects, pointers, or
references shall not be used, and assignment, increment, decrement,
function-call, or comma operators shall not be used."</p>
<h2>Future Directions</h2>
<p>This header may be replaced by a Boost compile-time algorithms
library.</p>
<hr>
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
"http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
height="31" width="88"></a></p>
<p>Revised
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->05
December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38516" --></p>
<p><i>Copyright © 2000, 2001 Stephen Cleary (scleary AT jerviswebb DOT
com)</i></p>
<p><i>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
or copy at <a href=
"http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
</body>
</html>
|