Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/integer/doc/static_min_max.html @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 3.7 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
2<html>
3<head>
4<title>Compile-Time Extrema Templates</title>
5</head>
6
7<body bgcolor="white" text="black" link="blue" alink="red" vlink="purple">
8<h1><img src="../../../boost.png" alt="boost.png (6897 bytes)"
9align="middle" width="277" height="86">Compile-Time Extrema
10Templates</h1>
11
12<p>The class templates in <cite><a
13href="../../../boost/integer/static_min_max.hpp">&lt;boost/integer/static_min_max.hpp&gt;</a></cite>
14provide a compile-time evaluation of the minimum or maximum of
15two integers.  These facilities are useful for generic programming problems.</p>
16
17<h2><a name="contents">Contents</a></h2>
18
19<ul>
20        <li><a href="#contents">Contents</a></li>
21        <li><a href="#synopsis">Synopsis</a></li>
22        <li><a href="#usage">Usage</a></li>
23        <li><a href="#example">Example</a></li>
24        <li><a href="#demo">Demonstration Program</a></li>
25        <li><a href="#rationale">Rationale</a></li>
26        <li><a href="#credits">Credits</a></li>
27</ul>
28
29<h2><a name="synopsis">Synopsis</a></h2>
30
31<blockquote><pre>
32namespace boost
33{
34
35template &lt; long Value1, long Value2 &gt;
36    struct static_signed_min;
37
38template &lt; long Value1, long Value2 &gt;
39    struct static_signed_max;
40
41template &lt; unsigned long Value1, unsigned long Value2 &gt;
42    struct static_unsigned_min;
43
44template &lt; unsigned long Value1, unsigned long Value2 &gt;
45    struct static_unsigned_max;
46
47}
48</pre></blockquote>
49
50<h2><a name="usage">Usage</a></h2>
51
52<p>The four class templates provide the combinations for finding the
53minimum or maximum of two signed or <code>unsigned</code>
54(<code>long</code>) parameters, <var>Value1</var> and <var>Value2</var>,
55at compile-time.  Each template has a single static data member,
56<code>value</code>, which is set to the respective minimum or maximum
57of the template's parameters.</p>
58
59<h2><a name="example">Example</a></h2>
60
61<blockquote><pre>
62#include &lt;boost/integer/static_min_max.hpp&gt;
63
64template &lt; unsigned long AddendSize1, unsigned long AddendSize2 &gt;
65class adder
66{
67public:
68    static  unsigned long  const  addend1_size = AddendSize1;
69    static  unsigned long  const  addend2_size = AddendSize2;
70    static  unsigned long  const  sum_size = boost::static_unsigned_max&lt;AddendSize1, AddendSize2&gt;::value + 1;
71
72    typedef int  addend1_type[ addend1_size ];
73    typedef int  addend2_type[ addend2_size ];
74    typedef int  sum_type[ sum_size ];
75
76    void  operator ()( addend1_type const &amp;a1, addend2_type const &amp;a2, sum_type &amp;s ) const;
77};
78
79//...
80
81int main()
82{
83    int const   a1[] = { 0, 4, 3 };  // 340
84    int const   a2[] = { 9, 8 };     //  89
85    int         s[ 4 ];
86    adder&lt;3,2&gt;  obj;
87
88    obj( a1, a2, s );  // 's' should be 429 or { 9, 2, 4, 0 }
89    //...
90}
91</pre></blockquote>
92
93<h2><a name="demo">Demonstration Program</a></h2>
94
95<p>The program <a
96href="../test/static_min_max_test.cpp">static_min_max_test.cpp</a> is a
97simplistic demonstration of various comparisons using the compile-time
98extrema class templates.</p>
99
100<h2><a name="rationale">Rationale</a></h2>
101
102<p>Sometimes the minimum or maximum of several values needs to be found
103for later compile-time processing, <i>e.g.</i> for a bound for another
104class template.</p>
105
106<h2><a name="credits">Credits</a></h2>
107
108<p>The author of the Boost compile-time extrema class templates is <a
109href="../../../people/daryle_walker.html">Daryle Walker</a>.</p>
110
111<hr>
112
113<p>Revised October 12, 2001</p>
114
115<p>&copy; Copyright Daryle Walker 2001.  Permission to copy, use,
116modify, sell and distribute this document is granted provided this
117copyright notice appears in all copies.  This document is provided
118&quot;as is&quot; without express or implied warranty, and with no claim
119as to its suitability for any purpose.</p>
120</body>
121</html>
Note: See TracBrowser for help on using the repository browser.