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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>ct_gcd_lcm - Compile-Time GCD and LCM</TITLE>
<LINK HREF="../pool.css" REL="stylesheet" TYPE="text/css">
</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>
<P>
<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>
<P>
<H2>Semantics</H2>
<TABLE ALIGN=CENTER BORDER>
<CAPTION><EM>Symbol Table</EM></CAPTION>
<TR><TH>Symbol<TH>Meaning</TR>
<TR><TD CLASS="code">A, B<TD>compile-time unsigned integer constants<A HREF="#5.19/1"><SUP>[5.19/1]</SUP></A></TR>
</TABLE>
<TABLE ALIGN=CENTER BORDER>
<CAPTION><EM>Semantics</EM></CAPTION>
<TR><TH>Expression<TH>Result Type<TH>Value<TH>Precondition
<TR><TD CLASS="code">ct_gcd<A, B>::value<TD>compile-time unsigned integer constant<TD>The greatest common divisor of <SPAN CLASS="code">A</SPAN> and <SPAN CLASS="code">B</SPAN><TD CLASS="code">A != 0 && B != 0
<TR><TD CLASS="code">ct_lcm<A, B>::value<TD>compile-time unsigned integer constant<TD>The least common multiple of <SPAN CLASS="code">A</SPAN> and <SPAN CLASS="code">B</SPAN><TD CLASS="code">A != 0 && B != 0
</TABLE>
<P>
<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>
<P>
<H2>Selected Quotations from the Standard</H2>
<P>
<A NAME="5.19/1">
<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."</A>
<P>
<H2>Future Directions</H2>
<P>
This header may be replaced by a Boost compile-time algorithms library.
<P>
<HR>
<P>
Copyright © 2000, 2001 Stephen Cleary (scleary AT jerviswebb DOT com)
<P>
This file can be redistributed and/or modified under the terms found in <A HREF="../copyright.html">copyright.html</A>
<P>
This software and its documentation is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.
</BODY>
</HTML>
|