Update Boost.Integer meta-programming classes to work with intmax_t where possible - ie to be 64-bit clean.
Added quickbook based docs - updated as necessary. Removed old html docs. [SVN r57926]
This commit is contained in:
parent
db267e22f8
commit
ca84baa55d
81
cstdint.htm
81
cstdint.htm
@ -1,81 +0,0 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<title>Header boost/cstdint.hpp</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<h1><img src="../../boost.png" alt="boost.png (6897 bytes)" align="center" width="277" height="86">Header
|
||||
boost/cstdint.hpp </h1>
|
||||
<p>The header <code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp></a></code>
|
||||
provides the typedef's useful for
|
||||
writing portable code that requires certain integer widths. All typedef's are in namespace boost.</p>
|
||||
<p>The specifications are based on the ISO/IEC 9899:1999 C Language standard
|
||||
header <stdint.h>. The 64-bit types required by the C standard are not
|
||||
required in the boost header, and may not be supplied in all implementations,
|
||||
because <code>long long</code> is not [yet] included in the C++ standard.</p>
|
||||
<p>See <a href="cstdint_test.cpp">cstdint_test.cpp</a> for a test program.</p>
|
||||
<h2>Exact-width integer types</h2>
|
||||
<p>The typedef <code>int#_t</code>, with # replaced by the width, designates a
|
||||
signed integer type of exactly # bits; <code>int8_t</code> denotes an 8-bit
|
||||
signed integer type. Similarly, the typedef <code>uint#_t</code>
|
||||
designates and unsigned integer type of exactly # bits.</p>
|
||||
<p>These types are optional. However, if an implementation provides integer
|
||||
types with widths of 8, 16, 32, or 64 bits, it shall define the corresponding
|
||||
typedef names.</p>
|
||||
<h2>Minimum-width integer types</h2>
|
||||
<p>The typedef <code>int_least#_t</code>, with # replaced by the width,
|
||||
designates a signed integer type with a width of at least # bits, such that no
|
||||
signed integer type with lesser size has at least the specified width. Thus, <code>int_least32_t</code>
|
||||
denotes a signed integer type with a width of at least 32 bits. Similarly, the
|
||||
typedef name <code>uint_least#_t</code> designates an unsigned integer type with
|
||||
a width of at least # bits, such that no unsigned integer type with lesser size
|
||||
has at least the specified width.</p>
|
||||
<p>Required minimum-width integer types:</p>
|
||||
<ul>
|
||||
<li><code>int_least8_t</code></li>
|
||||
<li><code>int_least16_t</code></li>
|
||||
<li><code>int_least32_t</code></li>
|
||||
<li><code>uint_least8_t</code></li>
|
||||
<li><code>uint_least16_t</code></li>
|
||||
<li><code>uint_least32_t</code></li>
|
||||
</ul>
|
||||
<p>All other minimum-width integer types are optional.</p>
|
||||
<h2>Fastest minimum-width integer types</h2>
|
||||
<p>The typedef <code>int_fast#_t</code>, with # replaced by the width,
|
||||
designates the fastest signed integer type with a width of at least # bits.
|
||||
Similarly, the typedef name <code>uint_fast#_t</code> designates the fastest
|
||||
unsigned integer type with a width of at least # bits.</p>
|
||||
<p>There is no guarantee that these types are fastest for all purposes. In
|
||||
any case, however, they satisfy the signedness and width requirements.</p>
|
||||
<p>Required fastest minimum-width integer types:</p>
|
||||
<ul>
|
||||
<li><code>int_fast8_t</code></li>
|
||||
<li><code>int_fast16_t</code></li>
|
||||
<li><code>int_fast32_t</code></li>
|
||||
<li><code>uint_fast8_t</code></li>
|
||||
<li><code>uint_fast16_t</code></li>
|
||||
<li><code>uint_fast32_t</code></li>
|
||||
</ul>
|
||||
<p>All other fastest minimum-width integer types are optional.</p>
|
||||
<h2>Greatest-width integer types</h2>
|
||||
<p>The typedef <code>intmax_t </code>designates a signed integer type capable of
|
||||
representing any value of any signed integer type.</p>
|
||||
<p>The typedef <code>uintmax_t</code> designates an unsigned integer type
|
||||
capable of representing any value of any unsigned integer type.</p>
|
||||
<p>These types are required.</p>
|
||||
<hr>
|
||||
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->06 Nov 2007<!--webbot bot="Timestamp" endspan i-checksum="15272" -->
|
||||
</p>
|
||||
<p>© Copyright Beman Dawes 2000</p>
|
||||
|
||||
<p>Distributed under the Boost Software License, Version 1.0. See
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
59
doc/Jamfile.v2
Normal file
59
doc/Jamfile.v2
Normal file
@ -0,0 +1,59 @@
|
||||
|
||||
|
||||
# Copyright John Maddock 2005. Use, modification, and distribution are
|
||||
# subject to the Boost Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
using quickbook ;
|
||||
|
||||
xml integer : integer.qbk ;
|
||||
boostbook standalone
|
||||
:
|
||||
integer
|
||||
:
|
||||
# HTML options first:
|
||||
# Use graphics not text for navigation:
|
||||
<xsl:param>navig.graphics=1
|
||||
# How far down we chunk nested sections, basically all of them:
|
||||
<xsl:param>chunk.section.depth=1
|
||||
# Don't put the first section on the same page as the TOC:
|
||||
<xsl:param>chunk.first.sections=0
|
||||
# How far down sections get TOC's
|
||||
<xsl:param>toc.section.depth=1
|
||||
# Max depth in each TOC:
|
||||
<xsl:param>toc.max.depth=1
|
||||
# How far down we go with TOC's
|
||||
<xsl:param>generate.section.toc.level=4
|
||||
# Path for links to Boost:
|
||||
<xsl:param>boost.root=../../../..
|
||||
# Path for libraries index:
|
||||
<xsl:param>boost.libraries=../../../../libs/libraries.htm
|
||||
# Use the main Boost stylesheet:
|
||||
<xsl:param>html.stylesheet=../../../../doc/html/boostbook.css
|
||||
|
||||
# PDF Options:
|
||||
# TOC Generation: this is needed for FOP-0.9 and later:
|
||||
<xsl:param>fop1.extensions=0
|
||||
# Or enable this if you're using XEP:
|
||||
<xsl:param>xep.extensions=1
|
||||
# TOC generation: this is needed for FOP 0.2, but must not be set to zero for FOP-0.9!
|
||||
<xsl:param>fop.extensions=0
|
||||
# No indent on body text:
|
||||
<xsl:param>body.start.indent=0pt
|
||||
# Margin size:
|
||||
<xsl:param>page.margin.inner=0.5in
|
||||
# Margin size:
|
||||
<xsl:param>page.margin.outer=0.5in
|
||||
# Yes, we want graphics for admonishments:
|
||||
<xsl:param>admon.graphics=1
|
||||
# Set this one for PDF generation *only*:
|
||||
# default pnd graphics are awful in PDF form,
|
||||
# better use SVG's instead:
|
||||
<format>pdf:<xsl:param>admon.graphics.extension=".svg"
|
||||
<format>pdf:<xsl:param>admon.graphics.path=$(boost-images)/
|
||||
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/libs/regex/doc/html
|
||||
;
|
||||
|
||||
install pdf-install : standalone : <location>. <install-type>PDF ;
|
||||
|
||||
|
235
doc/html/boost_integer/cstdint.html
Normal file
235
doc/html/boost_integer/cstdint.html
Normal file
@ -0,0 +1,235 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Standard Integer Types</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/html/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="../index.html" title="Boost.Integer">
|
||||
<link rel="next" href="traits.html" title="Integer Traits">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../index.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="traits.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.cstdint"></a><a class="link" href="cstdint.html" title="Standard Integer Types"> Standard Integer Types</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.overview">Overview</a></span></dt>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.rationale"> Rationale</a></span></dt>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.ce"> <span class="emphasis"><em>Caveat emptor</em></span></a></span></dt>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.exact_width_integer_types">Exact-width
|
||||
integer types</a></span></dt>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.minimum_width_integer_types">Minimum-width
|
||||
integer types</a></span></dt>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.fastest_minimum_width_integer_types">Fastest
|
||||
minimum-width integer types</a></span></dt>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.greatest_width_integer_types">Greatest-width
|
||||
integer types</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.overview"></a><a class="link" href="cstdint.html#boost_integer.cstdint.overview" title="Overview">Overview</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The header <code class="literal"><a href="../../../../../boost/cstdint.hpp" target="_top"><boost/cstdint.hpp></a></code>
|
||||
provides the typedef's useful for writing portable code that requires certain
|
||||
integer widths. All typedef's are in namespace boost.
|
||||
</p>
|
||||
<p>
|
||||
The specifications are based on the ISO/IEC 9899:1999 C Language standard
|
||||
header <stdint.h>. The 64-bit types required by the C standard are
|
||||
not required in the boost header, and may not be supplied in all implementations,
|
||||
because <code class="literal">long long</code> is not [yet] included in the C++ standard.
|
||||
</p>
|
||||
<p>
|
||||
See <a href="../../../test/cstdint_test.cpp" target="_top">cstdint_test.cpp</a> for
|
||||
a test program.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.rationale"></a><a class="link" href="cstdint.html#boost_integer.cstdint.rationale" title="Rationale"> Rationale</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The organization of the Boost.Integer headers and classes is designed to
|
||||
take advantage of <stdint.h> types from the 1999 C standard without
|
||||
resorting to undefined behavior in terms of the 1998 C++ standard. The header
|
||||
<boost/cstdint.hpp> makes the standard integer types safely available
|
||||
in namespace <code class="literal">boost</code> without placing any names in namespace
|
||||
<code class="literal">std</code>. As always, the intension is to complement rather
|
||||
than compete with the C++ Standard Library. Should some future C++ standard
|
||||
include <stdint.h> and <cstdint>, then <boost/cstdint.hpp>
|
||||
will continue to function, but will become redundant and may be safely deprecated.
|
||||
</p>
|
||||
<p>
|
||||
Because these are boost headers, their names conform to boost header naming
|
||||
conventions rather than C++ Standard Library header naming conventions.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.ce"></a><a class="link" href="cstdint.html#boost_integer.cstdint.ce" title="Caveat emptor"> <span class="emphasis"><em>Caveat emptor</em></span></a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
As an implementation artifact, certain C <limits.h> macro names may
|
||||
possibly be visible to users of <boost/cstdint.hpp>. Don't use these
|
||||
macros; they are not part of any Boost-specified interface. Use <code class="literal">boost::integer_traits<></code>
|
||||
or <code class="literal">std::numeric_limits<></code> instead.
|
||||
</p>
|
||||
<p>
|
||||
As another implementation artifact, certain C <stdint.h> typedef names
|
||||
may possibly be visible in the global namespace to users of <boost/cstdint.hpp>.
|
||||
Don't use these names, they are not part of any Boost-specified interface.
|
||||
Use the respective names in namespace <code class="literal">boost</code> instead.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.exact_width_integer_types"></a><a class="link" href="cstdint.html#boost_integer.cstdint.exact_width_integer_types" title="Exact-width integer types">Exact-width
|
||||
integer types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The typedef <code class="literal">int#_t</code>, with # replaced by the width, designates
|
||||
a signed integer type of exactly # bits; for example <code class="literal">int8_t</code>
|
||||
denotes an 8-bit signed integer type. Similarly, the typedef <code class="literal">uint#_t</code>
|
||||
designates an unsigned integer type of exactly # bits.
|
||||
</p>
|
||||
<p>
|
||||
These types are optional. However, if an implementation provides integer
|
||||
types with widths of 8, 16, 32, or 64 bits, it shall define the corresponding
|
||||
typedef names.
|
||||
</p>
|
||||
<p>
|
||||
The absence of int64_t and uint64_t is indicated by the macro <code class="computeroutput"><span class="identifier">BOOST_NO_INT64_T</span></code>.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.minimum_width_integer_types"></a><a class="link" href="cstdint.html#boost_integer.cstdint.minimum_width_integer_types" title="Minimum-width integer types">Minimum-width
|
||||
integer types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The typedef <code class="literal">int_least#_t</code>, with # replaced by the width,
|
||||
designates a signed integer type with a width of at least # bits, such that
|
||||
no signed integer type with lesser size has at least the specified width.
|
||||
Thus, <code class="literal">int_least32_t</code> denotes a signed integer type with
|
||||
a width of at least 32 bits. Similarly, the typedef name <code class="literal">uint_least#_t</code>
|
||||
designates an unsigned integer type with a width of at least # bits, such
|
||||
that no unsigned integer type with lesser size has at least the specified
|
||||
width.
|
||||
</p>
|
||||
<p>
|
||||
Required minimum-width integer types:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul type="disc">
|
||||
<li><code class="literal">int_least8_t</code></li>
|
||||
<li><code class="literal">int_least16_t</code></li>
|
||||
<li><code class="literal">int_least32_t</code></li>
|
||||
<li><code class="literal">uint_least8_t</code></li>
|
||||
<li><code class="literal">uint_least16_t</code></li>
|
||||
<li><code class="literal">uint_least32_t</code></li>
|
||||
</ul></div>
|
||||
<p>
|
||||
The types:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul type="disc">
|
||||
<li><code class="literal">int_least64_t</code></li>
|
||||
<li><code class="literal">uint_least64_t</code></li>
|
||||
</ul></div>
|
||||
<p>
|
||||
Are available only if, after inclusion of <code class="literal"><boost/cstdint.hpp></code>
|
||||
the macro <code class="computeroutput"><span class="identifier">BOOST_NO_INT64_T</span></code>
|
||||
is <span class="emphasis"><em><span class="bold"><strong>not defined</strong></span></em></span>.
|
||||
</p>
|
||||
<p>
|
||||
All other minimum-width integer types are optional.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.fastest_minimum_width_integer_types"></a><a class="link" href="cstdint.html#boost_integer.cstdint.fastest_minimum_width_integer_types" title="Fastest minimum-width integer types">Fastest
|
||||
minimum-width integer types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The typedef <code class="literal">int_fast#_t</code>, with # replaced by the width,
|
||||
designates the fastest signed integer type with a width of at least # bits.
|
||||
Similarly, the typedef name <code class="literal">uint_fast#_t</code> designates the
|
||||
fastest unsigned integer type with a width of at least # bits.
|
||||
</p>
|
||||
<p>
|
||||
There is no guarantee that these types are fastest for all purposes. In any
|
||||
case, however, they satisfy the signedness and width requirements.
|
||||
</p>
|
||||
<p>
|
||||
Required fastest minimum-width integer types:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul type="disc">
|
||||
<li><code class="literal">int_fast8_t</code></li>
|
||||
<li><code class="literal">int_fast16_t</code></li>
|
||||
<li><code class="literal">int_fast32_t</code></li>
|
||||
<li><code class="literal">uint_fast8_t</code></li>
|
||||
<li><code class="literal">uint_fast16_t</code></li>
|
||||
<li><code class="literal">uint_fast32_t</code></li>
|
||||
</ul></div>
|
||||
<p>
|
||||
The types:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul type="disc">
|
||||
<li><code class="literal">int_fast64_t</code></li>
|
||||
<li><code class="literal">uint_fast64_t</code></li>
|
||||
</ul></div>
|
||||
<p>
|
||||
Are available only if, after inclusion of <code class="literal"><boost/cstdint.hpp></code>
|
||||
the macro <code class="computeroutput"><span class="identifier">BOOST_NO_INT64_T</span></code>
|
||||
is <span class="emphasis"><em><span class="bold"><strong>not defined</strong></span></em></span>.
|
||||
</p>
|
||||
<p>
|
||||
All other fastest minimum-width integer types are optional.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.greatest_width_integer_types"></a><a class="link" href="cstdint.html#boost_integer.cstdint.greatest_width_integer_types" title="Greatest-width integer types">Greatest-width
|
||||
integer types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The typedef <code class="literal">intmax_t </code>designates a signed integer type
|
||||
capable of representing any value of any signed integer type.
|
||||
</p>
|
||||
<p>
|
||||
The typedef <code class="literal">uintmax_t</code> designates an unsigned integer type
|
||||
capable of representing any value of any unsigned integer type.
|
||||
</p>
|
||||
<p>
|
||||
These types are required.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001 -2009 Beman Dawes, Daryle Walker, Gennaro Prota,
|
||||
John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../index.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="traits.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
82
doc/html/boost_integer/history.html
Normal file
82
doc/html/boost_integer/history.html
Normal file
@ -0,0 +1,82 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>History</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/html/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="minmax.html" title="Compile time min/max calculation">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="minmax.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.history"></a><a class="link" href="history.html" title="History"> History</a>
|
||||
</h2></div></div></div>
|
||||
<a name="boost_integer.history.1_42_0"></a><h5>
|
||||
<a name="id677364"></a>
|
||||
<a class="link" href="history.html#boost_integer.history.1_42_0">1.42.0</a>
|
||||
</h5>
|
||||
<div class="itemizedlist"><ul type="disc">
|
||||
<li>
|
||||
Reverted Trunk to release branch state (i.e. a "known good state").
|
||||
</li>
|
||||
<li>
|
||||
Fixed issues: <a href="https://svn.boost.org/trac/boost/ticket/653" target="_top">653</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3084" target="_top">3084</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3177" target="_top">3177</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3180" target="_top">3180</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3548" target="_top">3568</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3657" target="_top">3657</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/2134" target="_top">2134</a>.
|
||||
</li>
|
||||
<li>
|
||||
Added long long support to <code class="literal">boost::static_log2</code>, <code class="literal">boost::static_signed_min</code>,
|
||||
<code class="literal">boost::static_signed_max</code>, <code class="literal">boost::static_unsigned_min</code><code class="literal">boost::static_unsigned_max</code>,
|
||||
when available.
|
||||
</li>
|
||||
<li>
|
||||
The argument type and the result type of <code class="literal">boost::static_signed_min</code>
|
||||
etc are now typedef'd. Formerly, they were hardcoded as <code class="literal">unsigned
|
||||
long</code> and <code class="literal">int</code> respectively. Please, use the provided
|
||||
typedefs in new code (and update old code as soon as possible).
|
||||
</li>
|
||||
</ul></div>
|
||||
<a name="boost_integer.history.1_32_0"></a><h5>
|
||||
<a name="id677466"></a>
|
||||
<a class="link" href="history.html#boost_integer.history.1_32_0">1.32.0</a>
|
||||
</h5>
|
||||
<div class="itemizedlist"><ul type="disc"><li>
|
||||
The argument type and the result type of <code class="literal">boost::static_log2</code>
|
||||
are now typedef'd. Formerly, they were hardcoded as <code class="literal">unsigned long</code>
|
||||
and <code class="literal">int</code> respectively. Please, use the provided typedefs
|
||||
in new code (and update old code as soon as possible).
|
||||
</li></ul></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001 -2009 Beman Dawes, Daryle Walker, Gennaro Prota,
|
||||
John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="minmax.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
323
doc/html/boost_integer/integer.html
Normal file
323
doc/html/boost_integer/integer.html
Normal file
@ -0,0 +1,323 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Integer Type Selection</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/html/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="traits.html" title="Integer Traits">
|
||||
<link rel="next" href="mask.html" title="Integer Masks">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="traits.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="mask.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.integer"></a><a class="link" href="integer.html" title="Integer Type Selection"> Integer Type Selection</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.synopsis"> Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.easiest"> Easiest-to-Manipulate
|
||||
Types</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.sized"> Sized Types</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.example">Example</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.demonstration_program">Demonstration
|
||||
Program</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.rationale">Rationale</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.alternative">Alternative</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.credits">Credits</a></span></dt>
|
||||
</dl></div>
|
||||
<p>
|
||||
The <a href="../../../../../boost/integer.hpp" target="_top"><boost/integer.hpp></a>
|
||||
type selection templates allow integer types to be selected based on desired
|
||||
characteristics such as number of bits or maximum value. This facility is particularly
|
||||
useful for solving generic programming problems.
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.synopsis"></a><a class="link" href="integer.html#boost_integer.integer.synopsis" title="Synopsis"> Synopsis</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
|
||||
<span class="special">{</span>
|
||||
<span class="comment">// fast integers from least integers
|
||||
</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">LeastInt</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_fast_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// signed
|
||||
</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">int</span> <span class="identifier">Bits</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// unsigned
|
||||
</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">int</span> <span class="identifier">Bits</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">uint_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// signed
|
||||
</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">MaxValue</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_max_value_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">MinValue</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_min_value_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// unsigned
|
||||
</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">Value</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">uint_value_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
<span class="special">}</span> <span class="comment">// namespace boost
|
||||
</span></pre>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.easiest"></a><a class="link" href="integer.html#boost_integer.integer.easiest" title="Easiest-to-Manipulate Types"> Easiest-to-Manipulate
|
||||
Types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The <code class="literal">int_fast_t</code> class template maps its input type to the
|
||||
next-largest type that the processor can manipulate the easiest, or to itself
|
||||
if the input type is already an easy-to-manipulate type. For instance, processing
|
||||
a bunch of <code class="literal">char</code> objects may go faster if they were converted
|
||||
to <code class="literal">int</code> objects before processing. The input type, passed
|
||||
as the only template parameter, must be a built-in integral type, except
|
||||
<code class="literal">bool</code>. Unsigned integral types can be used, as well as
|
||||
signed integral types, despite the name. The output type is given as the
|
||||
class member <code class="literal">fast</code>.
|
||||
</p>
|
||||
<p>
|
||||
<span class="bold"><strong>Implementation Notes:</strong></span> By default, the output
|
||||
type is identical to the input type. Eventually, this code's implementation
|
||||
should be conditionalized for each platform to give accurate mappings between
|
||||
the built-in types and the easiest-to-manipulate built-in types. Also, there
|
||||
is no guarantee that the output type actually is easier to manipulate than
|
||||
the input type.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.sized"></a><a class="link" href="integer.html#boost_integer.integer.sized" title="Sized Types"> Sized Types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The <code class="literal">int_t</code>, <code class="literal">uint_t</code>, <code class="literal">int_max_value_t</code>,
|
||||
<code class="literal">int_min_value_t</code>, and <code class="literal">uint_value_t</code> class
|
||||
templates find the most appropiate built-in integral type for the given template
|
||||
parameter. This type is given by the class member <code class="literal">least</code>.
|
||||
The easiest-to-manipulate version of that type is given by the class member
|
||||
<code class="literal">fast</code>. The following table describes each template's criteria.
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="id673121"></a><p class="title"><b>Table 1. Criteria for the Sized Type Class Templates</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Criteria for the Sized Type Class Templates">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Class Template
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Template Parameter Mapping
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::int_t<N></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The smallest built-in signed integral type with at least <span class="emphasis"><em>N</em></span>
|
||||
bits, including the sign bit. The parameter should be a positive number.
|
||||
A compile-time error results if the parameter is larger than the number
|
||||
of bits in the largest integer type.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::uint_t<N></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The smallest built-in unsigned integral type with at least <span class="emphasis"><em>N</em></span>
|
||||
bits. The parameter should be a positive number. A compile-time error
|
||||
results if the parameter is larger than the number of bits in the largest
|
||||
integer type.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::int_max_value_t<V></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The smallest built-in signed integral type that can hold all the values
|
||||
in the inclusive range <span class="emphasis"><em>0 - V</em></span>. The parameter should
|
||||
be a positive number.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::int_min_value_t<V></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The smallest built-in signed integral type that can hold all the values
|
||||
in the inclusive range <span class="emphasis"><em>V-0</em></span>. The parameter should
|
||||
be a negative number.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::uint_value_t<V></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The smallest built-in unsigned integral type that can hold all positive
|
||||
values up to and including <span class="emphasis"><em>V</em></span>. The parameter should
|
||||
be a positive number.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break">
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.example"></a><a class="link" href="integer.html#boost_integer.integer.example" title="Example">Example</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="comment">//...
|
||||
</span>
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">int_t</span><span class="special"><</span><span class="number">24</span><span class="special">>::</span><span class="identifier">least</span> <span class="identifier">my_var</span><span class="special">;</span> <span class="comment">// my_var has at least 24-bits
|
||||
</span> <span class="comment">//...
|
||||
</span> <span class="comment">// This one is guarenteed not to be truncated:
|
||||
</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">int_max_value_t</span><span class="special"><</span><span class="number">1000</span><span class="special">>::</span><span class="identifier">least</span> <span class="identifier">my1000</span> <span class="special">=</span> <span class="number">1000</span><span class="special">;</span>
|
||||
<span class="comment">//...
|
||||
</span> <span class="comment">// This one is guarenteed not to be truncated, and as fast
|
||||
</span> <span class="comment">// to manipulate as possible, it's size may be greater than
|
||||
</span> <span class="comment">// that of my1000:
|
||||
</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">int_max_value_t</span><span class="special"><</span><span class="number">1000</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">my_fast1000</span> <span class="special">=</span> <span class="number">1000</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.demonstration_program"></a><a class="link" href="integer.html#boost_integer.integer.demonstration_program" title="Demonstration Program">Demonstration
|
||||
Program</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The program <a href="../../../test/integer_test.cpp" target="_top">integer_test.cpp</a>
|
||||
is a simplistic demonstration of the results from instantiating various examples
|
||||
of the sized type class templates.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.rationale"></a><a class="link" href="integer.html#boost_integer.integer.rationale" title="Rationale">Rationale</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The rationale for the design of the templates in this header includes:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul type="disc">
|
||||
<li>
|
||||
Avoid recursion because of concern about C++'s limited guaranteed recursion
|
||||
depth (17).
|
||||
</li>
|
||||
<li>
|
||||
Avoid macros on general principles.
|
||||
</li>
|
||||
<li>
|
||||
Try to keep the design as simple as possible.
|
||||
</li>
|
||||
</ul></div>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.alternative"></a><a class="link" href="integer.html#boost_integer.integer.alternative" title="Alternative">Alternative</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
If the number of bits required is known beforehand, it may be more appropriate
|
||||
to use the types supplied in <a href="../../../../../boost/cstdint.hpp" target="_top"><boost/cstdint.hpp></a>.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.credits"></a><a class="link" href="integer.html#boost_integer.integer.credits" title="Credits">Credits</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The author of most of the Boost integer type choosing templates is <a href="http://www.boost.org/people/beman_dawes.html" target="_top">Beman Dawes</a>. He
|
||||
gives thanks to Valentin Bonnard and <a href="http://www.boost.org/people/kevlin_henney.htm" target="_top">Kevlin
|
||||
Henney</a> for sharing their designs for similar templates. <a href="http://www.boost.org/people/daryle_walker.html" target="_top">Daryle
|
||||
Walker</a> designed the value-based sized templates.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001 -2009 Beman Dawes, Daryle Walker, Gennaro Prota,
|
||||
John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="traits.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="mask.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
184
doc/html/boost_integer/log2.html
Normal file
184
doc/html/boost_integer/log2.html
Normal file
@ -0,0 +1,184 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Compile time log2 Calculation</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/html/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="mask.html" title="Integer Masks">
|
||||
<link rel="next" href="minmax.html" title="Compile time min/max calculation">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="mask.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="minmax.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.log2"></a><a class="link" href="log2.html" title="Compile time log2 Calculation"> Compile time log2 Calculation</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.usage">Usage</a></span></dt>
|
||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.example">Example</a></span></dt>
|
||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.demonstration_program">Demonstration
|
||||
Program</a></span></dt>
|
||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.rationale">Rationale</a></span></dt>
|
||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.credits">Credits</a></span></dt>
|
||||
</dl></div>
|
||||
<p>
|
||||
The class template in <a href="../../../../../boost/integer/static_log2.hpp" target="_top"><boost/integer/static_log2.hpp></a>
|
||||
determines the position of the highest bit in a given value. This facility
|
||||
is useful for solving generic programming problems.
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.log2.synopsis"></a><a class="link" href="log2.html#boost_integer.log2.synopsis" title="Synopsis">Synopsis</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
|
||||
<span class="special">{</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined</em></span> <span class="identifier">static_log2_argument_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined</em></span> <span class="identifier">static_log2_result_type</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">static_log2_argument_type</span> <span class="identifier">arg</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_log2</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">static_log2_result_type</span> <span class="identifier">value</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_log2</span><span class="special"><</span> <span class="number">0</span> <span class="special">></span>
|
||||
<span class="special">{</span>
|
||||
<span class="comment">// The logarithm of zero is undefined.
|
||||
</span> <span class="special">};</span>
|
||||
|
||||
|
||||
<span class="special">}</span> <span class="comment">// namespace boost
|
||||
</span></pre>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.log2.usage"></a><a class="link" href="log2.html#boost_integer.log2.usage" title="Usage">Usage</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The <code class="literal">boost::static_log2</code> class template takes one template
|
||||
parameter, a value of type <code class="literal">static_log2_argument_type</code>.
|
||||
The template only defines one member, <code class="literal">value</code>, which gives
|
||||
the truncated base-two logarithm of the template argument.
|
||||
</p>
|
||||
<p>
|
||||
Since the logarithm of zero, for any base, is undefined, there is a specialization
|
||||
of <code class="literal">static_log2</code> for a template argument of zero. This specialization
|
||||
has no members, so an attempt to use the base-two logarithm of zero results
|
||||
in a compile-time error.
|
||||
</p>
|
||||
<p>
|
||||
Note:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul type="disc">
|
||||
<li>
|
||||
<code class="literal">static_log2_argument_type</code> is an <span class="emphasis"><em>unsigned integer
|
||||
type</em></span> (C++ standard, 3.9.1p3).
|
||||
</li>
|
||||
<li>
|
||||
<code class="literal">static_log2_result_type</code> is an <span class="emphasis"><em>integer type</em></span>
|
||||
(C++ standard, 3.9.1p7).
|
||||
</li>
|
||||
</ul></div>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.log2.example"></a><a class="link" href="log2.html#boost_integer.log2.example" title="Example">Example</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="string">"boost/integer/static_log2.hpp"</span>
|
||||
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">static_log2_argument_type</span> <span class="identifier">value</span> <span class="special">></span>
|
||||
<span class="keyword">bool</span> <span class="identifier">is_it_what</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">static_log2</span><span class="special"><</span><span class="identifier">value</span><span class="special">></span> <span class="identifier">lb_type</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">temp</span> <span class="special">=</span> <span class="identifier">lb_type</span><span class="special">::</span><span class="identifier">value</span><span class="special">;</span>
|
||||
<span class="comment">//...
|
||||
</span> <span class="keyword">return</span> <span class="special">(</span><span class="identifier">temp</span> <span class="special">%</span> <span class="number">2</span><span class="special">)</span> <span class="special">!=</span> <span class="number">0</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
|
||||
<span class="comment">//...
|
||||
</span>
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">bool</span> <span class="identifier">temp</span> <span class="special">=</span> <span class="identifier">is_it_what</span><span class="special"><</span><span class="number">2000</span><span class="special">>();</span>
|
||||
<span class="comment">//...
|
||||
</span><span class="preprocessor"># if</span> <span class="number">0</span>
|
||||
<span class="identifier">temp</span> <span class="special">=</span> <span class="identifier">is_it_what</span><span class="special"><</span><span class="number">0</span><span class="special">>();</span> <span class="comment">// would give an error
|
||||
</span><span class="preprocessor"># endif</span>
|
||||
<span class="comment">//...
|
||||
</span> <span class="identifier">temp</span> <span class="special">=</span> <span class="identifier">is_it_what</span><span class="special"><</span><span class="number">24</span><span class="special">>();</span>
|
||||
<span class="comment">//...
|
||||
</span><span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.log2.demonstration_program"></a><a class="link" href="log2.html#boost_integer.log2.demonstration_program" title="Demonstration Program">Demonstration
|
||||
Program</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The program <a href="../../../test/static_log2_test.cpp" target="_top">static_log2_test.cpp</a>
|
||||
is a simplistic demonstration of the results from instantiating various examples
|
||||
of the binary logarithm class template.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.log2.rationale"></a><a class="link" href="log2.html#boost_integer.log2.rationale" title="Rationale">Rationale</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The base-two (binary) logarithm, abbreviated lb, function is occasionally
|
||||
used to give order-estimates of computer algorithms. The truncated logarithm
|
||||
can be considered the highest power-of-two in a value, which corresponds
|
||||
to the value's highest set bit (for binary integers). Sometimes the highest-bit
|
||||
position could be used in generic programming, which requires the position
|
||||
to be statically (<span class="emphasis"><em>i.e.</em></span> at compile-time) available.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.log2.credits"></a><a class="link" href="log2.html#boost_integer.log2.credits" title="Credits">Credits</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The original version of the Boost binary logarithm class template was written
|
||||
by <a href="http://www.boost.org/people/daryle_walker.html" target="_top">Daryle Walker</a>
|
||||
and then enhanced by Giovanni Bajo with support for compilers without partial
|
||||
template specialization. The current version was suggested, together with
|
||||
a reference implementation, by Vesa Karvonen. Gennaro Prota wrote the actual
|
||||
source file.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001 -2009 Beman Dawes, Daryle Walker, Gennaro Prota,
|
||||
John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="mask.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="minmax.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
376
doc/html/boost_integer/mask.html
Normal file
376
doc/html/boost_integer/mask.html
Normal file
@ -0,0 +1,376 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Integer Masks</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/html/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="integer.html" title="Integer Type Selection">
|
||||
<link rel="next" href="log2.html" title="Compile time log2 Calculation">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="integer.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="log2.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.mask"></a><a class="link" href="mask.html" title="Integer Masks"> Integer Masks</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.overview">Overview</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.single_bit_mask_class_template">Single
|
||||
Bit-Mask Class Template</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.group_bit_mask_class_template">Group
|
||||
Bit-Mask Class Template</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.implementation_notes">Implementation
|
||||
Notes</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.example">Example</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.demonstration_program">Demonstration
|
||||
Program</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.rationale">Rationale</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.credits">Credits</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.overview"></a><a class="link" href="mask.html#boost_integer.mask.overview" title="Overview">Overview</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The class templates in <a href="../../../../../boost/integer/integer_mask.hpp" target="_top"><boost/integer/integer_mask.hpp></a>
|
||||
provide bit masks for a certain bit position or a contiguous-bit pack of
|
||||
a certain size. The types of the masking constants come from the <a class="link" href="integer.html" title="Integer Type Selection">integer
|
||||
type selection templates</a> header.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.synopsis"></a><a class="link" href="mask.html#boost_integer.mask.synopsis" title="Synopsis">Synopsis</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">cstddef</span><span class="special">></span> <span class="comment">// for std::size_t
|
||||
</span>
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span>
|
||||
<span class="special">{</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">Bit</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">high_bit_mask_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">least</span> <span class="identifier">high_bit</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">fast</span> <span class="identifier">high_bit_fast</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">bit_position</span> <span class="special">=</span> <span class="identifier">Bit</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">Bits</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">low_bits_mask_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">least</span> <span class="identifier">sig_bits</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">fast</span> <span class="identifier">sig_bits_fast</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">bit_count</span> <span class="special">=</span> <span class="identifier">Bits</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// Specializations for low_bits_mask_t exist for certain bit counts.
|
||||
</span>
|
||||
<span class="special">}</span> <span class="comment">// namespace boost
|
||||
</span></pre>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.single_bit_mask_class_template"></a><a class="link" href="mask.html#boost_integer.mask.single_bit_mask_class_template" title="Single Bit-Mask Class Template">Single
|
||||
Bit-Mask Class Template</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The <code class="literal">boost::high_bit_mask_t</code> class template provides constants
|
||||
for bit masks representing the bit at a certain position. The masks are equivalent
|
||||
to the value 2<sup>Bit</sup>, where <code class="literal">Bit</code> is the template parameter.
|
||||
The bit position must be a nonnegative number from zero to <span class="emphasis"><em>Max</em></span>,
|
||||
where Max is one less than the number of bits supported by the largest unsigned
|
||||
built-in integral type. The following table describes the members of an instantiation
|
||||
of <code class="literal">high_bit_mask_t</code>.
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="id674116"></a><p class="title"><b>Table 2. Members of the `boost::high_bit_mask_t` Class Template</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Members of the `boost::high_bit_mask_t` Class Template">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Member
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Meaning
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">least</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The smallest unsigned built-in type that supports the given bit position.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">fast</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The quick-to-manipulate analog of <code class="literal">least</code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">high_bit</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
A <code class="literal">least</code> constant of the desired bit-masking value.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">high_bit_fast</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
A <code class="literal">fast</code> analog of <code class="literal">high_bit</code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">bit_position</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The value of the template parameter, in case its needed from a renamed
|
||||
instantiation of the class template.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break">
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.group_bit_mask_class_template"></a><a class="link" href="mask.html#boost_integer.mask.group_bit_mask_class_template" title="Group Bit-Mask Class Template">Group
|
||||
Bit-Mask Class Template</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The <code class="literal">boost::low_bits_mask_t</code> class template provides constants
|
||||
for bit masks representing the lowest bits of a certain amount. The masks
|
||||
are equivalent to the value (2<sup>Bits</sup> - 1), where <code class="literal">Bits</code> is
|
||||
the template parameter. The bit amount must be a nonnegative number from
|
||||
zero to <span class="emphasis"><em>Max</em></span>, where Max is the number of bits supported
|
||||
by the largest unsigned built-in integral type. The following table describes
|
||||
the members of an instantiation of <code class="literal">low_bits_mask_t</code>.
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="id674318"></a><p class="title"><b>Table 3. Members of the [^boost::low_bits_mask_t] Class Template</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Members of the [^boost::low_bits_mask_t] Class Template">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Member
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Meaning
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">least</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The smallest unsigned built-in type that supports the given bit count.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">fast</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The quick-to-manipulate analog of <code class="literal">least</code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">sig_bits</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
A <code class="literal">least</code> constant of the desired bit-masking value.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">sig_bits_fast</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
A <code class="literal">fast</code> analog of <code class="literal">sig_bits</code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">bit_count</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The value of the template parameter, in case its needed from a renamed
|
||||
instantiation of the class template.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break">
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.implementation_notes"></a><a class="link" href="mask.html#boost_integer.mask.implementation_notes" title="Implementation Notes">Implementation
|
||||
Notes</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
When <code class="literal">Bits</code> is the exact size of a built-in unsigned type,
|
||||
the implementation has to change to prevent undefined behavior. Therefore,
|
||||
there are specializations of <code class="literal">low_bits_mask_t</code> at those
|
||||
bit counts.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.example"></a><a class="link" href="mask.html#boost_integer.mask.example" title="Example">Example</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">integer_mask</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="comment">//...
|
||||
</span>
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">high_bit_mask_t</span><span class="special"><</span><span class="number">29</span><span class="special">></span> <span class="identifier">mask1_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">low_bits_mask_t</span><span class="special"><</span><span class="number">15</span><span class="special">></span> <span class="identifier">mask2_type</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">mask1_type</span><span class="special">::</span><span class="identifier">least</span> <span class="identifier">my_var1</span><span class="special">;</span>
|
||||
<span class="identifier">mask2_type</span><span class="special">::</span><span class="identifier">fast</span> <span class="identifier">my_var2</span><span class="special">;</span>
|
||||
<span class="comment">//...
|
||||
</span>
|
||||
<span class="identifier">my_var1</span> <span class="special">|=</span> <span class="identifier">mask1_type</span><span class="special">::</span><span class="identifier">high_bit</span><span class="special">;</span>
|
||||
<span class="identifier">my_var2</span> <span class="special">&=</span> <span class="identifier">mask2_type</span><span class="special">::</span><span class="identifier">sig_bits_fast</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">//...
|
||||
</span><span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.demonstration_program"></a><a class="link" href="mask.html#boost_integer.mask.demonstration_program" title="Demonstration Program">Demonstration
|
||||
Program</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The program <a href="../../../test/integer_mask_test.cpp" target="_top">integer_mask_test.cpp</a>
|
||||
is a simplistic demonstration of the results from instantiating various examples
|
||||
of the bit mask class templates.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.rationale"></a><a class="link" href="mask.html#boost_integer.mask.rationale" title="Rationale">Rationale</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The class templates in this header are an extension of the <a class="link" href="integer.html" title="Integer Type Selection">integer
|
||||
type selection class templates</a>. The new class templates provide the
|
||||
same sized types, but also convienent masks to use when extracting the highest
|
||||
or all the significant bits when the containing built-in type contains more
|
||||
bits. This prevents contaimination of values by the higher, unused bits.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.credits"></a><a class="link" href="mask.html#boost_integer.mask.credits" title="Credits">Credits</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The author of the Boost bit mask class templates is <a href="http://www.boost.org/people/daryle_walker.html" target="_top">Daryle
|
||||
Walker</a>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001 -2009 Beman Dawes, Daryle Walker, Gennaro Prota,
|
||||
John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="integer.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="log2.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
160
doc/html/boost_integer/minmax.html
Normal file
160
doc/html/boost_integer/minmax.html
Normal file
@ -0,0 +1,160 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Compile time min/max calculation</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/html/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="log2.html" title="Compile time log2 Calculation">
|
||||
<link rel="next" href="history.html" title="History">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="log2.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="history.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.minmax"></a><a class="link" href="minmax.html" title="Compile time min/max calculation"> Compile time min/max calculation</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.usage">Usage</a></span></dt>
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.example">Example</a></span></dt>
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.demonstration_program">Demonstration
|
||||
Program</a></span></dt>
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.rationale">Rationale</a></span></dt>
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.credits">Credits</a></span></dt>
|
||||
</dl></div>
|
||||
<p>
|
||||
The class templates in <a href="../../../../../boost/integer/static_min_max.hpp" target="_top"><boost/integer/static_min_max.hpp></a>
|
||||
provide a compile-time evaluation of the minimum or maximum of two integers.
|
||||
These facilities are useful for generic programming problems.
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.minmax.synopsis"></a><a class="link" href="minmax.html#boost_integer.minmax.synopsis" title="Synopsis">Synopsis</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
|
||||
<span class="special">{</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined</em></span> <span class="identifier">static_min_max_signed_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined</em></span> <span class="identifier">static_min_max_unsigned_type</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">static_min_max_signed_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_min_max_signed_type</span> <span class="identifier">Value2</span> <span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_signed_min</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">static_min_max_signed_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_min_max_signed_type</span> <span class="identifier">Value2</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_signed_max</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">static_min_max_unsigned_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_min_max_unsigned_type</span> <span class="identifier">Value2</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_unsigned_min</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">static_min_max_unsigned_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_min_max_unsigned_type</span> <span class="identifier">Value2</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_unsigned_max</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.minmax.usage"></a><a class="link" href="minmax.html#boost_integer.minmax.usage" title="Usage">Usage</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The four class templates provide the combinations for finding the minimum
|
||||
or maximum of two signed or <code class="literal">unsigned</code> (<code class="literal">long</code>)
|
||||
parameters, Value1 and Value2, at compile-time. Each template has a single
|
||||
static data member, <code class="literal">value</code>, which is set to the respective
|
||||
minimum or maximum of the template's parameters.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.minmax.example"></a><a class="link" href="minmax.html#boost_integer.minmax.example" title="Example">Example</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">static_min_max</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="identifier">AddendSize1</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="identifier">AddendSize2</span> <span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">adder</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">public</span><span class="special">:</span>
|
||||
<span class="keyword">static</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">const</span> <span class="identifier">addend1_size</span> <span class="special">=</span> <span class="identifier">AddendSize1</span><span class="special">;</span>
|
||||
<span class="keyword">static</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">const</span> <span class="identifier">addend2_size</span> <span class="special">=</span> <span class="identifier">AddendSize2</span><span class="special">;</span>
|
||||
<span class="keyword">static</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">const</span> <span class="identifier">sum_size</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">static_unsigned_max</span><span class="special"><</span><span class="identifier">AddendSize1</span><span class="special">,</span> <span class="identifier">AddendSize2</span><span class="special">>::</span><span class="identifier">value</span> <span class="special">+</span> <span class="number">1</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="keyword">int</span> <span class="identifier">addend1_type</span><span class="special">[</span> <span class="identifier">addend1_size</span> <span class="special">];</span>
|
||||
<span class="keyword">typedef</span> <span class="keyword">int</span> <span class="identifier">addend2_type</span><span class="special">[</span> <span class="identifier">addend2_size</span> <span class="special">];</span>
|
||||
<span class="keyword">typedef</span> <span class="keyword">int</span> <span class="identifier">sum_type</span><span class="special">[</span> <span class="identifier">sum_size</span> <span class="special">];</span>
|
||||
|
||||
<span class="keyword">void</span> <span class="keyword">operator</span> <span class="special">()(</span> <span class="identifier">addend1_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a1</span><span class="special">,</span> <span class="identifier">addend2_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a2</span><span class="special">,</span> <span class="identifier">sum_type</span> <span class="special">&</span><span class="identifier">s</span> <span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">//...
|
||||
</span>
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">int</span> <span class="keyword">const</span> <span class="identifier">a1</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="number">0</span><span class="special">,</span> <span class="number">4</span><span class="special">,</span> <span class="number">3</span> <span class="special">};</span> <span class="comment">// 340
|
||||
</span> <span class="keyword">int</span> <span class="keyword">const</span> <span class="identifier">a2</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="number">9</span><span class="special">,</span> <span class="number">8</span> <span class="special">};</span> <span class="comment">// 89
|
||||
</span> <span class="keyword">int</span> <span class="identifier">s</span><span class="special">[</span> <span class="number">4</span> <span class="special">];</span>
|
||||
<span class="identifier">adder</span><span class="special"><</span><span class="number">3</span><span class="special">,</span><span class="number">2</span><span class="special">></span> <span class="identifier">obj</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">obj</span><span class="special">(</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,</span> <span class="identifier">s</span> <span class="special">);</span> <span class="comment">// 's' should be 429 or { 9, 2, 4, 0 }
|
||||
</span> <span class="comment">//...
|
||||
</span><span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.minmax.demonstration_program"></a><a class="link" href="minmax.html#boost_integer.minmax.demonstration_program" title="Demonstration Program">Demonstration
|
||||
Program</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The program <a href="../../../test/static_min_max_test.cpp" target="_top">static_min_max_test.cpp</a>
|
||||
is a simplistic demonstration of various comparisons using the compile-time
|
||||
extrema class templates.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.minmax.rationale"></a><a class="link" href="minmax.html#boost_integer.minmax.rationale" title="Rationale">Rationale</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
Sometimes the minimum or maximum of several values needs to be found for
|
||||
later compile-time processing, <span class="emphasis"><em>e.g.</em></span> for a bound for
|
||||
another class template.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.minmax.credits"></a><a class="link" href="minmax.html#boost_integer.minmax.credits" title="Credits">Credits</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The author of the Boost compile-time extrema class templates is <a href="http://www.boost.org/people/daryle_walker.html" target="_top">Daryle
|
||||
Walker</a>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001 -2009 Beman Dawes, Daryle Walker, Gennaro Prota,
|
||||
John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="log2.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="history.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
214
doc/html/boost_integer/traits.html
Normal file
214
doc/html/boost_integer/traits.html
Normal file
@ -0,0 +1,214 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Integer Traits</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/html/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="cstdint.html" title="Standard Integer Types">
|
||||
<link rel="next" href="integer.html" title="Integer Type Selection">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="cstdint.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="integer.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.traits"></a><a class="link" href="traits.html" title="Integer Traits"> Integer Traits</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="traits.html#boost_integer.traits.motivation">Motivation</a></span></dt>
|
||||
<dt><span class="section"><a href="traits.html#boost_integer.traits.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="traits.html#boost_integer.traits.description">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="traits.html#boost_integer.traits.test_program">Test Program</a></span></dt>
|
||||
<dt><span class="section"><a href="traits.html#boost_integer.traits.acknowledgements">Acknowledgements</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.traits.motivation"></a><a class="link" href="traits.html#boost_integer.traits.motivation" title="Motivation">Motivation</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The C++ Standard Library <limits> header supplies a class template
|
||||
<code class="computeroutput"><span class="identifier">numeric_limits</span><span class="special"><></span></code>
|
||||
with specializations for each fundamental type.
|
||||
</p>
|
||||
<p>
|
||||
For integer types, the interesting members of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><></span></code> are:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_specialized</span><span class="special">;</span> <span class="comment">// Will be true for integer types.
|
||||
</span><span class="keyword">static</span> <span class="identifier">T</span> <span class="identifier">min</span><span class="special">()</span> <span class="keyword">throw</span><span class="special">();</span> <span class="comment">// Smallest representable value.
|
||||
</span><span class="keyword">static</span> <span class="identifier">T</span> <span class="identifier">max</span><span class="special">()</span> <span class="keyword">throw</span><span class="special">();</span> <span class="comment">// Largest representable value.
|
||||
</span><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">int</span> <span class="identifier">digits</span><span class="special">;</span> <span class="comment">// For integers, the number of value bits.
|
||||
</span><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">int</span> <span class="identifier">digits10</span><span class="special">;</span> <span class="comment">// The number of base 10 digits that can be represented.
|
||||
</span><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_signed</span><span class="special">;</span> <span class="comment">// True if the type is signed.
|
||||
</span><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_integer</span><span class="special">;</span> <span class="comment">// Will be true for all integer types.
|
||||
</span></pre>
|
||||
<p>
|
||||
For many uses, these are sufficient. But min() and max() are problematical
|
||||
because they are not constant expressions (std::5.19), yet some usages require
|
||||
constant expressions.
|
||||
</p>
|
||||
<p>
|
||||
The template class <code class="literal">integer_traits</code> addresses this problem.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.traits.synopsis"></a><a class="link" href="traits.html#boost_integer.traits.synopsis" title="Synopsis">Synopsis</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">integer_traits</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_integral</span> <span class="special">=</span> <span class="keyword">false</span><span class="special">;</span>
|
||||
<span class="comment">//
|
||||
</span> <span class="comment">// These members are defined only if T is a built-in
|
||||
</span> <span class="comment">// integal type:
|
||||
</span> <span class="comment">//
|
||||
</span> <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">T</span> <span class="identifier">const_min</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">T</span> <span class="identifier">const_max</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.traits.description"></a><a class="link" href="traits.html#boost_integer.traits.description" title="Description">Description</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
Template class <code class="literal">integer_traits</code> is derived from <code class="literal">std::numeric_limits</code>.
|
||||
In general, it adds the single <code class="literal">bool</code> member <code class="literal">is_integral</code>
|
||||
with the compile-time constant value <code class="literal">false</code>. However, for
|
||||
all integral types <code class="literal">T</code> (std::3.9.1/7 [basic.fundamental]),
|
||||
there are specializations provided with the following compile-time constants
|
||||
defined:
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
member
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
type
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
value
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">is_integral</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
bool
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">true</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">const_min</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">T</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
equivalent to <code class="literal">std::numeric_limits<T>::min()</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">const_max</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">T</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
equivalent to <code class="literal">std::numeric_limits<T>::max()</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
<p>
|
||||
Note: A flag <code class="literal">is_integral</code> is provided, because a user-defined
|
||||
integer class should specialize <code class="literal">std::numeric_limits<>::is_integer
|
||||
= true</code>, nonetheless compile-time constants <code class="literal">const_min</code>
|
||||
and <code class="literal">const_max</code> cannot be provided for that user-defined
|
||||
class.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.traits.test_program"></a><a class="link" href="traits.html#boost_integer.traits.test_program" title="Test Program">Test Program</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The program <code class="literal"><a href="../../../test/integer_traits_test.cpp" target="_top">integer_traits_test.cpp</a></code>
|
||||
exercises the <code class="literal">integer_traits</code> class.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.traits.acknowledgements"></a><a class="link" href="traits.html#boost_integer.traits.acknowledgements" title="Acknowledgements">Acknowledgements</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers discussed the integer
|
||||
traits idea on the boost mailing list in August 1999.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001 -2009 Beman Dawes, Daryle Walker, Gennaro Prota,
|
||||
John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="cstdint.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="integer.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
238
doc/html/index.html
Normal file
238
doc/html/index.html
Normal file
@ -0,0 +1,238 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Integer</title>
|
||||
<link rel="stylesheet" href="../../../../doc/html/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="index.html" title="Boost.Integer">
|
||||
<link rel="next" href="boost_integer/cstdint.html" title="Standard Integer Types">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav"><a accesskey="n" href="boost_integer/cstdint.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a></div>
|
||||
<div class="article" lang="en">
|
||||
<div class="titlepage">
|
||||
<div>
|
||||
<div><h2 class="title">
|
||||
<a name="boost_integer"></a>Boost.Integer</h2></div>
|
||||
<div><div class="authorgroup">
|
||||
<div class="author"><h3 class="author">
|
||||
<span class="firstname">Beman</span> <span class="surname">Dawes</span>
|
||||
</h3></div>
|
||||
<div class="author"><h3 class="author">
|
||||
<span class="firstname">Daryle</span> <span class="surname">Walker</span>
|
||||
</h3></div>
|
||||
<div class="author"><h3 class="author">
|
||||
<span class="firstname">Gennaro</span> <span class="surname">Prota</span>
|
||||
</h3></div>
|
||||
<div class="author"><h3 class="author">
|
||||
<span class="firstname">John</span> <span class="surname">Maddock</span>
|
||||
</h3></div>
|
||||
</div></div>
|
||||
<div><p class="copyright">Copyright © 2001 -2009 Beman Dawes, Daryle Walker, Gennaro Prota,
|
||||
John Maddock</p></div>
|
||||
<div><div class="legalnotice">
|
||||
<a name="id662860"></a><p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></div>
|
||||
</div>
|
||||
<hr>
|
||||
</div>
|
||||
<div class="toc">
|
||||
<p><b>Table of Contents</b></p>
|
||||
<dl>
|
||||
<dt><span class="section"><a href="index.html#boost_integer.overview"> Overview</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/cstdint.html"> Standard Integer Types</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/traits.html"> Integer Traits</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/integer.html"> Integer Type Selection</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/mask.html"> Integer Masks</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/log2.html"> Compile time log2 Calculation</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/minmax.html"> Compile time min/max calculation</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/history.html"> History</a></span></dt>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.overview"></a><a class="link" href="index.html#boost_integer.overview" title="Overview"> Overview</a>
|
||||
</h2></div></div></div>
|
||||
<p>
|
||||
Boost.Integer consists of the following components:
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Component
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Header
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Purpose
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
Forward Declarations.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/integer_fwd.hpp" target="_top"><boost/integer_fwd.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Forward declarations of classes and class templates - for use when
|
||||
just the name of a class is needed.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/cstdint.html" title="Standard Integer Types">Standard Integer Types</a>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/cstdint.hpp" target="_top"><boost/cstdint.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Provides typedef's based on the 1999 C Standard header <code class="computeroutput"><span class="special"><</span><span class="identifier">stdint</span><span class="special">.</span><span class="identifier">h</span><span class="special">></span></code>, wrapped in namespace boost. This
|
||||
implementation may #include the compiler supplied <code class="computeroutput"><span class="special"><</span><span class="identifier">stdint</span><span class="special">.</span><span class="identifier">h</span><span class="special">></span></code>,
|
||||
if present.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/traits.html" title="Integer Traits">Integer Traits</a>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/integer_traits.hpp" target="_top"><boost/integer_traits.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Class template <code class="literal">boost::integer_traits</code>, derives from
|
||||
<code class="literal">std::numeric_limits</code> and adds <code class="literal">const_min</code>
|
||||
and <code class="literal">const_max</code> members.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/integer.html" title="Integer Type Selection">Integer Type Selection</a>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/hpp" target="_top"><boost/integer.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Templates for integer type selection based on properties such as maximum
|
||||
value or number of bits: Use to select the type of an integer when
|
||||
some property such as maximum value or number of bits is known. Useful
|
||||
for generic programming.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/mask.html" title="Integer Masks">Integer Masks</a>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/integer/integer_mask.hpp" target="_top"><boost/integer/integer_mask.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Templates for the selection of integer masks, single or lowest group,
|
||||
based on the number of bits: Use to select a particular mask when the
|
||||
bit position(s) are based on a compile-time variable. Useful for generic
|
||||
programming.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/log2.html" title="Compile time log2 Calculation">Compile time log2 Calculation</a>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/integer/static_log2.hpp" target="_top"><boost/integer/static_log2.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Template for finding the highest power of two in a number: Use to find
|
||||
the bit-size/range based on a maximum value. Useful for generic programming.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/minmax.html" title="Compile time min/max calculation">Compile time min/max calculation</a>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/integer/static_min_max.hpp" target="_top"><boost/integer/static_min_max.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Templates for finding the extrema of two numbers: Use to find a bound
|
||||
based on a minimum or maximum value. Useful for generic programming.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: November 25, 2009 at 12:02:32 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav"><a accesskey="n" href="boost_integer/cstdint.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a></div>
|
||||
</body>
|
||||
</html>
|
801
doc/integer.qbk
Normal file
801
doc/integer.qbk
Normal file
@ -0,0 +1,801 @@
|
||||
[article Boost.Integer
|
||||
[quickbook 1.5]
|
||||
[copyright 2001-2009 Beman Dawes, Daryle Walker, Gennaro Prota, John Maddock]
|
||||
[purpose Integer Type Selection]
|
||||
[license
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
[@http://www.boost.org/LICENSE_1_0.txt])
|
||||
]
|
||||
[authors [Dawes, Beman], [Walker, Daryle], [Prota, Gennaro], [Maddock, John]]
|
||||
[/last-revision $Date: 2008-02-21 12:58:15 +0000 (Thu, 21 Feb 2008) $]
|
||||
]
|
||||
|
||||
[template super[x]'''<superscript>'''[x]'''</superscript>''']
|
||||
|
||||
[section:overview Overview]
|
||||
|
||||
Boost.Integer consists of the following components:
|
||||
|
||||
[table
|
||||
[[Component][Header][Purpose]]
|
||||
[
|
||||
[Forward Declarations.]
|
||||
[[^[@../../../../boost/integer_fwd.hpp <boost/integer_fwd.hpp>]]]
|
||||
[Forward declarations of classes and class templates - for use when just the name of a class is needed.]
|
||||
]
|
||||
[
|
||||
[[link boost_integer.cstdint Standard Integer Types].]
|
||||
[[^[@../../../../boost/cstdint.hpp <boost/cstdint.hpp>]]]
|
||||
[Provides typedef's based on the 1999 C Standard header `<stdint.h>`, wrapped in namespace boost.
|
||||
This implementation may #include the compiler supplied `<stdint.h>`, if present.]
|
||||
]
|
||||
[
|
||||
[[link boost_integer.traits Integer Traits].]
|
||||
[[^[@../../../../boost/integer_traits.hpp <boost/integer_traits.hpp>]]]
|
||||
[Class template [^boost::integer_traits], derives from [^std::numeric_limits] and adds [^const_min] and [^const_max] members.]
|
||||
]
|
||||
[
|
||||
[[link boost_integer.integer Integer Type Selection].]
|
||||
[[^[@../../../../boost/hpp <boost/integer.hpp>]]]
|
||||
[Templates for integer type selection based on properties such as maximum value or number of bits:
|
||||
Use to select the type of an integer when some property such as maximum value or number of bits is known.
|
||||
Useful for generic programming. ]
|
||||
]
|
||||
[
|
||||
[[link boost_integer.mask Integer Masks].]
|
||||
[[^[@../../../../boost/integer/integer_mask.hpp <boost/integer/integer_mask.hpp>]]]
|
||||
[Templates for the selection of integer masks, single or lowest group, based on the number of bits:
|
||||
Use to select a particular mask when the bit position(s) are based on a compile-time variable. Useful for generic programming. ]
|
||||
]
|
||||
[
|
||||
[[link boost_integer.log2 Compile time log2 Calculation].]
|
||||
[[^[@../../../../boost/integer/static_log2.hpp <boost/integer/static_log2.hpp>]]]
|
||||
[Template for finding the highest power of two in a number:
|
||||
Use to find the bit-size/range based on a maximum value. Useful for generic programming. ]
|
||||
]
|
||||
[
|
||||
[[link boost_integer.minmax Compile time min/max calculation].]
|
||||
[[^[@../../../../boost/integer/static_min_max.hpp <boost/integer/static_min_max.hpp>]]]
|
||||
[Templates for finding the extrema of two numbers:
|
||||
Use to find a bound based on a minimum or maximum value. Useful for generic programming. ]
|
||||
]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:cstdint Standard Integer Types]
|
||||
|
||||
[section Overview]
|
||||
|
||||
The header [^[@../../../../boost/cstdint.hpp <boost/cstdint.hpp>]] provides the typedef's useful
|
||||
for writing portable code that requires certain integer widths. All typedef's are in namespace boost.
|
||||
|
||||
The specifications are based on the ISO/IEC 9899:1999 C Language standard header <stdint.h>.
|
||||
The 64-bit types required by the C standard are not required in the boost header,
|
||||
and may not be supplied in all implementations, because [^long long] is not [yet] included in the C++ standard.
|
||||
|
||||
See [@../../test/cstdint_test.cpp cstdint_test.cpp] for a test program.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:rationale Rationale]
|
||||
|
||||
The organization of the Boost.Integer headers and classes is designed to take advantage of <stdint.h> types from the
|
||||
1999 C standard without resorting to undefined behavior in terms of the 1998 C++ standard.
|
||||
The header <boost/cstdint.hpp> makes the standard integer types safely available in namespace [^boost]
|
||||
without placing any names in namespace [^std]. As always, the intension is to complement rather than compete
|
||||
with the C++ Standard Library. Should some future C++ standard include <stdint.h> and <cstdint>,
|
||||
then <boost/cstdint.hpp> will continue to function, but will become redundant and may be safely deprecated.
|
||||
|
||||
Because these are boost headers, their names conform to boost header naming conventions rather than
|
||||
C++ Standard Library header naming conventions.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:ce ['Caveat emptor]]
|
||||
|
||||
As an implementation artifact, certain C <limits.h> macro names may possibly be
|
||||
visible to users of <boost/cstdint.hpp>. Don't use these macros; they are not part of
|
||||
any Boost-specified interface. Use [^boost::integer_traits<>] or [^std::numeric_limits<>] instead.
|
||||
|
||||
As another implementation artifact, certain C <stdint.h> typedef names may possibly be visible
|
||||
in the global namespace to users of <boost/cstdint.hpp>. Don't use these names, they are not part of
|
||||
any Boost-specified interface. Use the respective names in namespace [^boost] instead.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Exact-width integer types]
|
||||
|
||||
The typedef [^int#_t], with # replaced by the width, designates a signed integer type of exactly # bits;
|
||||
for example [^int8_t] denotes an 8-bit signed integer type. Similarly, the typedef [^uint#_t] designates an unsigned
|
||||
integer type of exactly # bits.
|
||||
|
||||
These types are optional. However, if an implementation provides integer types with widths of 8, 16, 32, or 64 bits,
|
||||
it shall define the corresponding typedef names.
|
||||
|
||||
The absence of int64_t and uint64_t is indicated by the macro `BOOST_NO_INT64_T`.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Minimum-width integer types]
|
||||
|
||||
The typedef [^int_least#_t], with # replaced by the width, designates a signed integer type with a width
|
||||
of at least # bits, such that no signed integer type with lesser size has at least the specified width.
|
||||
Thus, [^int_least32_t] denotes a signed integer type with a width of at least 32 bits.
|
||||
Similarly, the typedef name [^uint_least#_t] designates an unsigned integer type with a width of at least # bits,
|
||||
such that no unsigned integer type with lesser size has at least the specified width.
|
||||
|
||||
Required minimum-width integer types:
|
||||
|
||||
* [^int_least8_t]
|
||||
* [^int_least16_t]
|
||||
* [^int_least32_t]
|
||||
* [^uint_least8_t]
|
||||
* [^uint_least16_t]
|
||||
* [^uint_least32_t]
|
||||
|
||||
The types:
|
||||
|
||||
* [^int_least64_t]
|
||||
* [^uint_least64_t]
|
||||
|
||||
Are available only if, after inclusion of [^<boost/cstdint.hpp>] the macro `BOOST_NO_INT64_T` is ['[*not defined]].
|
||||
|
||||
All other minimum-width integer types are optional.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Fastest minimum-width integer types]
|
||||
|
||||
The typedef [^int_fast#_t], with # replaced by the width, designates the fastest signed integer type
|
||||
with a width of at least # bits. Similarly, the typedef name [^uint_fast#_t] designates the fastest
|
||||
unsigned integer type with a width of at least # bits.
|
||||
|
||||
There is no guarantee that these types are fastest for all purposes. In any case, however, they satisfy
|
||||
the signedness and width requirements.
|
||||
|
||||
Required fastest minimum-width integer types:
|
||||
|
||||
* [^int_fast8_t]
|
||||
* [^int_fast16_t]
|
||||
* [^int_fast32_t]
|
||||
* [^uint_fast8_t]
|
||||
* [^uint_fast16_t]
|
||||
* [^uint_fast32_t]
|
||||
|
||||
The types:
|
||||
|
||||
* [^int_fast64_t]
|
||||
* [^uint_fast64_t]
|
||||
|
||||
Are available only if, after inclusion of [^<boost/cstdint.hpp>] the macro `BOOST_NO_INT64_T` is ['[*not defined]].
|
||||
|
||||
All other fastest minimum-width integer types are optional.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Greatest-width integer types]
|
||||
|
||||
The typedef [^intmax_t ]designates a signed integer type capable of representing any value of any signed integer type.
|
||||
|
||||
The typedef [^uintmax_t] designates an unsigned integer type capable of representing any value of any unsigned integer type.
|
||||
|
||||
These types are required.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section:traits Integer Traits]
|
||||
|
||||
[section Motivation]
|
||||
|
||||
The C++ Standard Library <limits> header supplies a class template `numeric_limits<>` with specializations for each fundamental type.
|
||||
|
||||
For integer types, the interesting members of `std::numeric_limits<>` are:
|
||||
|
||||
static const bool is_specialized; // Will be true for integer types.
|
||||
static T min() throw(); // Smallest representable value.
|
||||
static T max() throw(); // Largest representable value.
|
||||
static const int digits; // For integers, the number of value bits.
|
||||
static const int digits10; // The number of base 10 digits that can be represented.
|
||||
static const bool is_signed; // True if the type is signed.
|
||||
static const bool is_integer; // Will be true for all integer types.
|
||||
|
||||
For many uses, these are sufficient.
|
||||
But min() and max() are problematical because they are not constant expressions (std::5.19),
|
||||
yet some usages require constant expressions.
|
||||
|
||||
The template class [^integer_traits] addresses this problem.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Synopsis]
|
||||
|
||||
namespace boost {
|
||||
template<class T>
|
||||
class integer_traits : public std::numeric_limits<T>
|
||||
{
|
||||
static const bool is_integral = false;
|
||||
//
|
||||
// These members are defined only if T is a built-in
|
||||
// integal type:
|
||||
//
|
||||
static const T const_min = ``['implementation-defined]``;
|
||||
static const T const_max = ``['implementation-defined]``;
|
||||
};
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Description]
|
||||
|
||||
Template class [^integer_traits] is derived from [^std::numeric_limits]. In general, it adds the single
|
||||
[^bool] member [^is_integral] with the compile-time constant value [^false].
|
||||
However, for all integral types [^T] (std::3.9.1/7 [basic.fundamental]), there are specializations
|
||||
provided with the following compile-time constants defined:
|
||||
|
||||
[table
|
||||
[[member][type][value]]
|
||||
[[[^is_integral]][bool][[^true]]]
|
||||
[[[^const_min]][[^T]][equivalent to [^std::numeric_limits<T>::min()]]]
|
||||
[[[^const_max]][[^T]][equivalent to [^std::numeric_limits<T>::max()]]]
|
||||
]
|
||||
|
||||
Note: A flag [^is_integral] is provided, because a user-defined integer class should specialize
|
||||
[^std::numeric_limits<>::is_integer = true], nonetheless compile-time constants
|
||||
[^const_min] and [^const_max] cannot be provided for that user-defined class.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Test Program]
|
||||
|
||||
The program [^[@../../test/integer_traits_test.cpp integer_traits_test.cpp]] exercises the [^integer_traits] class.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Acknowledgements]
|
||||
|
||||
Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers discussed the integer traits idea on the boost mailing list in August 1999.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section:integer Integer Type Selection]
|
||||
|
||||
The [@../../../../boost/integer.hpp <boost/integer.hpp>] type selection templates allow
|
||||
integer types to be selected based on desired characteristics such as number of bits or maximum value.
|
||||
This facility is particularly useful for solving generic programming problems.
|
||||
|
||||
[section:synopsis Synopsis]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
// fast integers from least integers
|
||||
template<typename LeastInt>
|
||||
struct int_fast_t
|
||||
{
|
||||
typedef ``['implementation-defined-type]`` fast;
|
||||
};
|
||||
|
||||
// signed
|
||||
template<int Bits>
|
||||
struct int_t
|
||||
{
|
||||
typedef ``['implementation-defined-type]`` least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template<int Bits>
|
||||
struct uint_t
|
||||
{
|
||||
typedef ``['implementation-defined-type]`` least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// signed
|
||||
template<long long MaxValue>
|
||||
struct int_max_value_t
|
||||
{
|
||||
typedef ``['implementation-defined-type]`` least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
template<long long MinValue>
|
||||
struct int_min_value_t
|
||||
{
|
||||
typedef ``['implementation-defined-type]`` least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template<unsigned long long Value>
|
||||
struct uint_value_t
|
||||
{
|
||||
typedef ``['implementation-defined-type]`` least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
} // namespace boost
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:easiest Easiest-to-Manipulate Types]
|
||||
|
||||
The [^int_fast_t] class template maps its input type to the next-largest type that the processor
|
||||
can manipulate the easiest, or to itself if the input type is already an easy-to-manipulate type.
|
||||
For instance, processing a bunch of [^char] objects may go faster if they were converted to [^int] objects before processing.
|
||||
The input type, passed as the only template parameter, must be a built-in integral type, except [^bool].
|
||||
Unsigned integral types can be used, as well as signed integral types, despite the name.
|
||||
The output type is given as the class member [^fast].
|
||||
|
||||
[*Implementation Notes:]
|
||||
By default, the output type is identical to the input type. Eventually, this code's implementation should
|
||||
be conditionalized for each platform to give accurate mappings between the built-in types and the easiest-to-manipulate
|
||||
built-in types. Also, there is no guarantee that the output type actually is easier to manipulate than the input type.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:sized Sized Types]
|
||||
|
||||
The [^int_t], [^uint_t], [^int_max_value_t], [^int_min_value_t], and [^uint_value_t] class templates find
|
||||
the most appropiate built-in integral type for the given template parameter. This type is given by the
|
||||
class member [^least]. The easiest-to-manipulate version of that type is given by the class member [^fast].
|
||||
The following table describes each template's criteria.
|
||||
|
||||
[table Criteria for the Sized Type Class Templates
|
||||
[
|
||||
[Class Template][Template Parameter Mapping]
|
||||
]
|
||||
[
|
||||
[[^boost::int_t<N>]]
|
||||
[The smallest built-in signed integral type with at least /N/ bits, including the sign bit.
|
||||
The parameter should be a positive number. A compile-time error results if the parameter is
|
||||
larger than the number of bits in the largest integer type.]
|
||||
]
|
||||
[
|
||||
[[^boost::uint_t<N>]]
|
||||
[The smallest built-in unsigned integral type with at least /N/ bits.
|
||||
The parameter should be a positive number. A compile-time error results if the
|
||||
parameter is larger than the number of bits in the largest integer type.]
|
||||
]
|
||||
[
|
||||
[[^boost::int_max_value_t<V>]]
|
||||
[The smallest built-in signed integral type that can hold all the values in the inclusive range ['0 - V].
|
||||
The parameter should be a positive number.]
|
||||
]
|
||||
[
|
||||
[[^boost::int_min_value_t<V>]]
|
||||
[The smallest built-in signed integral type that can hold all the values in the inclusive range ['V-0].
|
||||
The parameter should be a negative number.]
|
||||
]
|
||||
[
|
||||
[[^boost::uint_value_t<V>]]
|
||||
[The smallest built-in unsigned integral type that can hold all positive values
|
||||
up to and including /V/. The parameter should be a positive number.]
|
||||
]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Example]
|
||||
|
||||
#include <boost/integer.hpp>
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::int_t<24>::least my_var; // my_var has at least 24-bits
|
||||
//...
|
||||
// This one is guarenteed not to be truncated:
|
||||
boost::int_max_value_t<1000>::least my1000 = 1000;
|
||||
//...
|
||||
// This one is guarenteed not to be truncated, and as fast
|
||||
// to manipulate as possible, it's size may be greater than
|
||||
// that of my1000:
|
||||
boost::int_max_value_t<1000>::fast my_fast1000 = 1000;
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Demonstration Program]
|
||||
|
||||
The program [@../../test/integer_test.cpp integer_test.cpp] is a simplistic demonstration of the results from instantiating
|
||||
various examples of the sized type class templates.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Rationale]
|
||||
|
||||
The rationale for the design of the templates in this header includes:
|
||||
|
||||
* Avoid recursion because of concern about C++'s limited guaranteed recursion depth (17).
|
||||
* Avoid macros on general principles.
|
||||
* Try to keep the design as simple as possible.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Alternative]
|
||||
|
||||
If the number of bits required is known beforehand, it may be more appropriate to use the types supplied
|
||||
in [@../../../../boost/cstdint.hpp <boost/cstdint.hpp>].
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Credits]
|
||||
|
||||
The author of most of the Boost integer type choosing templates is
|
||||
[@http://www.boost.org/people/beman_dawes.html Beman Dawes].
|
||||
He gives thanks to Valentin Bonnard and [@http://www.boost.org/people/kevlin_henney.htm Kevlin Henney]
|
||||
for sharing their designs for similar templates.
|
||||
[@http://www.boost.org/people/daryle_walker.html Daryle Walker] designed the value-based sized templates.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
[section:mask Integer Masks]
|
||||
|
||||
[section Overview]
|
||||
|
||||
The class templates in [@../../../../boost/integer/integer_mask.hpp <boost/integer/integer_mask.hpp>]
|
||||
provide bit masks for a certain bit position or a contiguous-bit pack of a certain size.
|
||||
The types of the masking constants come from the [link boost_integer.integer integer type selection templates] header.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Synopsis]
|
||||
|
||||
#include <cstddef> // for std::size_t
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template <std::size_t Bit>
|
||||
struct high_bit_mask_t
|
||||
{
|
||||
typedef ``['implementation-defined-type]`` least;
|
||||
typedef ``['implementation-defined-type]`` fast;
|
||||
|
||||
static const least high_bit = ``['implementation-defined]``;
|
||||
static const fast high_bit_fast = ``['implementation-defined]``;
|
||||
|
||||
static const std::size_t bit_position = Bit;
|
||||
};
|
||||
|
||||
template <std::size_t Bits>
|
||||
struct low_bits_mask_t
|
||||
{
|
||||
typedef ``['implementation-defined-type]`` least;
|
||||
typedef ``['implementation-defined-type]`` fast;
|
||||
|
||||
static const least sig_bits = ``['implementation-defined]``;
|
||||
static const fast sig_bits_fast = ``['implementation-defined]``;
|
||||
|
||||
static const std::size_t bit_count = Bits;
|
||||
};
|
||||
|
||||
// Specializations for low_bits_mask_t exist for certain bit counts.
|
||||
|
||||
} // namespace boost
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Single Bit-Mask Class Template]
|
||||
|
||||
The [^boost::high_bit_mask_t] class template provides constants for bit masks representing the bit at a
|
||||
certain position. The masks are equivalent to the value 2[super Bit], where [^Bit] is the template parameter.
|
||||
The bit position must be a nonnegative number from zero to ['Max], where Max is one less than the
|
||||
number of bits supported by the largest unsigned built-in integral type. The following table describes
|
||||
the members of an instantiation of [^high_bit_mask_t].
|
||||
|
||||
[table Members of the `boost::high_bit_mask_t` Class Template
|
||||
[[Member][Meaning]]
|
||||
[[[^least]][The smallest unsigned built-in type that supports the given bit position.]]
|
||||
[[[^fast]][The quick-to-manipulate analog of [^least].]]
|
||||
[[[^high_bit]][A [^least] constant of the desired bit-masking value.]]
|
||||
[[[^high_bit_fast]][A [^fast] analog of [^high_bit].]]
|
||||
[[[^bit_position]][The value of the template parameter, in case its needed from a renamed instantiation of the class template.]]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Group Bit-Mask Class Template]
|
||||
|
||||
The [^boost::low_bits_mask_t] class template provides constants for bit masks representing the lowest
|
||||
bits of a certain amount. The masks are equivalent to the value (2[super Bits] - 1),
|
||||
where [^Bits] is the template parameter. The bit amount must be a nonnegative number from
|
||||
zero to ['Max], where Max is the number of bits supported by the largest unsigned built-in integral type.
|
||||
The following table describes the members of an instantiation of [^low_bits_mask_t].
|
||||
|
||||
[table Members of the [^boost::low_bits_mask_t] Class Template
|
||||
[[Member][Meaning]]
|
||||
[[[^least]][The smallest unsigned built-in type that supports the given bit count.]]
|
||||
[[[^fast]][The quick-to-manipulate analog of [^least].]]
|
||||
[[[^sig_bits]][A [^least] constant of the desired bit-masking value.]]
|
||||
[[[^sig_bits_fast]][A [^fast] analog of [^sig_bits].]]
|
||||
[[[^bit_count]][The value of the template parameter, in case its needed from a renamed instantiation of the class template.]]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Implementation Notes]
|
||||
|
||||
When [^Bits] is the exact size of a built-in unsigned type, the implementation has to change to
|
||||
prevent undefined behavior. Therefore, there are specializations of [^low_bits_mask_t] at those bit counts.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Example]
|
||||
|
||||
#include <boost/integer/integer_mask.hpp>
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::high_bit_mask_t<29> mask1_type;
|
||||
typedef boost::low_bits_mask_t<15> mask2_type;
|
||||
|
||||
mask1_type::least my_var1;
|
||||
mask2_type::fast my_var2;
|
||||
//...
|
||||
|
||||
my_var1 |= mask1_type::high_bit;
|
||||
my_var2 &= mask2_type::sig_bits_fast;
|
||||
|
||||
//...
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Demonstration Program]
|
||||
|
||||
The program [@../../test/integer_mask_test.cpp integer_mask_test.cpp] is a simplistic demonstration of the
|
||||
results from instantiating various examples of the bit mask class templates.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Rationale]
|
||||
|
||||
The class templates in this header are an extension of the [link boost_integer.integer integer type selection class templates].
|
||||
The new class templates provide the same sized types, but also convienent masks to use when extracting the
|
||||
highest or all the significant bits when the containing built-in type contains more bits.
|
||||
This prevents contaimination of values by the higher, unused bits.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Credits]
|
||||
|
||||
The author of the Boost bit mask class templates is [@http://www.boost.org/people/daryle_walker.html Daryle Walker].
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section:log2 Compile time log2 Calculation]
|
||||
|
||||
The class template in [@../../../../boost/integer/static_log2.hpp <boost/integer/static_log2.hpp>]
|
||||
determines the position of the highest bit in a given value. This facility is useful for solving generic programming problems.
|
||||
|
||||
[section Synopsis]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
typedef ``['implementation-defined]`` static_log2_argument_type;
|
||||
typedef ``['implementation-defined]`` static_log2_result_type;
|
||||
|
||||
template <static_log2_argument_type arg>
|
||||
struct static_log2
|
||||
{
|
||||
static const static_log2_result_type value = ``['implementation-defined]``;
|
||||
};
|
||||
|
||||
|
||||
template < >
|
||||
struct static_log2< 0 >
|
||||
{
|
||||
// The logarithm of zero is undefined.
|
||||
};
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Usage]
|
||||
|
||||
The [^boost::static_log2] class template takes one template parameter, a value of type
|
||||
[^static_log2_argument_type]. The template only defines one member, [^value], which gives the
|
||||
truncated base-two logarithm of the template argument.
|
||||
|
||||
Since the logarithm of zero, for any base, is undefined, there is a specialization of [^static_log2]
|
||||
for a template argument of zero. This specialization has no members, so an attempt to use the base-two
|
||||
logarithm of zero results in a compile-time error.
|
||||
|
||||
Note:
|
||||
|
||||
* [^static_log2_argument_type] is an ['unsigned integer type] (C++ standard, 3.9.1p3).
|
||||
* [^static_log2_result_type] is an ['integer type] (C++ standard, 3.9.1p7).
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Example]
|
||||
|
||||
#include "boost/integer/static_log2.hpp"
|
||||
|
||||
|
||||
template < boost::static_log2_argument_type value >
|
||||
bool is_it_what()
|
||||
{
|
||||
typedef boost::static_log2<value> lb_type;
|
||||
|
||||
int temp = lb_type::value;
|
||||
//...
|
||||
return (temp % 2) != 0;
|
||||
}
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
bool temp = is_it_what<2000>();
|
||||
//...
|
||||
# if 0
|
||||
temp = is_it_what<0>(); // would give an error
|
||||
# endif
|
||||
//...
|
||||
temp = is_it_what<24>();
|
||||
//...
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Demonstration Program]
|
||||
|
||||
The program [@../../test/static_log2_test.cpp static_log2_test.cpp] is a simplistic
|
||||
demonstration of the results from instantiating various examples of the binary logarithm class template.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Rationale]
|
||||
|
||||
The base-two (binary) logarithm, abbreviated lb, function is occasionally used to give order-estimates
|
||||
of computer algorithms. The truncated logarithm can be considered the highest power-of-two in a value,
|
||||
which corresponds to the value's highest set bit (for binary integers). Sometimes the highest-bit position
|
||||
could be used in generic programming, which requires the position to be statically (['i.e.] at compile-time) available.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Credits]
|
||||
|
||||
The original version of the Boost binary logarithm class template was
|
||||
written by [@http://www.boost.org/people/daryle_walker.html Daryle Walker] and then
|
||||
enhanced by Giovanni Bajo with support for compilers without partial template specialization.
|
||||
The current version was suggested, together with a reference implementation, by Vesa Karvonen.
|
||||
Gennaro Prota wrote the actual source file.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section:minmax Compile time min/max calculation]
|
||||
|
||||
The class templates in [@../../../../boost/integer/static_min_max.hpp <boost/integer/static_min_max.hpp>]
|
||||
provide a compile-time evaluation of the minimum or maximum of two integers. These facilities are useful
|
||||
for generic programming problems.
|
||||
|
||||
[section Synopsis]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
typedef ``['implementation-defined]`` static_min_max_signed_type;
|
||||
typedef ``['implementation-defined]`` static_min_max_unsigned_type;
|
||||
|
||||
template <static_min_max_signed_type Value1, static_min_max_signed_type Value2 >
|
||||
struct static_signed_min;
|
||||
|
||||
template <static_min_max_signed_type Value1, static_min_max_signed_type Value2>
|
||||
struct static_signed_max;
|
||||
|
||||
template <static_min_max_unsigned_type Value1, static_min_max_unsigned_type Value2>
|
||||
struct static_unsigned_min;
|
||||
|
||||
template <static_min_max_unsigned_type Value1, static_min_max_unsigned_type Value2>
|
||||
struct static_unsigned_max;
|
||||
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Usage]
|
||||
|
||||
The four class templates provide the combinations for finding the minimum or maximum of two signed or
|
||||
[^unsigned] ([^long]) parameters, Value1 and Value2, at compile-time. Each template has a single static data member,
|
||||
[^value], which is set to the respective minimum or maximum of the template's parameters.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Example]
|
||||
|
||||
#include <boost/integer/static_min_max.hpp>
|
||||
|
||||
template < unsigned long AddendSize1, unsigned long AddendSize2 >
|
||||
class adder
|
||||
{
|
||||
public:
|
||||
static unsigned long const addend1_size = AddendSize1;
|
||||
static unsigned long const addend2_size = AddendSize2;
|
||||
static unsigned long const sum_size = boost::static_unsigned_max<AddendSize1, AddendSize2>::value + 1;
|
||||
|
||||
typedef int addend1_type[ addend1_size ];
|
||||
typedef int addend2_type[ addend2_size ];
|
||||
typedef int sum_type[ sum_size ];
|
||||
|
||||
void operator ()( addend1_type const &a1, addend2_type const &a2, sum_type &s ) const;
|
||||
};
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
int const a1[] = { 0, 4, 3 }; // 340
|
||||
int const a2[] = { 9, 8 }; // 89
|
||||
int s[ 4 ];
|
||||
adder<3,2> obj;
|
||||
|
||||
obj( a1, a2, s ); // 's' should be 429 or { 9, 2, 4, 0 }
|
||||
//...
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Demonstration Program]
|
||||
|
||||
The program [@../../test/static_min_max_test.cpp static_min_max_test.cpp] is a simplistic demonstration of
|
||||
various comparisons using the compile-time extrema class templates.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Rationale]
|
||||
|
||||
Sometimes the minimum or maximum of several values needs to be found for later compile-time processing,
|
||||
['e.g.] for a bound for another class template.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Credits]
|
||||
|
||||
The author of the Boost compile-time extrema class templates is [@http://www.boost.org/people/daryle_walker.html Daryle Walker].
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section:history History]
|
||||
|
||||
[h4 1.42.0]
|
||||
|
||||
* Reverted Trunk to release branch state (i.e. a "known good state").
|
||||
* Fixed issues: [@https://svn.boost.org/trac/boost/ticket/653 653],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3084 3084],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3177 3177],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3180 3180],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3548 3568],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3657 3657],
|
||||
[@https://svn.boost.org/trac/boost/ticket/2134 2134].
|
||||
* Added long long support to [^boost::static_log2], [^boost::static_signed_min], [^boost::static_signed_max],
|
||||
[^boost::static_unsigned_min][^boost::static_unsigned_max], when available.
|
||||
* The argument type and the result type of [^boost::static_signed_min] etc are now typedef'd.
|
||||
Formerly, they were hardcoded as [^unsigned long] and [^int] respectively. Please, use the
|
||||
provided typedefs in new code (and update old code as soon as possible).
|
||||
|
||||
[h4 1.32.0]
|
||||
|
||||
* The argument type and the result type of [^boost::static_log2] are now typedef'd.
|
||||
Formerly, they were hardcoded as [^unsigned long] and [^int] respectively. Please, use the
|
||||
provided typedefs in new code (and update old code as soon as possible).
|
||||
|
||||
[endsect]
|
||||
|
@ -1,210 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Integer Bit Mask Templates</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
|
||||
<h1><img src="../../../boost.png" alt="boost.png (6897 bytes)"
|
||||
align="middle" width="277" height="86">Integer Bit Mask Templates</h1>
|
||||
|
||||
<p>The class templates in <cite><a href="../../../boost/integer/integer_mask.hpp"><boost/integer/integer_mask.hpp></a></cite> provide bit masks for a certain bit position or a contiguous-bit pack of a certain size. The types of the masking constants come from the <a href="../integer.htm">integer type selection templates</a> header.</p>
|
||||
|
||||
<h2><a name="contents">Contents</a></h2>
|
||||
|
||||
<ul>
|
||||
<li><a href="#contents">Contents</a></li>
|
||||
<li><a href="#synopsis">Synopsis</a></li>
|
||||
<li><a href="#single">Single Bit-Mask Class Template</a></li>
|
||||
<li><a href="#group">Group Bit-Mask Class Template</a></li>
|
||||
<li><a href="#example">Example</a></li>
|
||||
<li><a href="#demo">Demonstration Program</a></li>
|
||||
<li><a href="#rationale">Rationale</a></li>
|
||||
<li><a href="#credits">Credits</a></li>
|
||||
</ul>
|
||||
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
|
||||
<blockquote><pre>
|
||||
#include <cstddef> <i>// for std::size_t</i>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template < std::size_t Bit >
|
||||
struct high_bit_mask_t
|
||||
{
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef <em>implementation_supplied</em> fast;
|
||||
|
||||
static const least high_bit = <em>implementation_defined</em>;
|
||||
static const fast high_bit_fast = <em>implementation_defined</em>;
|
||||
|
||||
static const std::size_t bit_position = Bit;
|
||||
|
||||
};
|
||||
|
||||
template < std::size_t Bits >
|
||||
struct low_bits_mask_t
|
||||
{
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef <em>implementation_supplied</em> fast;
|
||||
|
||||
static const least sig_bits = <em>implementation_defined</em>;
|
||||
static const fast sig_bits_fast = <em>implementation_defined</em>;
|
||||
|
||||
static const std::size_t bit_count = Bits;
|
||||
|
||||
};
|
||||
|
||||
// Specializations for low_bits_mask_t exist for certain bit counts.
|
||||
|
||||
} // namespace boost
|
||||
</pre></blockquote>
|
||||
|
||||
<h2><a name="single">Single Bit-Mask Class Template</a></h2>
|
||||
|
||||
<p>The <code>boost::high_bit_mask_t</code> class template provides
|
||||
constants for bit masks representing the bit at a certain position. The
|
||||
masks are equivalent to the value 2<sup><code>Bit</code></sup>, where
|
||||
<code>Bit</code> is the template parameter. The bit position must be a
|
||||
nonnegative number from zero to <i>Max</i>, where <dfn>Max</dfn> is one
|
||||
less than the number of bits supported by the largest unsigned built-in
|
||||
integral type. The following table describes the members of an
|
||||
instantiation of <code>high_bit_mask_t</code>.</p>
|
||||
|
||||
<table border="1" cellpadding="5">
|
||||
<caption>Members of the <code>boost::high_bit_mask_t</code> Class
|
||||
Template</caption>
|
||||
<tr>
|
||||
<th>Member</th>
|
||||
<th>Meaning</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>least</code></td>
|
||||
<td>The smallest unsigned built-in type that supports the given
|
||||
bit position.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>fast</code></td>
|
||||
<td>The quick-to-manipulate analog of <code>least</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>high_bit</code></td>
|
||||
<td>A <code>least</code> constant of the desired bit-masking
|
||||
value.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>high_bit_fast</code></td>
|
||||
<td>A <code>fast</code> analog of <code>high_bit</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>bit_position</code></td>
|
||||
<td>The value of the template parameter, in case its needed from
|
||||
a renamed instantiation of the class template.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><a name="group">Group Bit-Mask Class Template</a></h2>
|
||||
|
||||
<p>The <code>boost::low_bits_mask_t</code> class template provides
|
||||
constants for bit masks representing the lowest bits of a certain
|
||||
amount. The masks are equivalent to the value
|
||||
(2<sup><code>Bits</code></sup> - 1), where <code>Bits</code> is the
|
||||
template parameter. The bit amount must be a nonnegative number from
|
||||
zero to <i>Max</i>, where <dfn>Max</dfn> is the number of bits supported
|
||||
by the largest unsigned built-in integral type. The following table
|
||||
describes the members of an instantiation of
|
||||
<code>low_bits_mask_t</code>.</p>
|
||||
|
||||
<table border="1" cellpadding="5">
|
||||
<caption>Members of the <code>boost::low_bits_mask_t</code> Class
|
||||
Template</caption>
|
||||
<tr>
|
||||
<th>Member</th>
|
||||
<th>Meaning</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>least</code></td>
|
||||
<td>The smallest unsigned built-in type that supports the given
|
||||
bit count.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>fast</code></td>
|
||||
<td>The quick-to-manipulate analog of <code>least</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>sig_bits</code></td>
|
||||
<td>A <code>least</code> constant of the desired bit-masking
|
||||
value.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>sig_bits_fast</code></td>
|
||||
<td>A <code>fast</code> analog of <code>sig_bits</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>bit_count</code></td>
|
||||
<td>The value of the template parameter, in case its needed from
|
||||
a renamed instantiation of the class template.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p><strong>Implementation Note</strong><br>
|
||||
When <code>Bits</code> is the exact size of a built-in unsigned type,
|
||||
the implementation has to change to prevent undefined behavior.
|
||||
Therefore, there are specializations of <code>low_bits_mask_t</code> at
|
||||
those bit counts.</p>
|
||||
|
||||
<h2><a name="example">Example</a></h2>
|
||||
|
||||
<blockquote><pre>
|
||||
#include <boost/integer/integer_mask.hpp>
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::high_bit_mask_t<29> mask1_type;
|
||||
typedef boost::low_bits_mask_t<15> mask2_type;
|
||||
|
||||
mask1_type::least my_var1;
|
||||
mask2_type::fast my_var2;
|
||||
//...
|
||||
|
||||
my_var1 |= mask1_type::high_bit;
|
||||
my_var2 &= mask2_type::sig_bits_fast;
|
||||
|
||||
//...
|
||||
}
|
||||
</pre></blockquote>
|
||||
|
||||
<h2><a name="demo">Demonstration Program</a></h2>
|
||||
|
||||
<p>The program <a href="../test/integer_mask_test.cpp">integer_mask_test.cpp</a>
|
||||
is a simplistic demonstration of the results from instantiating various
|
||||
examples of the bit mask class templates.</p>
|
||||
|
||||
<h2><a name="rationale">Rationale</a></h2>
|
||||
|
||||
<p>The class templates in this header are an extension of the <a
|
||||
href="../integer.htm">integer type selection class templates</a>. The new
|
||||
class templates provide the same sized types, but also convienent masks
|
||||
to use when extracting the highest or all the significant bits when the
|
||||
containing built-in type contains more bits. This prevents
|
||||
contaimination of values by the higher, unused bits.</p>
|
||||
|
||||
<h2><a name="credits">Credits</a></h2>
|
||||
|
||||
<p>The author of the Boost bit mask class templates is <a
|
||||
href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a>.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised September 23, 2001</p>
|
||||
|
||||
<p>© Copyright Daryle Walker 2001. Use, modification, and distribution are
|
||||
subject to the Boost Software License, Version 1.0. (See accompanying file <a
|
||||
href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a
|
||||
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
||||
</body>
|
||||
</html>
|
@ -1,215 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
|
||||
<title>Binary Logarithm Template</title>
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
|
||||
<body bgcolor="white" text="black">
|
||||
|
||||
<h1><img src="../../../boost.png" alt="boost.png (6897 bytes)"
|
||||
align="middle" width="277" height="86">Binary Logarithm Template</h1>
|
||||
|
||||
|
||||
<p>The class template in <cite><a href="../../../boost/integer/static_log2.hpp"><boost/integer/static_log2.hpp></a></cite> determines the position of the highest bit in a given value. This facility is useful for solving generic programming problems.</p>
|
||||
|
||||
|
||||
|
||||
<h2><a name="contents">Contents</a></h2>
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
<li><a href="#contents">Contents</a></li>
|
||||
|
||||
<li><a href="#synopsis">Synopsis</a></li>
|
||||
|
||||
<li><a href="#usage">Usage</a></li>
|
||||
|
||||
<li><a href="#example">Example</a></li>
|
||||
|
||||
<li><a href="#demo">Demonstration Program</a></li>
|
||||
|
||||
<li><a href="#rationale">Rationale</a></li>
|
||||
|
||||
<li><a href="#credits">Credits</a></li>
|
||||
|
||||
<li><a href="#whatsnew"><b>What's new</b></a></li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
|
||||
|
||||
|
||||
<blockquote><pre>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
typedef <em>implementation-defined</em> static_log2_argument_type;
|
||||
typedef <em>implementation-defined</em> static_log2_result_type;
|
||||
|
||||
template < static_log2_argument_type arg >
|
||||
struct static_log2
|
||||
{
|
||||
static const static_log2_result_type value = <em>implementation-defined</em>;
|
||||
};
|
||||
|
||||
|
||||
template < >
|
||||
struct static_log2< 0 >
|
||||
{
|
||||
// The logarithm of zero is undefined.
|
||||
};
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
</pre></blockquote>
|
||||
|
||||
|
||||
|
||||
|
||||
<h2><a name="usage">Usage</a></h2>
|
||||
|
||||
|
||||
|
||||
<p>The <code>boost::static_log2</code> class template takes one template
|
||||
parameter, a value of type <code>static_log2_argument_type</code>. The template
|
||||
only defines one member, <code>value</code>, which gives the truncated
|
||||
base-two logarithm of the template argument.</p>
|
||||
|
||||
<p>Since the logarithm of zero, for any base, is undefined, there is a
|
||||
specialization of <code>static_log2</code> for a template argument
|
||||
of zero. This specialization has no members, so an attempt to use
|
||||
the base-two logarithm of zero results in a compile-time error.</p>
|
||||
|
||||
<p>Note: <ul>
|
||||
|
||||
<li><code>static_log2_argument_type</code> is an <i>unsigned integer
|
||||
type</i> (C++ standard, 3.9.1p3).</li>
|
||||
|
||||
<li><code>static_log2_result_type</code> is an <i>integer type</i>
|
||||
(C++ standard, 3.9.1p7).</li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<h2><a name="example">Example</a></h2>
|
||||
|
||||
|
||||
|
||||
<blockquote><pre>
|
||||
|
||||
#include "boost/integer/static_log2.hpp"
|
||||
|
||||
|
||||
template < boost::static_log2_argument_type value >
|
||||
bool is_it_what()
|
||||
{
|
||||
typedef boost::static_log2<value> lb_type;
|
||||
|
||||
int temp = lb_type::value;
|
||||
//...
|
||||
return (temp % 2) != 0;
|
||||
}
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
bool temp = is_it_what<2000>();
|
||||
//...
|
||||
# if 0
|
||||
temp = is_it_what<0>(); // would give an error
|
||||
# endif
|
||||
//...
|
||||
temp = is_it_what<24>();
|
||||
//...
|
||||
}
|
||||
|
||||
</pre></blockquote>
|
||||
|
||||
|
||||
|
||||
<h2><a name="demo">Demonstration Program</a></h2>
|
||||
|
||||
|
||||
|
||||
<p>The program <a href="../test/static_log2_test.cpp">static_log2_test.cpp</a>
|
||||
is a simplistic demonstration of the results from instantiating various
|
||||
examples of the binary logarithm class template.</p>
|
||||
|
||||
|
||||
|
||||
<h2><a name="rationale">Rationale</a></h2>
|
||||
|
||||
|
||||
|
||||
<p>The base-two (binary) logarithm, abbreviated <dfn>lb</dfn>, function
|
||||
is occasionally used to give order-estimates of computer algorithms.
|
||||
The truncated logarithm can be considered the highest power-of-two in a
|
||||
value, which corresponds to the value's highest set bit (for binary
|
||||
integers). Sometimes the highest-bit position could be used in generic
|
||||
programming, which requires the position to be statically (<i>i.e.</i>
|
||||
at compile-time) available.</p>
|
||||
|
||||
|
||||
|
||||
<h2><a name="whatsnew">Changes from previous versions:</a></h2>
|
||||
|
||||
|
||||
|
||||
<ul>
|
||||
<li><i>New in version 1.32.0:</i><br><br>
|
||||
|
||||
The argument type and the result type of <code>boost::static_log2</code>
|
||||
are now typedef'd. Formerly, they were hardcoded as <code>unsigned long</code>
|
||||
and <code>int</code> respectively. Please, use the provided typedefs in new
|
||||
code (and update old code as soon as possible).
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<h2><a name="credits">Credits</a></h2>
|
||||
|
||||
|
||||
|
||||
<p>The original version of the Boost binary logarithm class template was
|
||||
written by <a href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a>
|
||||
and then enhanced by Giovanni Bajo with support for compilers without
|
||||
partial template specialization. The current version was suggested,
|
||||
together with a reference implementation, by Vesa Karvonen. Gennaro Prota
|
||||
wrote the actual source file.
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
|
||||
|
||||
|
||||
<p>Revised July 19, 2004</p>
|
||||
|
||||
<p>© Copyright Daryle Walker 2001.<br>
|
||||
© Copyright Gennaro Prota 2004.</p>
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">
|
||||
http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
|
||||
<br>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
@ -1,120 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Compile-Time Extrema Templates</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="white" text="black" link="blue" alink="red" vlink="purple">
|
||||
<h1><img src="../../../boost.png" alt="boost.png (6897 bytes)"
|
||||
align="middle" width="277" height="86">Compile-Time Extrema
|
||||
Templates</h1>
|
||||
|
||||
<p>The class templates in <cite><a
|
||||
href="../../../boost/integer/static_min_max.hpp"><boost/integer/static_min_max.hpp></a></cite>
|
||||
provide a compile-time evaluation of the minimum or maximum of
|
||||
two integers. These facilities are useful for generic programming problems.</p>
|
||||
|
||||
<h2><a name="contents">Contents</a></h2>
|
||||
|
||||
<ul>
|
||||
<li><a href="#contents">Contents</a></li>
|
||||
<li><a href="#synopsis">Synopsis</a></li>
|
||||
<li><a href="#usage">Usage</a></li>
|
||||
<li><a href="#example">Example</a></li>
|
||||
<li><a href="#demo">Demonstration Program</a></li>
|
||||
<li><a href="#rationale">Rationale</a></li>
|
||||
<li><a href="#credits">Credits</a></li>
|
||||
</ul>
|
||||
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
|
||||
<blockquote><pre>
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
struct static_signed_min;
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
struct static_signed_max;
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
struct static_unsigned_min;
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
struct static_unsigned_max;
|
||||
|
||||
}
|
||||
</pre></blockquote>
|
||||
|
||||
<h2><a name="usage">Usage</a></h2>
|
||||
|
||||
<p>The four class templates provide the combinations for finding the
|
||||
minimum or maximum of two signed or <code>unsigned</code>
|
||||
(<code>long</code>) parameters, <var>Value1</var> and <var>Value2</var>,
|
||||
at compile-time. Each template has a single static data member,
|
||||
<code>value</code>, which is set to the respective minimum or maximum
|
||||
of the template's parameters.</p>
|
||||
|
||||
<h2><a name="example">Example</a></h2>
|
||||
|
||||
<blockquote><pre>
|
||||
#include <boost/integer/static_min_max.hpp>
|
||||
|
||||
template < unsigned long AddendSize1, unsigned long AddendSize2 >
|
||||
class adder
|
||||
{
|
||||
public:
|
||||
static unsigned long const addend1_size = AddendSize1;
|
||||
static unsigned long const addend2_size = AddendSize2;
|
||||
static unsigned long const sum_size = boost::static_unsigned_max<AddendSize1, AddendSize2>::value + 1;
|
||||
|
||||
typedef int addend1_type[ addend1_size ];
|
||||
typedef int addend2_type[ addend2_size ];
|
||||
typedef int sum_type[ sum_size ];
|
||||
|
||||
void operator ()( addend1_type const &a1, addend2_type const &a2, sum_type &s ) const;
|
||||
};
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
int const a1[] = { 0, 4, 3 }; // 340
|
||||
int const a2[] = { 9, 8 }; // 89
|
||||
int s[ 4 ];
|
||||
adder<3,2> obj;
|
||||
|
||||
obj( a1, a2, s ); // 's' should be 429 or { 9, 2, 4, 0 }
|
||||
//...
|
||||
}
|
||||
</pre></blockquote>
|
||||
|
||||
<h2><a name="demo">Demonstration Program</a></h2>
|
||||
|
||||
<p>The program <a
|
||||
href="../test/static_min_max_test.cpp">static_min_max_test.cpp</a> is a
|
||||
simplistic demonstration of various comparisons using the compile-time
|
||||
extrema class templates.</p>
|
||||
|
||||
<h2><a name="rationale">Rationale</a></h2>
|
||||
|
||||
<p>Sometimes the minimum or maximum of several values needs to be found
|
||||
for later compile-time processing, <i>e.g.</i> for a bound for another
|
||||
class template.</p>
|
||||
|
||||
<h2><a name="credits">Credits</a></h2>
|
||||
|
||||
<p>The author of the Boost compile-time extrema class templates is <a
|
||||
href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a>.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised October 12, 2001</p>
|
||||
|
||||
<p>© Copyright Daryle Walker 2001. Use, modification, and distribution are
|
||||
subject to the Boost Software License, Version 1.0. (See accompanying file <a
|
||||
href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a
|
||||
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
||||
</body>
|
||||
</html>
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include <boost/integer_fwd.hpp> // self include
|
||||
|
||||
#include <boost/integer_traits.hpp> // for ::boost::integer_traits
|
||||
#include <boost/integer_traits.hpp> // for boost::::boost::integer_traits
|
||||
#include <boost/limits.hpp> // for ::std::numeric_limits
|
||||
#include <boost/cstdint.hpp> // for boost::int64_t and BOOST_NO_INTEGRAL_INT64_T
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
#ifndef BOOST_INTEGER_STATIC_LOG2_HPP
|
||||
#define BOOST_INTEGER_STATIC_LOG2_HPP
|
||||
|
||||
#include "boost/config.hpp" // for BOOST_STATIC_CONSTANT
|
||||
#include "boost/integer_fwd.hpp" // for boost::intmax_t
|
||||
|
||||
namespace boost {
|
||||
|
||||
@ -41,9 +41,8 @@ namespace boost {
|
||||
// terminates with x = 1 and n = 0 (see the algorithm's
|
||||
// invariant).
|
||||
|
||||
typedef unsigned long argument_type;
|
||||
typedef int result_type;
|
||||
|
||||
typedef boost::static_log2_argument_type argument_type;
|
||||
typedef boost::static_log2_result_type result_type;
|
||||
|
||||
template <result_type n>
|
||||
struct choose_initial_n {
|
||||
@ -107,10 +106,6 @@ namespace boost {
|
||||
// static_log2<x>
|
||||
// ----------------------------------------
|
||||
|
||||
typedef detail::static_log2_impl::argument_type static_log2_argument_type;
|
||||
typedef detail::static_log2_impl::result_type static_log2_result_type;
|
||||
|
||||
|
||||
template <static_log2_argument_type x>
|
||||
struct static_log2 {
|
||||
|
||||
|
@ -12,39 +12,35 @@
|
||||
|
||||
#include <boost/integer_fwd.hpp> // self include
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
||||
// Compile-time extrema class declarations ---------------------------------//
|
||||
// Get the minimum or maximum of two values, signed or unsigned.
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
template <static_min_max_signed_type Value1, static_min_max_signed_type Value2>
|
||||
struct static_signed_min
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( long, value = (Value1 > Value2) ? Value2 : Value1 );
|
||||
BOOST_STATIC_CONSTANT(static_min_max_signed_type, value = (Value1 > Value2) ? Value2 : Value1 );
|
||||
};
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
template <static_min_max_signed_type Value1, static_min_max_signed_type Value2>
|
||||
struct static_signed_max
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( long, value = (Value1 < Value2) ? Value2 : Value1 );
|
||||
BOOST_STATIC_CONSTANT(static_min_max_signed_type, value = (Value1 < Value2) ? Value2 : Value1 );
|
||||
};
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
template <static_min_max_unsigned_type Value1, static_min_max_unsigned_type Value2>
|
||||
struct static_unsigned_min
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( unsigned long, value
|
||||
BOOST_STATIC_CONSTANT(static_min_max_unsigned_type, value
|
||||
= (Value1 > Value2) ? Value2 : Value1 );
|
||||
};
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
template <static_min_max_unsigned_type Value1, static_min_max_unsigned_type Value2>
|
||||
struct static_unsigned_max
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( unsigned long, value
|
||||
BOOST_STATIC_CONSTANT(static_min_max_unsigned_type, value
|
||||
= (Value1 < Value2) ? Value2 : Value1 );
|
||||
};
|
||||
|
||||
|
@ -14,11 +14,23 @@
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_NO_INTRINSIC_WCHAR_T
|
||||
#include <boost/limits.hpp> // for std::numeric_limits
|
||||
#include <boost/cstdint.hpp> // For intmax_t
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
#ifdef BOOST_NO_INTEGRAL_INT64_T
|
||||
typedef unsigned long static_log2_argument_type;
|
||||
typedef int static_log2_result_type;
|
||||
typedef long static_min_max_signed_type;
|
||||
typedef unsigned long static_min_max_unsigned_type;
|
||||
#else
|
||||
typedef boost::uintmax_t static_min_max_unsigned_type;
|
||||
typedef boost::intmax_t static_min_max_signed_type;
|
||||
typedef boost::uintmax_t static_log2_argument_type;
|
||||
typedef int static_log2_result_type;
|
||||
#endif
|
||||
|
||||
// From <boost/cstdint.hpp> ------------------------------------------------//
|
||||
|
||||
@ -136,28 +148,26 @@ template < >
|
||||
|
||||
// From <boost/integer/static_log2.hpp> ------------------------------------//
|
||||
|
||||
template < unsigned long Value >
|
||||
template <static_log2_argument_type Value >
|
||||
struct static_log2;
|
||||
|
||||
template < >
|
||||
struct static_log2< 0ul >;
|
||||
template <> struct static_log2<0u>;
|
||||
|
||||
|
||||
// From <boost/integer/static_min_max.hpp> ---------------------------------//
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
template <static_min_max_signed_type Value1, static_min_max_signed_type Value2>
|
||||
struct static_signed_min;
|
||||
|
||||
template < long Value1, long Value2 >
|
||||
template <static_min_max_signed_type Value1, static_min_max_signed_type Value2>
|
||||
struct static_signed_max;
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
template <static_min_max_unsigned_type Value1, static_min_max_unsigned_type Value2>
|
||||
struct static_unsigned_min;
|
||||
|
||||
template < unsigned long Value1, unsigned long Value2 >
|
||||
template <static_min_max_unsigned_type Value1, static_min_max_unsigned_type Value2>
|
||||
struct static_unsigned_max;
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
|
156
index.html
156
index.html
@ -1,148 +1,16 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Boost Integer Library</title>
|
||||
<meta http-equiv="refresh" content="0; URL=doc/html/index.html">
|
||||
</head>
|
||||
|
||||
<body bgcolor="white" text="black">
|
||||
<table border="1" bgcolor="teal" cellpadding="2">
|
||||
<tr>
|
||||
<td bgcolor="white"><img src="../../boost.png" alt="boost.png (6897 bytes)" width="277" height="86"></td>
|
||||
<td><a href="../../index.htm"><font face="Arial" color="white"><big>Home</big></font></a></td>
|
||||
<td><a href="../libraries.htm"><font face="Arial" color="white"><big>Libraries</big></font></a></td>
|
||||
<td><a href="http://www.boost.org/people/people.htm"><font face="Arial" color="white"><big>People</big></font></a></td>
|
||||
<td><a href="http://www.boost.org/more/faq.htm"><font face="Arial" color="white"><big>FAQ</big></font></a></td>
|
||||
<td><a href="../../more/index.htm"><font face="Arial" color="white"><big>More</big></font></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h1>Boost Integer Library</h1>
|
||||
|
||||
<table border="1" cellpadding="5">
|
||||
<tr>
|
||||
<th>Header / Docs</th>
|
||||
<th>Contents</th>
|
||||
<th>Use</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><cite><a href="../../boost/integer_fwd.hpp"><boost/integer_fwd.hpp></a></cite></td>
|
||||
<td valign="top">Forward declarations of classes and class templates</td>
|
||||
<td valign="top">When just the name of a class is needed</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp><br>
|
||||
</a></code><a href="cstdint.htm"><br>
|
||||
documentation</a>
|
||||
</td>
|
||||
<td valign="top">Typedef's based on the 1999 C Standard header <<code>stdint.h></code>, wrapped in namespace boost.
|
||||
This implementation may #include the compiler
|
||||
supplied <<code>stdint.h></code>, if present. </td>
|
||||
<td valign="top">Supplies typedefs for standard integer types such as <code> int32_t</code> or <code>uint_least16_t</code>.
|
||||
Use in preference to <<code>stdint.h></code>
|
||||
for enhanced portability. Furthermore, all names are safely placed in the boost namespace.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer_traits.hpp"><boost/integer_traits.hpp></a></code><br>
|
||||
<br>
|
||||
<a href="integer_traits.html">documentation</a>
|
||||
</td>
|
||||
<td valign="top">Template class <code>boost::integer_traits</code>, derived from <code>std::numeric_limits</code>.
|
||||
Adds <code>const_min</code> and <code>const_max</code> members.</td>
|
||||
<td valign="top">Use to obtain the characteristics of a known integer type.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer.hpp"><boost/integer.hpp></a><br>
|
||||
<br>
|
||||
</code><a href="integer.htm">documentation</a></td>
|
||||
<td valign="top">Templates for integer type selection based on properties such as
|
||||
maximum value or number of bits.</td>
|
||||
<td valign="top">Use to select the type an integer when some property such as maximum value or number of bits is known.
|
||||
Useful for generic programming. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer/integer_mask.hpp"><boost/integer/integer_mask.hpp></a><br>
|
||||
<br>
|
||||
</code><a href="doc/integer_mask.html">documentation</a></td>
|
||||
<td valign="top">Templates for the selection of integer masks, single or lowest group, based on the number of bits.</td>
|
||||
<td valign="top">Use to select a particular mask when the bit position(s) are based on a compile-time variable.
|
||||
Useful for generic programming. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer/static_log2.hpp"><boost/integer/static_log2.hpp></a><br>
|
||||
<br>
|
||||
</code><a href="doc/static_log2.html">documentation</a></td>
|
||||
<td valign="top">Template for finding the highest power of two in a number.</td>
|
||||
<td valign="top">Use to find the bit-size/range based on a maximum value.
|
||||
Useful for generic programming. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer/static_min_max.hpp"><boost/integer/static_min_max.hpp></a><br>
|
||||
<br>
|
||||
</code><a href="doc/static_min_max.html">documentation</a></td>
|
||||
<td valign="top">Templates for finding the extrema of two numbers.</td>
|
||||
<td valign="top">Use to find a bound based on a minimum or maximum value.
|
||||
Useful for generic programming. </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>Rationale</h2>
|
||||
|
||||
<p>The organization of boost integer headers and classes is designed to
|
||||
take advantage of <cite><stdint.h></cite> types from the 1999 C
|
||||
standard without resorting to undefined behavior in terms of the 1998
|
||||
C++ standard. The header <cite><boost/cstdint.hpp></cite> makes
|
||||
the standard integer types safely available in namespace
|
||||
<code>boost</code> without placing any names in namespace
|
||||
<code>std</code>. As always, the intension is to complement rather than
|
||||
compete with the C++ Standard Library. Should some future C++ standard
|
||||
include <cite><stdint.h></cite> and <cite><cstdint></cite>,
|
||||
then <cite><boost/cstdint.hpp></cite> will continue to function,
|
||||
but will become redundant and may be safely deprecated.</p>
|
||||
|
||||
<p>Because these are boost headers, their names conform to boost header
|
||||
naming conventions rather than C++ Standard Library header naming
|
||||
conventions.</p>
|
||||
|
||||
<h2><i>Caveat emptor</i></h2>
|
||||
|
||||
<p>As an implementation artifact, certain C
|
||||
<cite><limits.h></cite> macro names may possibly be visible to
|
||||
users of <cite><boost/cstdint.hpp></cite>. Don't use these
|
||||
macros; they are not part of any Boost-specified interface. Use
|
||||
<code>boost::integer_traits<></code> or
|
||||
<code>std::numeric_limits<></code> instead.</p>
|
||||
|
||||
<p>As another implementation artifact, certain C
|
||||
<cite><stdint.h></cite> typedef names may possibly be visible in
|
||||
the global namespace to users of <cite><boost/cstdint.hpp></cite>.
|
||||
Don't use these names, they are not part of any Boost-specified
|
||||
interface. Use the respective names in namespace <code>boost</code>
|
||||
instead.</p>
|
||||
|
||||
<h2>
|
||||
<i>History</i>
|
||||
</h2>
|
||||
|
||||
<p>
|
||||
Reverted Trunk to release branch state (i.e. a "known good state"), Nov 2009. Then fixed issues:
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/653">653</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3084">3084</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3177">3177</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3180">3180</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3548">3568</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3657">3657</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/2134">2134</a>,
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->06 Nov 2007<!--webbot bot="Timestamp" endspan i-checksum="15272" -->
|
||||
</p>
|
||||
|
||||
<p>© Copyright Beman Dawes 2003</p>
|
||||
|
||||
<p>Distributed under the Boost Software License, Version 1.0. See
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
||||
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="doc/html/index.html">doc/html/index.html</a>.
|
||||
<P>Copyright Beman Dawes, Daryle Walker, Gennaro Prota and John Maddock 2001-2009</P>
|
||||
<P>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">www.boost.org/LICENSE_1_0.txt</A>).</P>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
|
||||
|
212
integer.htm
212
integer.htm
@ -1,212 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Integer Type Selection Templates</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="white" text="black">
|
||||
<h1>
|
||||
<img src="../../boost.png" alt="boost.png (6897 bytes)"
|
||||
align="middle" width="277" height="86">Integer Type Selection
|
||||
Templates</h1>
|
||||
|
||||
<p>The <cite><a
|
||||
href="../../boost/integer.hpp"><boost/integer.hpp></a></cite> type
|
||||
selection templates allow integer types to be selected based on desired
|
||||
characteristics such as number of bits or maximum value. This facility
|
||||
is particularly useful for solving generic programming problems.</p>
|
||||
|
||||
<h2><a name="contents">Contents</a></h2>
|
||||
|
||||
<ul>
|
||||
<li><a href="#contents">Contents</a></li>
|
||||
<li><a href="#synopsis">Synopsis</a></li>
|
||||
<li><a href="#easy">Easiest-to-Manipulate Types</a></li>
|
||||
<li><a href="#sized">Sized Types</a></li>
|
||||
<li><a href="#example">Example</a></li>
|
||||
<li><a href="#demo">Demonstration Program</a></li>
|
||||
<li><a href="#rationale">Rationale</a></li>
|
||||
<li><a href="#alternative">Alternative</a></li>
|
||||
<li><a href="#credits">Credits</a></li>
|
||||
</ul>
|
||||
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
|
||||
<blockquote><pre>namespace boost
|
||||
{
|
||||
// fast integers from least integers
|
||||
template< typename LeastInt >
|
||||
struct int_fast_t
|
||||
{
|
||||
typedef <em>implementation_supplied</em> fast;
|
||||
};
|
||||
|
||||
// signed
|
||||
template< int Bits >
|
||||
struct int_t
|
||||
{
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template< int Bits >
|
||||
struct uint_t
|
||||
{
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// signed
|
||||
template< long long MaxValue >
|
||||
struct int_max_value_t
|
||||
{
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
template< long long MinValue >
|
||||
struct int_min_value_t
|
||||
{
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
// unsigned
|
||||
template< unsigned long long Value >
|
||||
struct uint_value_t
|
||||
{
|
||||
typedef <em>implementation_supplied</em> least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
} // namespace boost
|
||||
</pre></blockquote>
|
||||
|
||||
<h2><a name="easy">Easiest-to-Manipulate Types</a></h2>
|
||||
|
||||
<p>The <code>int_fast_t</code> class template maps its input type to the
|
||||
next-largest type that the processor can manipulate the easiest, or to
|
||||
itself if the input type is already an easy-to-manipulate type. For
|
||||
instance, processing a bunch of <code>char</code> objects may go faster
|
||||
if they were converted to <code>int</code> objects before processing.
|
||||
The input type, passed as the only template parameter, must be a
|
||||
built-in integral type, except <code>bool</code>. Unsigned integral
|
||||
types can be used, as well as signed integral types, despite the name.
|
||||
The output type is given as the class member <code>fast</code>.</p>
|
||||
|
||||
<p><strong>Implementation Notes</strong><br>
|
||||
By default, the output type is identical to the input type. Eventually,
|
||||
this code's implementation should be conditionalized for each platform
|
||||
to give accurate mappings between the built-in types and the
|
||||
easiest-to-manipulate built-in types. Also, there is no guarantee that
|
||||
the output type actually is easier to manipulate than the input
|
||||
type.</p>
|
||||
|
||||
<h2><a name="sized">Sized Types</a></h2>
|
||||
|
||||
<p>The <code>int_t</code>, <code>uint_t</code>,
|
||||
<code>int_max_value_t</code>, <code>int_min_value_t</code>, and
|
||||
<code>uint_value_t</code> class templates find the most appropiate
|
||||
built-in integral type for the given template parameter. This type is
|
||||
given by the class member <code>least</code>. The easiest-to-manipulate
|
||||
version of that type is given by the class member <code>fast</code>.
|
||||
The following table describes each template's criteria.</p>
|
||||
|
||||
<table border="1" cellpadding="5">
|
||||
<caption>Criteria for the Sized Type Class Templates</caption>
|
||||
<tr>
|
||||
<th>Class Template</th>
|
||||
<th>Template Parameter Mapping</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>boost::int_t</code></td>
|
||||
<td>The smallest built-in signed integral type with at least the
|
||||
given number of bits, including the sign bit. The parameter
|
||||
should be a positive number. A compile-time error results if
|
||||
the parameter is larger than the number of bits in a
|
||||
<code>long</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>boost::uint_t</code></td>
|
||||
<td>The smallest built-in unsigned integral type with at least
|
||||
the given number of bits. The parameter should be a positive
|
||||
number. A compile-time error results if the parameter is
|
||||
larger than the number of bits in an <code>unsigned
|
||||
long</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>boost::int_max_value_t</code></td>
|
||||
<td>The smallest built-in signed integral type that supports the
|
||||
given value as a maximum. The parameter should be a
|
||||
positive number.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>boost::int_min_value_t</code></td>
|
||||
<td>The smallest built-in signed integral type that supports the
|
||||
given value as a minimum. The parameter should be a
|
||||
negative number.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>boost::uint_value_t</code></td>
|
||||
<td>The smallest built-in unsigned integral type that supports
|
||||
the given value as a maximum. The parameter should be a
|
||||
positive number.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><a name="example">Example</a></h2>
|
||||
|
||||
<blockquote><pre>#include <boost/integer.hpp>
|
||||
|
||||
//...
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::int_t<24>::least my_var;
|
||||
//...
|
||||
}
|
||||
</pre></blockquote>
|
||||
|
||||
<h2><a name="demo">Demonstration Program</a></h2>
|
||||
|
||||
<p>The program <a href="integer_test.cpp">integer_test.cpp</a> is a
|
||||
simplistic demonstration of the results from instantiating various
|
||||
examples of the sized type class templates.</p>
|
||||
|
||||
<h2><a name="rationale">Rationale</a></h2>
|
||||
|
||||
<p>The rationale for the design of the templates in this header includes:</p>
|
||||
|
||||
<ul>
|
||||
<li>Avoid recursion because of concern about C++'s limited
|
||||
guaranteed recursion depth (17).</li>
|
||||
<li>Avoid macros on general principles.</li>
|
||||
<li>Try to keep the design as simple as possible.</li>
|
||||
</ul>
|
||||
|
||||
<h2><a name="alternative">Alternative</a></h2>
|
||||
|
||||
<p>If the number of bits required is known beforehand, it may be more
|
||||
appropriate to use the types supplied in <cite><a
|
||||
href="../../boost/cstdint.hpp"><boost/cstdint.hpp></a></cite>.</p>
|
||||
|
||||
<h2><a name="credits">Credits</a></h2>
|
||||
|
||||
<p>The author of most of the Boost integer type choosing templates is <a
|
||||
href="http://www.boost.org/people/beman_dawes.html">Beman Dawes</a>. He gives thanks
|
||||
to Valentin Bonnard and
|
||||
<a href="http://www.boost.org/people/kevlin_henney.htm"> Kevlin Henney</a> for sharing
|
||||
their designs for similar templates. <a
|
||||
href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a> designed the
|
||||
value-based sized templates.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised May 20, 2001</p>
|
||||
|
||||
<p>© Copyright Beman Dawes 1999. Use, modification, and distribution are
|
||||
subject to the Boost Software License, Version 1.0. (See accompanying file <a
|
||||
href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a
|
||||
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
||||
</body>
|
||||
</html>
|
@ -1,94 +0,0 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
|
||||
<title>integer_traits: Compile-Time Limits for Integral Types</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<h1><img src="../../boost.png" alt="boost.png (6897 bytes)" align="center" width="277" height="86">Compile-Time Integral
|
||||
Type Limits</h1>
|
||||
|
||||
<p>
|
||||
The C++ Standard Library <limits> header supplies a class template
|
||||
numeric_limits<> with specializations for each fundamental
|
||||
type.</p>
|
||||
<p>
|
||||
For integer types, the interesting members of std::numeric_limits<> are:
|
||||
<pre> static const bool is_specialized; // will be true for integers
|
||||
static T min() throw();
|
||||
static T max() throw();
|
||||
static const int digits; // for integers, # value bits
|
||||
static const int digits10;
|
||||
static const bool is_signed;
|
||||
static const bool is_integer; // will be true for integers</pre>
|
||||
For many uses, these are sufficient. But min() and max() are problematical because they are not constant expressions
|
||||
(std::5.19), yet some usages require constant expressions.
|
||||
<p>
|
||||
The template class <code>integer_traits</code> addresses this
|
||||
problem.
|
||||
|
||||
|
||||
<h2>Header <code><a href="../../boost/integer_traits.hpp">integer_traits.hpp</a></code> Synopsis</h2>
|
||||
|
||||
<pre>namespace boost {
|
||||
template<class T>
|
||||
class integer_traits : public std::numeric_limits<T>
|
||||
{
|
||||
static const bool is_integral = false;
|
||||
};
|
||||
|
||||
// specializations for all integral types
|
||||
}</pre>
|
||||
|
||||
|
||||
<h2>Description</h2>
|
||||
|
||||
Template class <code>integer_traits</code> is derived from
|
||||
<code>std::numeric_limits</code>. In general, it adds the single
|
||||
<code>bool</code> member <code>is_integral</code> with the
|
||||
compile-time constant value <code>false</code>. However, for all
|
||||
integral types <code>T</code> (std::3.9.1/7 [basic.fundamental]),
|
||||
there are specializations provided with the following compile-time
|
||||
constants defined:
|
||||
<p>
|
||||
<table border=1>
|
||||
<tr><th>member</th><th>type</th><th>value</th></tr>
|
||||
<tr><td><code>is_integral</code></td><td>bool</td><td><code>true</code></td></tr>
|
||||
<tr><td><code>const_min</code></td><td><code>T</code></td><td>equivalent
|
||||
to <code>std::numeric_limits<T>::min()</code></td></tr>
|
||||
<tr><td><code>const_max</code></td><td><code>T</code></td><td>equivalent
|
||||
to <code>std::numeric_limits<T>::max()</code></td></tr>
|
||||
</table>
|
||||
|
||||
<p>
|
||||
|
||||
<em>Note:</em> A flag <code>is_integral</code> is provided, because a
|
||||
user-defined integer class should specialize
|
||||
<code>std::numeric_limits<>::is_integer = true</code>,
|
||||
nonetheless compile-time constants <code>const_min</code> and
|
||||
<code>const_max</code> cannot be provided for that user-defined class.
|
||||
|
||||
<h2>
|
||||
|
||||
Test Program</h2>
|
||||
|
||||
<p>
|
||||
|
||||
The program <code><a href="integer_traits_test.cpp">integer_traits_test.cpp</a></code>
|
||||
exercises the <code>integer_traits</code> class.
|
||||
|
||||
<h2>Acknowledgements</h2>
|
||||
|
||||
Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers discussed the integer
|
||||
traits idea on the boost mailing list in August 1999.
|
||||
<hr>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->06 November 2007<!--webbot bot="Timestamp" endspan i-checksum="40336" --></p>
|
||||
<p>© Copyright Beman Dawes 2000</p>
|
||||
|
||||
<p>Distributed under the Boost Software License, Version 1.0. See
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
||||
|
Loading…
Reference in New Issue
Block a user