Compare commits

...

54 Commits

Author SHA1 Message Date
28e720315e Branch for 2nd try at V2 removal
[SVN r77497]
2012-03-23 12:04:44 +00:00
1898e66238 Apply patch from Vincent Botet Escriba: fix check for size > long long.
[SVN r77109]
2012-02-24 16:57:13 +00:00
cc73477d13 Fix typo.
Refs #6003.

[SVN r76137]
2011-12-24 17:29:03 +00:00
8457bd01b1 Fix integer_traits<long long> when no macro from limits.h is available.
[SVN r68802]
2011-02-12 15:06:21 +00:00
707faa1086 Remove old dead code.
[SVN r68097]
2011-01-13 13:43:08 +00:00
7bd48eb3f3 Change logic so that int32_t etc is an int rather than a long where possible.
[SVN r65299]
2010-09-05 16:27:09 +00:00
7c62277986 Add VMS support.
Fixes #4474.

[SVN r64750]
2010-08-12 12:36:42 +00:00
8368cd0a55 Rebuild integer docs.
[SVN r63765]
2010-07-08 20:50:29 +00:00
794fdf9bad Update various libraries' documentation build.
Mostly to use the images and css files under doc/src instead of
doc/html, usually be deleting the settings in order to use the defaults.
Also add 'boost.root' to some builds in order to fix links which rely on
it.

[SVN r63146]
2010-06-20 18:00:48 +00:00
cd98c4a257 Add a 64 bit specialization of low_bits_mask_t. Fixes #4332
[SVN r62756]
2010-06-10 19:49:34 +00:00
84c8a52085 Rebuild the integer documentation.
[SVN r61058]
2010-04-05 07:27:25 +00:00
8a1d11f369 Fix link to integer header.
[SVN r59676]
2010-02-14 13:09:24 +00:00
a5356bb254 Change integer code to still work when BOOST_HAS_MS_INT64 is defined but BOOST_HAS_LONG_LONG is not.
Update VC++ config to define BOOST_HAS_LONG_LONG for MSVC-8 in ANSI mode.
Fixes #3657.

[SVN r59468]
2010-02-04 11:15:54 +00:00
2f13159023 Change code to check individually for the INT#_C macros before defining them - this correctly handles cases where they are partially defined by other other headers (for example ICU).
Also declare this a gcc system header - seems to be the only way to really suppress the warnings - fixes #3889.

[SVN r59430]
2010-02-02 18:35:33 +00:00
6293af825a Commit alternative warning suppression code.
[SVN r59264]
2010-01-25 10:55:50 +00:00
896f2a7654 Disable warnings when defining INT#_C macros for gcc.
[SVN r58948]
2010-01-12 18:51:40 +00:00
e5c64669e2 Update docs to match code.
[SVN r58293]
2009-12-11 17:56:01 +00:00
14e17dd9f6 Update cstdint.hpp to always define the INT#_C macros.
Try again with Codegear workaround.

[SVN r58292]
2009-12-11 17:46:10 +00:00
86519e7bcf Extend codegear/borland fix.
[SVN r58291]
2009-12-11 15:59:42 +00:00
e5267abf6e Tentative Borland/Codegear patch.
[SVN r58113]
2009-12-03 12:14:15 +00:00
92a617bbe9 Get the tests warning free again with GCC.
Finally get everything working with the Borland compiler.
Fix a few typos: use of long rather than unsigned long, use of long long rather than long_long_type etc.

[SVN r58056]
2009-11-30 13:50:05 +00:00
ad5d5b0e1f Up template instantiation depth for sun compiler.
[SVN r58033]
2009-11-29 16:23:04 +00:00
3af7c55ad9 Make code respect BOOST_NO_INTEGRAL_INT64_T.
[SVN r58031]
2009-11-29 16:02:45 +00:00
1797528e35 Change long long to boost::long_long_type etc.
[SVN r58029]
2009-11-29 13:59:18 +00:00
05c1f88324 Fix issues in docs.
[SVN r58008]
2009-11-28 17:08:31 +00:00
6a497ee263 Regenerate with new stylesheets.
[SVN r57968]
2009-11-27 11:13:02 +00:00
98b57c1f3b Get the tests warning free with gcc, and add conceptual-header-inclusion tests.
[SVN r57948]
2009-11-26 18:06:10 +00:00
154b9ce992 Fix some typos.
[SVN r57946]
2009-11-26 15:43:32 +00:00
fad95e3d1f Oops, tests should return the error code is any.
[SVN r57943]
2009-11-26 13:35:03 +00:00
b83327861c Changed to use the lightweight test framework - we can now test with a much wider range of compilers.
[SVN r57942]
2009-11-26 12:59:39 +00:00
ac155d3843 Added support for exact width integer type to int_t and uint_t
Updated docs to match.
Fixes #1225.

[SVN r57941]
2009-11-26 11:08:27 +00:00
ca84baa55d 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]
2009-11-25 12:38:09 +00:00
db267e22f8 Integer: fixed search&replace gone mad
[SVN r57908]
2009-11-24 21:24:20 +00:00
cf359129a3 Bring docs into line with code.
[SVN r57885]
2009-11-24 10:14:43 +00:00
09ee5872ba Tidied up namespace usage, fixes #2134.
[SVN r57884]
2009-11-24 10:12:29 +00:00
0248ecb71b Add history/revision log.
[SVN r57883]
2009-11-24 10:07:45 +00:00
ddb6a13f29 Add support for long long throughout.
Fixes #653.

[SVN r57873]
2009-11-23 18:51:33 +00:00
e07b49c955 remove reference to dead test (no longer relevant)
[SVN r57867]
2009-11-23 16:45:21 +00:00
44c3831e05 Fix Jamfile and Boost.Test usage.
[SVN r57866]
2009-11-23 16:39:45 +00:00
4c23c47ebe Add support for MS style __int64 when long long is not available.
Fixes #3084.

[SVN r57863]
2009-11-23 13:23:15 +00:00
285048504c Suppress and/or fix warnings - in particular avoid undefined behaviour in the test cases!
[SVN r57859]
2009-11-23 10:43:00 +00:00
8cab32a0dd Fix for Comeau compiler - does not define __GLIBC_HAVE_LONG_LONG which in turn causes GLIBC's stdint.h to misbehave.
Fixes #3548.

[SVN r57858]
2009-11-23 09:51:23 +00:00
9ff5c9d3b6 Fixes #3180.
[SVN r57845]
2009-11-22 17:12:57 +00:00
dd1194afa4 Fix preprocessor logic for long long support.
Fixes #3657.
Fixes #3568.

[SVN r57843]
2009-11-22 16:38:05 +00:00
eecbd5276f Reverted Integer back to Release branch state - as per devel-list discussions.
[SVN r57580]
2009-11-11 18:57:24 +00:00
fd0a8f8c2c Suppress gcc warnings: for bug report #1451.
[SVN r57170]
2009-10-27 09:58:40 +00:00
f9561fec20 rm cmake from trunk. I'm not entirely sure this is necessary to satisfy the inspect script, but I'm not taking any chances, and it is easy to put back
[SVN r56942]
2009-10-17 02:07:38 +00:00
9fd48f6a56 Copyrights on CMakeLists.txt to keep them from clogging up the inspect
reports.  This is essentially the same commit as r55095 on the release
branch.



[SVN r55159]
2009-07-26 00:49:56 +00:00
edd638ec91 Use BOOST_STATIC_CONSTANT in static_log2, as g++ 4.0 has problems with enum.
[SVN r54811]
2009-07-08 21:27:05 +00:00
3706ee7bd9 Fixes #2654.
[SVN r50572]
2009-01-14 10:17:25 +00:00
ec8ede3378 Changed control of extra messages to be determined solely by the Boost.Test messaging controls
[SVN r50009]
2008-11-29 07:45:02 +00:00
a8f7c90aff Updating dependency information for modularized libraries.
[SVN r49628]
2008-11-07 17:05:27 +00:00
768023af1a Updating CMake files to latest trunk. Added dependency information for regression tests and a few new macros for internal use.
[SVN r49627]
2008-11-07 17:02:56 +00:00
c7e9da6551 Continuing merge of CMake build system files into trunk with the encouragement of Doug Gregor
[SVN r49510]
2008-11-01 13:15:41 +00:00
41 changed files with 4395 additions and 3267 deletions

View File

@ -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&nbsp;</h1>
<p>The header <code><a href="../../boost/cstdint.hpp">&lt;boost/cstdint.hpp&gt;</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 &lt;stdint.h&gt;.&nbsp; 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="test/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.&nbsp; 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,&nbsp;
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.&nbsp; In
any case, however, they satisfy&nbsp; 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><EFBFBD> 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>

55
doc/Jamfile.v2 Normal file
View File

@ -0,0 +1,55 @@
# 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=../../../..
# 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 ;

View File

@ -0,0 +1,289 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Standard Integer Types</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<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/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="traits.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<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>
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.integer_constant_macros">Integer
Constant Macros</a></span></dt>
</dl></div>
<div class="section">
<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">&lt;boost/cstdint.hpp&gt;</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 for these types are based on the ISO/IEC 9899:1999 C Language
standard header &lt;stdint.h&gt;. The 64-bit types required by the C standard
are <span class="emphasis"><em>not required</em></span> in the boost header, and may not be
supplied for all platforms/compilers, 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">
<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 &lt;stdint.h&gt; types from the 1999 C standard without
causing undefined behavior in terms of the 1998 C++ standard. The header
&lt;boost/cstdint.hpp&gt; 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>. The intension is to complement rather than compete
with the C++ Standard Library. Should some future C++ standard include &lt;stdint.h&gt;
and &lt;cstdint&gt;, then &lt;boost/cstdint.hpp&gt; 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">
<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 &lt;limits.h&gt; macro names may
possibly be visible to users of &lt;boost/cstdint.hpp&gt;. Don't use these
macros; they are not part of any Boost-specified interface. Use <code class="literal">boost::integer_traits&lt;&gt;</code>
or <code class="literal">std::numeric_limits&lt;&gt;</code> instead.
</p>
<p>
As another implementation artifact, certain C &lt;stdint.h&gt; typedef names
may possibly be visible in the global namespace to users of &lt;boost/cstdint.hpp&gt;.
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">
<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 a platform supports integer types with
widths of 8, 16, 32, 64, or any combination thereof, then &lt;boost/cstdint.hpp&gt;
does provide the corresponding typedefs.
</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">
<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 the smallest 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>
The following minimum-width integer types are provided for all platforms:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
<code class="literal">int_least8_t</code>
</li>
<li class="listitem">
<code class="literal">int_least16_t</code>
</li>
<li class="listitem">
<code class="literal">int_least32_t</code>
</li>
<li class="listitem">
<code class="literal">uint_least8_t</code>
</li>
<li class="listitem">
<code class="literal">uint_least16_t</code>
</li>
<li class="listitem">
<code class="literal">uint_least32_t</code>
</li>
</ul></div>
<p>
The following types are available only if, after including &lt;boost/cstdint.hpp&gt;,
the macro BOOST_NO_INT64_T is not defined:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
<code class="literal">int_least64_t</code>
</li>
<li class="listitem">
<code class="literal">uint_least64_t</code>
</li>
</ul></div>
<p>
All other minimum-width integer types are optional.
</p>
</div>
<div class="section">
<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>
The following fastest minimum-width integer types are provided for all platforms:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
<code class="literal">int_fast8_t</code>
</li>
<li class="listitem">
<code class="literal">int_fast16_t</code>
</li>
<li class="listitem">
<code class="literal">int_fast32_t</code>
</li>
<li class="listitem">
<code class="literal">uint_fast8_t</code>
</li>
<li class="listitem">
<code class="literal">uint_fast16_t</code>
</li>
<li class="listitem">
<code class="literal">uint_fast32_t</code>
</li>
</ul></div>
<p>
The following types are available only if, after including &lt;boost/cstdint.hpp&gt;,
the macro BOOST_NO_INT64_T is not defined:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
<code class="literal">int_fast64_t</code>
</li>
<li class="listitem">
<code class="literal">uint_fast64_t</code>
</li>
</ul></div>
<p>
All other fastest minimum-width integer types are optional.
</p>
</div>
<div class="section">
<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 provided for all platforms.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_integer.cstdint.integer_constant_macros"></a><a class="link" href="cstdint.html#boost_integer.cstdint.integer_constant_macros" title="Integer Constant Macros">Integer
Constant Macros</a>
</h3></div></div></div>
<p>
The following macros are always defined after inclusion of this header, these
allow integer constants of at least the specified width to be declared: INT8_C,
UINT8_C, INT16_C, UINT16_C, INT32_C, UINT32_C, INTMAX_C, UINTMAX_C.
</p>
<p>
The macros INT64_C and UINT64_C are also defined if the the macro BOOST_NO_INT64_T
is not defined.
</p>
<p>
The C99 macro __STDC_CONSTANT_MACROS is also defined as an artifact of the
implementation.
</p>
<p>
For example:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">cstdint</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="comment">// Here the constant 0x1FFFFFFFF has the correct suffix applied:
</span><span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">uint64_t</span> <span class="identifier">c</span> <span class="special">=</span> <span class="identifier">INT64_C</span><span class="special">(</span><span class="number">0</span><span class="identifier">x1FFFFFFFF</span><span class="special">);</span>
</pre>
</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 &#169; 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/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="traits.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@ -0,0 +1,82 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>History</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<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/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a>
</div>
<div class="section">
<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="id766183"></a>
<a class="link" href="history.html#boost_integer.history.1_42_0">1.42.0</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
Reverted Trunk to release branch state (i.e. a "known good state").
</li>
<li class="listitem">
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 class="listitem">
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 class="listitem">
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="id766314"></a>
<a class="link" href="history.html#boost_integer.history.1_32_0">1.32.0</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
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 &#169; 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/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a>
</div>
</body>
</html>

View File

@ -0,0 +1,432 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Integer Type Selection</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<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/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="mask.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<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">&lt;boost/integer.hpp&gt;</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">
<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">&lt;</span><span class="keyword">typename</span> <span class="identifier">LeastInt</span><span class="special">&gt;</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">type</span><span class="special">;</span>
<span class="special">};</span>
<span class="comment">// signed
</span> <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">int</span> <span class="identifier">Bits</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">int_t</span>
<span class="special">{</span>
<span class="comment">/* Member exact may or may not be defined depending upon Bits */</span>
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">exact</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">&lt;</span><span class="identifier">least</span><span class="special">&gt;::</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">&lt;</span><span class="keyword">int</span> <span class="identifier">Bits</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">uint_t</span>
<span class="special">{</span>
<span class="comment">/* Member exact may or may not be defined depending upon Bits */</span>
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">exact</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">&lt;</span><span class="identifier">least</span><span class="special">&gt;::</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">&lt;</span><span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">MaxValue</span><span class="special">&gt;</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">&lt;</span><span class="identifier">least</span><span class="special">&gt;::</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">&lt;</span><span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">MinValue</span><span class="special">&gt;</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">&lt;</span><span class="identifier">least</span><span class="special">&gt;::</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">&lt;</span><span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">Value</span><span class="special">&gt;</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">&lt;</span><span class="identifier">least</span><span class="special">&gt;::</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">
<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. The output type is given as the nested type <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 customized 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">
<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 nested type <code class="literal">least</code>.
The easiest-to-manipulate version of that type is given by the nested type
<code class="literal">fast</code>. The following table describes each template's criteria.
</p>
<div class="table">
<a name="boost_integer.integer.sized.criteria_for_the_sized_type_class_templates"></a><p class="title"><b>Table&#160;1.&#160;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&lt;N&gt;::least</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::int_t&lt;N&gt;::fast</code>
</p>
</td>
<td>
<p>
The easiest-to-manipulate, 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::int_t&lt;N&gt;::exact</code>
</p>
</td>
<td>
<p>
A built-in, signed integral type with exactly <span class="emphasis"><em>N</em></span>
bits, including the sign bit. The parameter should be a positive
number. Note that the member <span class="emphasis"><em>exact</em></span> is defined
<span class="bold"><strong>only</strong></span> if there exists a type with
exactly <span class="emphasis"><em>N</em></span> bits.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="literal">boost::uint_t&lt;N&gt;::least</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::uint_t&lt;N&gt;::fast</code>
</p>
</td>
<td>
<p>
The easiest-to-manipulate, 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::uint_t&lt;N&gt;::exact</code>
</p>
</td>
<td>
<p>
A built-in, unsigned integral type with exactly <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. Note that the member <span class="emphasis"><em>exact</em></span>
is defined <span class="bold"><strong>only</strong></span> if there exists
a type with exactly N bits.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="literal">boost::int_max_value_t&lt;V&gt;::last</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_max_value_t&lt;V&gt;::fast</code>
</p>
</td>
<td>
<p>
The easiest-to-manipulate, 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&lt;V&gt;::least</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::int_min_value_t&lt;V&gt;::fast</code>
</p>
</td>
<td>
<p>
The easiest-to-manipulate, 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&lt;V&gt;::least</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>
<tr>
<td>
<p>
<code class="literal">boost::uint_value_t&lt;V&gt;::fast</code>
</p>
</td>
<td>
<p>
The easiest-to-manipulate, 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">
<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">&lt;</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">&gt;</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">&lt;</span><span class="number">24</span><span class="special">&gt;::</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">&lt;</span><span class="number">1000</span><span class="special">&gt;::</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, its 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">&lt;</span><span class="number">1000</span><span class="special">&gt;::</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">
<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">
<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 class="itemizedlist" type="disc">
<li class="listitem">
Avoid recursion because of concern about C++'s limited guaranteed recursion
depth (17).
</li>
<li class="listitem">
Avoid macros on general principles.
</li>
<li class="listitem">
Try to keep the design as simple as possible.
</li>
</ul></div>
</div>
<div class="section">
<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">&lt;boost/cstdint.hpp&gt;</a>.
</p>
</div>
<div class="section">
<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 &#169; 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/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="mask.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@ -0,0 +1,151 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Compile Time log2 Calculation</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<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/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="minmax.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<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.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">&lt;boost/integer/static_log2.hpp&gt;</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">
<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">&lt;</span><span class="identifier">static_log2_argument_type</span> <span class="identifier">arg</span><span class="special">&gt;</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">&lt;</span> <span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">static_log2</span><span class="special">&lt;</span> <span class="number">0</span> <span class="special">&gt;</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">
<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 class="itemizedlist" type="disc">
<li class="listitem">
<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 class="listitem">
<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">
<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">
<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 available statically (<span class="emphasis"><em>i.e.</em></span> at compile-time).
</p>
</div>
<div class="section">
<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 &#169; 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/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="minmax.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@ -0,0 +1,378 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Integer Masks</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<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/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="log2.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<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">
<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">&lt;boost/integer/integer_mask.hpp&gt;</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">
<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">&lt;</span><span class="identifier">cstddef</span><span class="special">&gt;</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">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">Bit</span><span class="special">&gt;</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">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">Bits</span><span class="special">&gt;</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">
<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="boost_integer.mask.single_bit_mask_class_template.members_of_the__boost__high_bit_mask_t__class_template"></a><p class="title"><b>Table&#160;2.&#160;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 easiest-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 value 2<sup>Bit</sup>.
</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">
<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 equivalent to the value (2<sup>Bits</sup> - 1), where <code class="literal">Bits</code>
is the template parameter. The parameter <code class="literal">Bits</code> must be
a non-negative integer 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 <code class="literal">low_bits_mask_t</code>.
</p>
<div class="table">
<a name="boost_integer.mask.group_bit_mask_class_template.members_of_the___boost__low_bits_mask_t__class_template"></a><p class="title"><b>Table&#160;3.&#160;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 easiest-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">
<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">
<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">&lt;</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">&gt;</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">&lt;</span><span class="number">29</span><span class="special">&gt;</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">&lt;</span><span class="number">15</span><span class="special">&gt;</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">&amp;=</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">
<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">
<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 convenient masks to use when extracting the highest
or all the significant bits when the containing built-in type contains more
bits. This prevents contamination of values by the higher, unused bits.
</p>
</div>
<div class="section">
<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 &#169; 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/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="log2.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@ -0,0 +1,160 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Compile time min/max calculation</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<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/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="history.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<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">&lt;boost/integer/static_min_max.hpp&gt;</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">
<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">&lt;</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">&gt;</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">&lt;</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">&gt;</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">&lt;</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">&gt;</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">&lt;</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">&gt;</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">
<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 <code class="literal">signed</code> or <code class="literal">unsigned</code>
(<code class="literal">long</code>) parameters, <span class="emphasis"><em>Value1</em></span> and <span class="emphasis"><em>Value2</em></span>,
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">
<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">&lt;</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">&gt;</span>
<span class="keyword">template</span> <span class="special">&lt;</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">&gt;</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">&lt;</span><span class="identifier">AddendSize1</span><span class="special">,</span> <span class="identifier">AddendSize2</span><span class="special">&gt;::</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">&amp;</span><span class="identifier">a1</span><span class="special">,</span> <span class="identifier">addend2_type</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">a2</span><span class="special">,</span> <span class="identifier">sum_type</span> <span class="special">&amp;</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">&lt;</span><span class="number">3</span><span class="special">,</span><span class="number">2</span><span class="special">&gt;</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">
<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">
<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">
<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 &#169; 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/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="history.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@ -0,0 +1,215 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Integer Traits</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<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/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="integer.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<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">
<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 &lt;limits&gt; header supplies a class template
<code class="computeroutput"><span class="identifier">numeric_limits</span><span class="special">&lt;&gt;</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">&lt;&gt;</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">
<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">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</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">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">public</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">
<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>.
The primary specialization 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&lt;T&gt;::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&lt;T&gt;::max()</code>
</p>
</td>
</tr>
</tbody>
</table></div>
<p>
Note: The <span class="emphasis"><em>is_integral</em></span> flag is provided, because a user-defined
integer class should specialize <code class="literal">std::numeric_limits&lt;&gt;::is_integer
= true</code>, while compile-time constants <code class="literal">const_min</code>
and <code class="literal">const_max</code> are not provided for that user-defined class,
unless boost::integer_traits is also specialized.
</p>
</div>
<div class="section">
<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">
<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 &#169; 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/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="integer.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

246
doc/html/index.html Normal file
View File

@ -0,0 +1,246 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Boost.Integer</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<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/src/images/next.png" alt="Next"></a></div>
<div class="article">
<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 &#169; 2001 -2009 Beman Dawes, Daryle Walker, Gennaro Prota,
John Maddock</p></div>
<div><div class="legalnotice">
<a name="id759732"></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">
<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 provides integer type support, particularly helpful in generic
programming. It provides standard C99 integer types, such as might be found
in &lt;stdint.h&gt;, without requiring that header. It provides the means to
select an integer type based upon its properties, like the number of bits or
the maximum supported value, as well as compile-time bit mask selection. There
is a derivative of std::numeric_limits that provides integral constant expressions
for <code class="computeroutput"><span class="identifier">min</span></code> and <code class="computeroutput"><span class="identifier">max</span></code>.
Finally, it provides two compile-time algorithms: determining the highest power
of two in a compile-time value; and computing min and max of constant expressions.
</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">&lt;boost/integer_fwd.hpp&gt;</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">&lt;boost/cstdint.hpp&gt;</a></code>
</p>
</td>
<td>
<p>
Provides typedef's based on the 1999 C Standard header <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">stdint</span><span class="special">.</span><span class="identifier">h</span><span class="special">&gt;</span></code>, wrapped in namespace boost.
This implementation may #include the compiler supplied <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">stdint</span><span class="special">.</span><span class="identifier">h</span><span class="special">&gt;</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">&lt;boost/integer_traits.hpp&gt;</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/integer.hpp" target="_top">&lt;boost/integer.hpp&gt;</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">&lt;boost/integer/integer_mask.hpp&gt;</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">&lt;boost/integer/static_log2.hpp&gt;</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">&lt;boost/integer/static_min_max.hpp&gt;</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: July 08, 2010 at 20:45:20 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/src/images/next.png" alt="Next"></a></div>
</body>
</html>

840
doc/integer.qbk Normal file
View File

@ -0,0 +1,840 @@
[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 provides integer type support, particularly helpful in generic programming. It provides standard
C99 integer types, such as might be found in <stdint.h>, without requiring that header.
It provides the means to select an integer type based upon its properties, like the number of bits or
the maximum supported value, as well as compile-time bit mask selection. There is a derivative of
std::numeric_limits that provides integral constant expressions for `min` and `max`.
Finally, it provides two compile-time algorithms: determining the highest power of two in a
compile-time value; and computing min and max of constant expressions.
[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/integer.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 for these types 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 for all platforms/compilers, 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 causing 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]. 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 a platform supports integer types with widths of
8, 16, 32, 64, or any combination thereof, then <boost/cstdint.hpp> does provide the
corresponding typedefs.
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 the smallest 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.
The following minimum-width integer types are provided for all platforms:
* [^int_least8_t]
* [^int_least16_t]
* [^int_least32_t]
* [^uint_least8_t]
* [^uint_least16_t]
* [^uint_least32_t]
The following types are available only if, after including <boost/cstdint.hpp>, the macro BOOST_NO_INT64_T is not defined:
* [^int_least64_t]
* [^uint_least64_t]
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.
The following fastest minimum-width integer types are provided for all platforms:
* [^int_fast8_t]
* [^int_fast16_t]
* [^int_fast32_t]
* [^uint_fast8_t]
* [^uint_fast16_t]
* [^uint_fast32_t]
The following types are available only if, after including <boost/cstdint.hpp>, the macro BOOST_NO_INT64_T is not defined:
* [^int_fast64_t]
* [^uint_fast64_t]
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 provided for all platforms.
[endsect]
[section Integer Constant Macros]
The following macros are always defined after inclusion of this header, these allow
integer constants of at least the specified width to be declared:
INT8_C, UINT8_C, INT16_C, UINT16_C, INT32_C, UINT32_C, INTMAX_C, UINTMAX_C.
The macros INT64_C and UINT64_C are also defined if the the macro BOOST_NO_INT64_T is not defined.
The C99 macro __STDC_CONSTANT_MACROS is also defined as an artifact of the implementation.
For example:
#include <boost/cstdint.hpp>
// Here the constant 0x1FFFFFFFF has the correct suffix applied:
static const boost::uint64_t c = INT64_C(0x1FFFFFFFF);
[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>
{
public:
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]. The primary specialization 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: The /is_integral/ flag is provided, because a user-defined integer class should specialize
[^std::numeric_limits<>::is_integer = true], while compile-time constants
[^const_min] and [^const_max] are not provided for that user-defined class, unless boost::integer_traits is also specialized.
[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]`` type;
};
// signed
template<int Bits>
struct int_t
{
/* Member exact may or may not be defined depending upon Bits */
typedef ``['implementation-defined-type]`` exact;
typedef ``['implementation-defined-type]`` least;
typedef int_fast_t<least>::fast fast;
};
// unsigned
template<int Bits>
struct uint_t
{
/* Member exact may or may not be defined depending upon Bits */
typedef ``['implementation-defined-type]`` exact;
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.
The output type is given as the nested type [^fast].
[*Implementation Notes:]
By default, the output type is identical to the input type. Eventually, this code's implementation should
be customized 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
nested type [^least]. The easiest-to-manipulate version of that type is given by the nested type [^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>::least]]
[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::int_t<N>::fast]]
[The easiest-to-manipulate, 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::int_t<N>::exact]]
[A built-in, signed integral type with exactly /N/ bits, including the sign bit.
The parameter should be a positive number. Note that the member /exact/ is defined
[*only] if there exists a type with exactly /N/ bits.]
]
[
[[^boost::uint_t<N>::least]]
[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::uint_t<N>::fast]]
[The easiest-to-manipulate, 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::uint_t<N>::exact]]
[A built-in, unsigned integral type with exactly /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.
Note that the member /exact/ is defined
[*only] if there exists a type with exactly N bits.]
]
[
[[^boost::int_max_value_t<V>::last]]
[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_max_value_t<V>::fast]]
[The easiest-to-manipulate, 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>::least]]
[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::int_min_value_t<V>::fast]]
[The easiest-to-manipulate, 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>::least]]
[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.]
]
[
[[^boost::uint_value_t<V>::fast]]
[The easiest-to-manipulate, 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, its 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 easiest-to-manipulate analog of [^least].]]
[[[^high_bit]][A [^least] constant of the value 2[super Bit].]]
[[[^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
equivalent to the value (2[super Bits] - 1), where [^Bits] is the template parameter.
The parameter [^Bits] must be a non-negative integer 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 [^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 easiest-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 convenient masks to use when extracting the
highest or all the significant bits when the containing built-in type contains more bits.
This prevents contamination 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 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 available statically (['i.e.] at compile-time).
[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]

View File

@ -1,377 +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">&lt;boost/integer/integer_mask.hpp&gt;</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="#mpl">MPL-Compatible Variants</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 &lt;<a href="../../../boost/integer_fwd.hpp">boost/integer_fwd.hpp</a>&gt; <i>// forwarding header</i>
#include &lt;<a href="../../../boost/integer.hpp">boost/integer.hpp</a>&gt; <i>// for boost::int_fast_t</i>
#include &lt;cstddef&gt; <i>// for std::size_t</i>
namespace boost
{
// MPL-compatible
template &lt; int Offset &gt;
struct integer_hi_mask
{
static bool const is_specialized = <em>implementation_supplied</em>;
static int const bit_offset = Offset;
typedef <em>implementation_supplied</em> type;
typedef <em>implementation_supplied</em> value_type;
static value_type const value = <em>implementation_supplied</em>;
// There are other (optional) operations....
};
template &lt; int Length &gt;
struct integer_lo_mask
{
static bool const is_specialized = <em>implementation_supplied</em>;
static int const bit_count = Length;
typedef <em>implementation_supplied</em> type;
typedef <em>implementation_supplied</em> value_type;
static value_type const value = <em>implementation_supplied</em>;
// There are other (optional) operations....
};
// single
template &lt; std::size_t Bit &gt;
class high_bit_mask_t
{
public:
typedef typename integer_hi_mask&lt;Bit&gt;::value_type least;
typedef int_fast_t&lt;least&gt;::fast fast;
static const least high_bit = integer_hi_mask&lt;Bit&gt;::value;
static const fast high_bit_fast = high_bit;
static const std::size_t bit_position = Bit;
};
// group
template &lt; std::size_t Bits &gt;
class low_bits_mask_t
{
public:
typedef typename integer_lo_mask&lt;Bits&gt;::value_type least;
typedef int_fast_t&lt;least&gt;::fast fast;
static const least sig_bits = integer_lo_mask&lt;Bits&gt;::value;
static const fast sig_bits_fast = sig_bits;
static const std::size_t bit_count = Bits;
};
} // 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>
<h2><a name="mpl">MPL-Compatible Variants</a></h2>
<p>The single and group bit-mask class templates have several drawbacks:</p>
<ul>
<li>You must know the valid bit-lengths in advance.</li>
<li>Using an inappropriate parameter value results in a compiler
diagnostic.</li>
<li>The type names used are inconsistent with other transformations in
Boost, like in <a href="../../mpl/">MPL</a>.</li>
<li>The above two facts make use of the regular bit-mask class templates
incompatible with template meta-programming techniques.</li>
</ul>
<p>The <code>integer_hi_mask</code> and <code>integer_lo_mask</code> class
templates provide MPL-compatible alternatives. These alternatives have the
form:</p>
<blockquote><pre>
template&lt; int <var>Size</var> &gt;
struct <var>name</var>
{
static bool const is_specialized = <em>implementation_supplied</em>;
static int const <var>switch_id</var> = <var>Size</var>;
typedef <em>implementation_supplied</em> type;
typedef <em>implementation_supplied</em> value_type;
static value_type const value = <em>implementation_supplied</em>;
// with other operations...
};
</pre></blockquote>
<p>Only some of the members are always present. The presence of other members
and operations is flagged by the (always-present) <code>is_specialized</code>.</p>
<table border="2" cellpadding="5" align="center">
<caption>Permanent Members of the MPL-Compatible Masking Class Template
Types</caption>
<tr>
<th>Class Template Member</th>
<th>Meaning</th>
</tr>
<tr>
<td><code>is_specialized</code></td>
<td>Flag indicating when a particular template class instantiation is a
valid meta-function (<code>true</code>) or not (<code>false</code>).</td>
</tr>
<tr>
<td><code><var>switch_id</var></code> (Actual name is template-specific.)</td>
<td>The value of the main control parameter, accessible even if the
template class instantiation is aliased.</td>
</tr>
</table>
<p>The optional members are based from inheriting from a <a
href="../../mpl/doc/refmanual/integral-constant.html">MPL-style Integral
Constant</a> type, but only if <code>is_specialized</code> is <code>true</code>.</p>
<table border="2" cellpadding="5" align="center">
<caption>Optional Members of the MPL-Compatible Masking Types</caption>
<tr>
<th>Class Template Member</th>
<th>Meaning</th>
</tr>
<tr>
<td><code>value</code></td>
<td>The actual bit mask.</td>
</tr>
<tr>
<td><code>value_type</code></td>
<td>The type of the bit mask value.</td>
</tr>
<tr>
<td><code>type</code></td>
<td>The Integral Constant</a> implementation type, which should be
<code><a href="../../mpl/doc/refmanual/integral-c.html">boost::mpl::
integral_c</a>&lt; <var>value_type</var>, <var>value</var>
&gt;</code>.</td>
</tr>
</table>
<p>The Integral Constant prototype also adds the following operations:</p>
<table border="2" cellpadding="5" align="center">
<caption>Optional Operations of the MPL-Compatible Masking Types</caption>
<tr>
<th>Operation (with <var>n</var> as a masking type)</th>
<th>Meaning</th>
</tr>
<tr>
<td><code>boost::mpl::next&lt; n &gt;::type</code></td>
<td><code>boost::mpl::next&lt; n::type &gt;::type</code>, i.e.
<code>boost::mpl::integral_c&lt; n::value_type, n::value + 1
&gt;</code>.</td>
</tr>
<tr>
<td><code>boost::mpl::prior&lt; n &gt;::type</code></td>
<td><code>boost::mpl::prior&lt; n::type &gt;::type</code>, i.e.
<code>boost::mpl::integral_c&lt; n::value_type, n::value - 1
&gt;</code>.</td>
</tr>
<tr>
<td><code>n::value_type const c = n();</code></td>
<td><var>c</var> is set to <code>n::value</code>.</td>
</tr>
</table>
<p>The specifics for each masking class template are:</p>
<table border="2" cellpadding="5" align="center">
<caption>Criteria for the MPL-Compatible Masking Types<br>
(Everything besides the parameter ID is in name-space
<code>boost</code> except where indicated.)</caption>
<tr>
<th>Class Template</th>
<th>Parameter Member ID</th>
<th>Classic Equivalent</th>
<th>Value Type</th>
<th>Value</th>
<th>Valid Range</th>
</tr>
<tr>
<td><code>integer_hi_mask</code></td>
<td><code>bit_offset</code></td>
<td><code>high_bit_mask_t</code></td>
<td><code>sized_integral &lt; bit_offset + 1, unsigned &gt;</code></td>
<td>2<sup><code>bit_offset</code></sup></td>
<td><code>0 &lt;= bit_offset &lt; std::numeric_limits&lt; uintmax_t &gt;::digits</code></td>
</tr>
<tr>
<td><code>integer_lo_mask</code></td>
<td><code>bit_count</code></td>
<td><code>low_bits_mask_t</code></td>
<td><code>sized_integral &lt; bit_count, unsigned &gt;</code></td>
<td>2<sup><code>bit_offset</code></sup> - 1</td>
<td><code>0 &lt;= bit_count &lt;= std::numeric_limits&lt; uintmax_t &gt;::digits</code></td>
</tr>
</table>
<h2><a name="example">Example</a></h2>
<blockquote><pre>
#include &lt;<a href="../../../boost/integer/integer_mask.hpp">boost/integer/integer_mask.hpp</a>&gt;
//...
int main()
{
typedef boost::high_bit_mask_t&lt;29&gt; mask1_type;
typedef boost::low_bits_mask_t&lt;15&gt; mask2_type;
mask1_type::least my_var1;
mask2_type::fast my_var2;
//...
my_var1 |= mask1_type::high_bit;
my_var2 &amp;= 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 July 29, 2008</p>
<p>&copy; 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 &lt;<a
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>&gt;.)</p>
</body>
</html>

View File

@ -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">&lt;boost/integer/static_log2.hpp&gt;</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 &lt; static_log2_argument_type arg &gt;
struct static_log2
{
static const static_log2_result_type value = <em>implementation-defined</em>;
};
template &lt; &gt;
struct static_log2&lt; 0 &gt;
{
// 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 &lt; boost::static_log2_argument_type value &gt;
bool is_it_what()
{
typedef boost::static_log2&lt;value&gt; lb_type;
int temp = lb_type::value;
//...
return (temp % 2) != 0;
}
//...
int main()
{
bool temp = is_it_what&lt;2000&gt;();
//...
# if 0
temp = is_it_what&lt;0&gt;(); // would give an error
# endif
//...
temp = is_it_what&lt;24&gt;();
//...
}
</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>&copy; Copyright Daryle Walker 2001.<br>
&copy; 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>

View File

@ -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">&lt;boost/integer/static_min_max.hpp&gt;</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 &lt; long Value1, long Value2 &gt;
struct static_signed_min;
template &lt; long Value1, long Value2 &gt;
struct static_signed_max;
template &lt; unsigned long Value1, unsigned long Value2 &gt;
struct static_unsigned_min;
template &lt; unsigned long Value1, unsigned long Value2 &gt;
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 &lt;boost/integer/static_min_max.hpp&gt;
template &lt; unsigned long AddendSize1, unsigned long AddendSize2 &gt;
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&lt;AddendSize1, AddendSize2&gt;::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 &amp;a1, addend2_type const &amp;a2, sum_type &amp;s ) const;
};
//...
int main()
{
int const a1[] = { 0, 4, 3 }; // 340
int const a2[] = { 9, 8 }; // 89
int s[ 4 ];
adder&lt;3,2&gt; 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>&copy; 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 &lt;<a
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>&gt;.)</p>
</body>
</html>

View File

@ -23,10 +23,25 @@
#ifndef BOOST_CSTDINT_HPP
#define BOOST_CSTDINT_HPP
//
// Since we always define the INT#_C macros as per C++0x,
// define __STDC_CONSTANT_MACROS so that <stdint.h> does the right
// thing if possible, and so that the user knows that the macros
// are actually defined as per C99.
//
#ifndef __STDC_CONSTANT_MACROS
# define __STDC_CONSTANT_MACROS
#endif
#include <boost/config.hpp>
#ifdef BOOST_HAS_STDINT_H
//
// Note that GLIBC is a bit inconsistent about whether int64_t is defined or not
// depending upon what headers happen to have been included first...
// so we disable use of stdint.h when GLIBC does not define __GLIBC_HAVE_LONG_LONG.
// See https://svn.boost.org/trac/boost/ticket/3548 and http://sources.redhat.com/bugzilla/show_bug.cgi?id=10990
//
#if defined(BOOST_HAS_STDINT_H) && (!defined(__GLIBC__) || defined(__GLIBC_HAVE_LONG_LONG))
// The following #include is an implementation artifact; not part of interface.
# ifdef __hpux
@ -36,7 +51,7 @@
// this is triggered with GCC, because it defines __cplusplus < 199707L
# define BOOST_NO_INT64_T
# endif
# elif defined(__FreeBSD__) || defined(__IBMCPP__)
# elif defined(__FreeBSD__) || defined(__IBMCPP__) || defined(_AIX)
# include <inttypes.h>
# else
# include <stdint.h>
@ -122,7 +137,7 @@ namespace boost
} // namespace boost
#elif defined(__FreeBSD__) && (__FreeBSD__ <= 4) || defined(__osf__)
#elif defined(__FreeBSD__) && (__FreeBSD__ <= 4) || defined(__osf__) || defined(__VMS)
// FreeBSD and Tru64 have an <inttypes.h> that contains much of what we need.
# include <inttypes.h>
@ -220,6 +235,15 @@ namespace boost
typedef unsigned short uint_least16_t;
typedef unsigned short uint_fast16_t;
# endif
# elif (USHRT_MAX == 0xffffffff) && defined(__MTA__)
// On MTA / XMT short is 32 bits unless the -short16 compiler flag is specified
// MTA / XMT does support the following non-standard integer types
typedef __short16 int16_t;
typedef __short16 int_least16_t;
typedef __short16 int_fast16_t;
typedef unsigned __short16 uint16_t;
typedef unsigned __short16 uint_least16_t;
typedef unsigned __short16 uint_fast16_t;
# elif (USHRT_MAX == 0xffffffff) && defined(CRAY)
// no 16-bit types on Cray:
typedef short int_least16_t;
@ -232,20 +256,35 @@ namespace boost
// 32-bit types -----------------------------------------------------------//
# if ULONG_MAX == 0xffffffff
typedef long int32_t;
typedef long int_least32_t;
typedef long int_fast32_t;
typedef unsigned long uint32_t;
typedef unsigned long uint_least32_t;
typedef unsigned long uint_fast32_t;
# elif UINT_MAX == 0xffffffff
# if UINT_MAX == 0xffffffff
typedef int int32_t;
typedef int int_least32_t;
typedef int int_fast32_t;
typedef unsigned int uint32_t;
typedef unsigned int uint_least32_t;
typedef unsigned int uint_fast32_t;
# elif (USHRT_MAX == 0xffffffff)
typedef short int32_t;
typedef short int_least32_t;
typedef short int_fast32_t;
typedef unsigned short uint32_t;
typedef unsigned short uint_least32_t;
typedef unsigned short uint_fast32_t;
# elif ULONG_MAX == 0xffffffff
typedef long int32_t;
typedef long int_least32_t;
typedef long int_fast32_t;
typedef unsigned long uint32_t;
typedef unsigned long uint_least32_t;
typedef unsigned long uint_fast32_t;
# elif (UINT_MAX == 0xffffffffffffffff) && defined(__MTA__)
// Integers are 64 bits on the MTA / XMT
typedef __int32 int32_t;
typedef __int32 int_least32_t;
typedef __int32 int_fast32_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int32 uint_least32_t;
typedef unsigned __int32 uint_fast32_t;
# else
# error defaults not correct; you must hand modify boost/cstdint.hpp
# endif
@ -326,91 +365,130 @@ namespace boost
Macro definition section:
Define various INTXX_C macros only if
__STDC_CONSTANT_MACROS is defined.
Undefine the macros if __STDC_CONSTANT_MACROS is
not defined and the macros are (cf <cassert>).
Added 23rd September 2000 (John Maddock).
Modified 11th September 2001 to be excluded when
BOOST_HAS_STDINT_H is defined (John Maddock).
Modified 11th Dec 2009 to always define the
INT#_C macros if they're not already defined (John Maddock).
******************************************************/
#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(BOOST_HAS_STDINT_H)
#if !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && \
(!defined(INT8_C) || !defined(INT16_C) || !defined(INT32_C) || !defined(INT64_C))
//
// For the following code we get several warnings along the lines of:
//
// boost/cstdint.hpp:428:35: error: use of C99 long long integer constant
//
// So we declare this a system header to suppress these warnings.
//
#if defined(__GNUC__) && (__GNUC__ >= 4)
#pragma GCC system_header
#endif
#include <limits.h>
# define BOOST__STDC_CONSTANT_MACROS_DEFINED
# if defined(BOOST_HAS_MS_INT64)
//
// Borland/Intel/Microsoft compilers have width specific suffixes:
//
#ifndef INT8_C
# define INT8_C(value) value##i8
#endif
#ifndef INT16_C
# define INT16_C(value) value##i16
#endif
#ifndef INT32_C
# define INT32_C(value) value##i32
#endif
#ifndef INT64_C
# define INT64_C(value) value##i64
#endif
# ifdef __BORLANDC__
// Borland bug: appending ui8 makes the type a signed char
# define UINT8_C(value) static_cast<unsigned char>(value##u)
# else
# define UINT8_C(value) value##ui8
# endif
#ifndef UINT16_C
# define UINT16_C(value) value##ui16
#endif
#ifndef UINT32_C
# define UINT32_C(value) value##ui32
#endif
#ifndef UINT64_C
# define UINT64_C(value) value##ui64
#endif
#ifndef INTMAX_C
# define INTMAX_C(value) value##i64
# define UINTMAX_C(value) value##ui64
#endif
# else
// do it the old fashioned way:
// 8-bit types ------------------------------------------------------------//
# if UCHAR_MAX == 0xff
# if (UCHAR_MAX == 0xff) && !defined(INT8_C)
# define INT8_C(value) static_cast<boost::int8_t>(value)
# define UINT8_C(value) static_cast<boost::uint8_t>(value##u)
# endif
// 16-bit types -----------------------------------------------------------//
# if USHRT_MAX == 0xffff
# if (USHRT_MAX == 0xffff) && !defined(INT16_C)
# define INT16_C(value) static_cast<boost::int16_t>(value)
# define UINT16_C(value) static_cast<boost::uint16_t>(value##u)
# endif
// 32-bit types -----------------------------------------------------------//
# if UINT_MAX == 0xffffffff
#ifndef INT32_C
# if (UINT_MAX == 0xffffffff)
# define INT32_C(value) value
# define UINT32_C(value) value##u
# elif ULONG_MAX == 0xffffffff
# define INT32_C(value) value##L
# define UINT32_C(value) value##uL
# endif
#endif
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
#ifndef INT64_C
# if defined(BOOST_HAS_LONG_LONG) && \
(defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
(defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX) || defined(_LLONG_MAX))
# if defined(__hpux)
// HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || \
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U) || \
(defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U)
// HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
# define INT64_C(value) value##LL
# define UINT64_C(value) value##uLL
# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || \
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || \
(defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL) || \
(defined(_LLONG_MAX) && _LLONG_MAX == 18446744073709551615ULL)
# define INT64_C(value) value##LL
# define UINT64_C(value) value##uLL
# else
# error defaults not correct; you must hand modify boost/cstdint.hpp
# endif
# define INT64_C(value) value##LL
# define UINT64_C(value) value##uLL
# elif ULONG_MAX != 0xffffffff
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
# if ULONG_MAX == 18446744073709551615U // 2**64 - 1
# define INT64_C(value) value##L
# define UINT64_C(value) value##uL
# else
# error defaults not correct; you must hand modify boost/cstdint.hpp
# endif
# elif defined(BOOST_HAS_LONG_LONG)
// Usual macros not defined, work things out for ourselves:
# if(~0uLL == 18446744073709551615ULL)
# define INT64_C(value) value##LL
# define UINT64_C(value) value##uLL
# else
# error defaults not correct; you must hand modify boost/cstdint.hpp
# endif
# else
# error defaults not correct; you must hand modify boost/cstdint.hpp
# endif
# ifdef BOOST_NO_INT64_T
@ -420,26 +498,10 @@ BOOST_HAS_STDINT_H is defined (John Maddock).
# define INTMAX_C(value) INT64_C(value)
# define UINTMAX_C(value) UINT64_C(value)
# endif
#endif
# endif // Borland/Microsoft specific width suffixes
#elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS) && !defined(BOOST_HAS_STDINT_H)
//
// undef all the macros:
//
# undef INT8_C
# undef INT16_C
# undef INT32_C
# undef INT64_C
# undef UINT8_C
# undef UINT16_C
# undef UINT32_C
# undef UINT64_C
# undef INTMAX_C
# undef UINTMAX_C
#endif // __STDC_CONSTANT_MACROS_DEFINED etc.
#endif // INT#_C macros.

View File

@ -1,177 +0,0 @@
// Boost detail/extended_integer.hpp header file ----------------------------//
// (C) Copyright Daryle Walker 2008. Distributed under the Boost Software
// License, Version 1.0. (See the accompanying file LICENSE_1_0.txt or a copy
// at <http://www.boost.org/LICENSE_1_0.txt>.)
// Encapsulates the double-long and __int64 type families as a single family,
// as they are mutually exclusive.
/** \file
\brief Common definition of extended integer types.
Instead of other Boost headers making separate \#defines for the double-long
and __int64 type families, since they're mutually exclusive, make a single
set of types and macros for the family that exists (if either).
*/
#ifndef BOOST_DETAIL_EXTENDED_INTEGER_HPP
#define BOOST_DETAIL_EXTENDED_INTEGER_HPP
#include <boost/config.hpp> // for BOOST_HAS_LONG_LONG and BOOST_HAS_MS_INT64
#include <climits> // for CHAR_BIT, etc.
namespace boost
{
namespace detail
{
// Extended integer type macro and alias definitions -----------------------//
// (Unsigned) long long family
#ifdef BOOST_HAS_LONG_LONG
// Existence
#define BOOST_HAS_XINT 1
// Extents
#ifdef ULLONG_MAX
#define BOOST_XINT_MAX LLONG_MAX
#define BOOST_XINT_MIN LLONG_MIN
#define BOOST_UXINT_MAX ULLONG_MAX
#elif defined(ULONG_LONG_MAX)
#define BOOST_XINT_MAX LONG_LONG_MAX
#define BOOST_XINT_MIN LONG_LONG_MIN
#define BOOST_UXINT_MAX ULONG_LONG_MAX
#elif defined(ULONGLONG_MAX)
#define BOOST_XINT_MAX LONGLONG_MAX
#define BOOST_XINT_MIN LONGLONG_MIN
#define BOOST_UXINT_MAX ULONGLONG_MAX
#elif defined(_LLONG_MAX) && defined(_C2)
#define BOOST_XINT_MAX _LLONG_MAX
#define BOOST_XINT_MIN (-_LLONG_MAX - _C2)
#define BOOST_UXINT_MAX _ULLONG_MAX
#else // guess
// Sometimes we get the double-long types without the corresponding constants,
// e.g. GCC in "-ansi" mode. In this case, we'll just have to work out the
// values ourselves. (Here we assume a two's complement representation.)
#define BOOST_XINT_MIN (1LL << (sizeof(::boost::long_long_type) * CHAR_BIT - 1))
#define BOOST_XINT_MAX (~ BOOST_XINT_MIN)
#define BOOST_UXINT_MAX (~ 0uLL)
#endif
// Types
typedef ::boost:: long_long_type xint_t;
typedef ::boost::ulong_long_type uxint_t;
// (Unsigned) __int64 family
#elif defined(BOOST_HAS_MS_INT64)
// Existence
#define BOOST_HAS_XINT 1
// Extents
#ifdef _UI64_MAX
#define BOOST_XINT_MAX _I64_MAX
#define BOOST_XINT_MIN _I64_MIN
#define BOOST_UXINT_MAX _UI64_MAX
#else // guess
// The types are exactly 2's-compl. 64-bit, so we'll enter the values directly.
#define BOOST_XINT_MAX 0x7FFFFFFFFFFFFFFFi64
#define BOOST_XINT_MIN 0x8000000000000000i64
#define BOOST_UXINT_MAX 0xFFFFFFFFFFFFFFFFui64
#endif
// Types
typedef __int64 xint_t;
typedef unsigned __int64 uxint_t;
// Neither
#else
// Non-existence
#define BOOST_HAS_XINT 0
// Dummy extents
#define BOOST_XINT_MAX LONG_MAX
#define BOOST_XINT_MIN LONG_MIN
#define BOOST_UXINT_MAX ULONG_MAX
// Dummy types
typedef signed long xint_t;
typedef unsigned long uxint_t;
#endif // defined(BOOST_HAS_LONG_LONG)/defined(BOOST_HAS_MS_INT64)/else
/** \def BOOST_HAS_XINT
\brief Flag for extended integer types.
Indicates the presence of one of the two common extended integer type
families, either (<code>unsigned</code>) <code>long long</code> or
(<code>unsigned</code>) <code>__int64</code>. \c BOOST_HAS_XINT is \c 1 if
either type family is defined, and \c 0 if neither is.
*/
/** \def BOOST_XINT_MAX
\brief Maximum value for the signed extended integer type.
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
Macro constant representing the largest value the signed extended integer
type supports. Its composition may be another macro, an expression, or a
literal. Defaulted to \c LONG_MAX if \c BOOST_HAS_XINT is zero.
*/
/** \def BOOST_XINT_MIN
\brief Minimum value for the signed extended integer type.
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
Macro constant representing the smallest value the signed extended integer
type supports. Its composition may be another macro, an expression, or a
literal. Defaulted to \c LONG_MIN if \c BOOST_HAS_XINT is zero.
*/
/** \def BOOST_UXINT_MAX
\brief Maximum value for the unsigned extended integer type.
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
Macro constant representing the largest value the unsigned extended integer
type supports. Its composition may be another macro, an expression, or a
literal. Defaulted to \c ULONG_MAX if \c BOOST_HAS_XINT is zero. (Use
\c 0u for the type's minimum value.)
*/
/** \typedef signed long boost::detail::xint_t
\brief Alias for the signed extended integer type.
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
Alias representing the signed extended integer type, no matter which type
family it came from. Defaulted to <code>signed long</code> if
\c BOOST_HAS_XINT is zero.
*/
/** \typedef unsigned long ::boost::detail::uxint_t
\brief Alias for the signed extended integer type.
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
Alias representing the unsigned extended integer type, no matter which type
family it came from. Defaulted to <code>unsigned long</code> if
\c BOOST_HAS_XINT is zero.
*/
} // namespace detail
} // namespace boost
#endif // BOOST_DETAIL_EXTENDED_INTEGER_HPP

View File

@ -7,12 +7,6 @@
// See http://www.boost.org/libs/integer for documentation.
// Revision History
// 16 Jul 08 Added MPL-compatible variants of the minimum-size and value-
// based integer templates. (Daryle Walker)
// 15 Jul 08 Added exact-integer templates; added MPL-compatible variant of
// processor-optimized integer template. (Daryle Walker)
// 14 Jul 08 Added extended-integer support. (Daryle Walker)
// 13 Jul 08 Redid implmentation. (Daryle Walker)
// 22 Sep 01 Added value-based integer templates. (Daryle Walker)
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (John Maddock)
// 30 Jul 00 Add typename syntax fix (Jens Maurer)
@ -23,357 +17,238 @@
#include <boost/integer_fwd.hpp> // self include
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT, etc.
#include <boost/cstdint.hpp> // for boost::uintmax_t, intmax_t
#include <boost/integer_traits.hpp> // for boost::integer_traits
#include <boost/limits.hpp> // for std::numeric_limits
#include <boost/utility/enable_if.hpp> // for boost::enable_if_c
#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
#include <boost/detail/extended_integer.hpp> // for BOOST_HAS_XINT, etc.
#include <climits> // for UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, etc.
//
// We simply cannot include this header on gcc without getting copious warnings of the kind:
//
// boost/integer.hpp:77:30: warning: use of C99 long long integer constant
//
// And yet there is no other reasonable implementation, so we declare this a system header
// to suppress these warnings.
//
#if defined(__GNUC__) && (__GNUC__ >= 4)
#pragma GCC system_header
#endif
namespace boost
{
// integer template mapping a type to its processor-optimized analog -----//
// Some types can be handled better by the processor than others. This
// template metafunction should map various built-in integral types to
// the processor's perferred type for the given type's value range
template < typename BaseInt >
struct fast_integral
{
typedef BaseInt type;
};
// Platform-specific specializations should go here.
// Helper templates ------------------------------------------------------//
// fast integers from least integers
// int_fast_t<> works correctly for unsigned too, in spite of the name.
template< typename LeastInt >
struct int_fast_t { typedef typename fast_integral<LeastInt>::type fast; };
struct int_fast_t
{
typedef LeastInt fast;
typedef fast type;
}; // imps may specialize
namespace detail
{
namespace detail{
// Helper templates ------------------------------------------------------//
// convert category to type
template< int Category > struct int_least_helper {}; // default is empty
// convert integer category to type ; default is empty
template< int Rank, typename Signedness > struct int_least_helper {};
// specializatons: 1=(unsigned) __int64/long long, 2=(unsigned) long,
// 3=unsigned/int, 4=(unsigned) short, 5=(un)signed char
// no specializations for 0: requests for a type > (unsigned) (long) long are
// in error
#if BOOST_HAS_XINT
template<> struct int_least_helper<1, signed> { typedef xint_t least; };
template<> struct int_least_helper<1, unsigned> { typedef uxint_t least; };
// specializatons: 1=long, 2=int, 3=short, 4=signed char,
// 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned char
// no specializations for 0 and 5: requests for a type > long are in error
#ifdef BOOST_HAS_LONG_LONG
template<> struct int_least_helper<1> { typedef boost::long_long_type least; };
#elif defined(BOOST_HAS_MS_INT64)
template<> struct int_least_helper<1> { typedef __int64 least; };
#endif
template<> struct int_least_helper<2, signed> { typedef long least; };
template<> struct int_least_helper<2, unsigned>
{ typedef unsigned long least; };
template<> struct int_least_helper<3, signed> { typedef int least; };
template<> struct int_least_helper<3, unsigned>
{ typedef unsigned int least; };
template<> struct int_least_helper<4, signed> { typedef short least; };
template<> struct int_least_helper<4, unsigned>
{ typedef unsigned short least; };
template<> struct int_least_helper<5, signed> { typedef signed char least; };
template<> struct int_least_helper<5, unsigned>
{ typedef unsigned char least; };
// category bounds
enum
{
#if BOOST_HAS_XINT
lowest_integral_rank = 1,
#else
lowest_integral_rank = 2,
template<> struct int_least_helper<2> { typedef long least; };
template<> struct int_least_helper<3> { typedef int least; };
template<> struct int_least_helper<4> { typedef short least; };
template<> struct int_least_helper<5> { typedef signed char least; };
#ifdef BOOST_HAS_LONG_LONG
template<> struct int_least_helper<6> { typedef boost::ulong_long_type least; };
#elif defined(BOOST_HAS_MS_INT64)
template<> struct int_least_helper<6> { typedef unsigned __int64 least; };
#endif
highest_integral_rank = 5
};
template<> struct int_least_helper<7> { typedef unsigned long least; };
template<> struct int_least_helper<8> { typedef unsigned int least; };
template<> struct int_least_helper<9> { typedef unsigned short least; };
template<> struct int_least_helper<10> { typedef unsigned char least; };
// map a bit count to a category
template < int BitsIncludingSign >
struct int_rank_helper
{
BOOST_STATIC_CONSTANT( int, mantissa = BitsIncludingSign - 1 );
#if BOOST_HAS_XINT
BOOST_STATIC_CONSTANT( int, extended_ = (mantissa <= std::numeric_limits<
xint_t >::digits) );
#else
BOOST_STATIC_CONSTANT( int, extended_ = 1 );
template <int Bits>
struct exact_signed_base_helper{};
template <int Bits>
struct exact_unsigned_base_helper{};
template <> struct exact_signed_base_helper<sizeof(signed char)* CHAR_BIT> { typedef signed char exact; };
template <> struct exact_unsigned_base_helper<sizeof(unsigned char)* CHAR_BIT> { typedef unsigned char exact; };
#if USHRT_MAX != UCHAR_MAX
template <> struct exact_signed_base_helper<sizeof(short)* CHAR_BIT> { typedef short exact; };
template <> struct exact_unsigned_base_helper<sizeof(unsigned short)* CHAR_BIT> { typedef unsigned short exact; };
#endif
BOOST_STATIC_CONSTANT( int, rank = (BitsIncludingSign > 0) * (extended_ +
(mantissa <= std::numeric_limits< long >::digits) +
(mantissa <= std::numeric_limits< int >::digits) +
(mantissa <= std::numeric_limits< short >::digits) +
(mantissa <= std::numeric_limits< signed char >::digits)) );
};
template < int Bits >
struct uint_rank_helper
{
#if BOOST_HAS_XINT
BOOST_STATIC_CONSTANT( int, extended_ = (Bits <= std::numeric_limits<
uxint_t >::digits) );
#else
BOOST_STATIC_CONSTANT( int, extended_ = 1 );
#if UINT_MAX != USHRT_MAX
template <> struct exact_signed_base_helper<sizeof(int)* CHAR_BIT> { typedef int exact; };
template <> struct exact_unsigned_base_helper<sizeof(unsigned int)* CHAR_BIT> { typedef unsigned int exact; };
#endif
BOOST_STATIC_CONSTANT( int, rank = (Bits >= 0) * (extended_ +
(Bits <= std::numeric_limits< unsigned long >::digits) +
(Bits <= std::numeric_limits< unsigned int >::digits) +
(Bits <= std::numeric_limits< unsigned short >::digits) +
(Bits <= std::numeric_limits< unsigned char >::digits)) );
};
template < int BitsIncludingSign >
struct int_exact_rank_helper { BOOST_STATIC_CONSTANT( int, rank = 0 ); };
template < int Bits >
struct uint_exact_rank_helper { BOOST_STATIC_CONSTANT( int, rank = 0 ); };
#define BOOST_PRIVATE_INT_EXACT_BUILDER(Type, Rank) \
template < > \
struct int_exact_rank_helper<std::numeric_limits< Type >::digits + 1> \
{ BOOST_STATIC_CONSTANT( int, rank = Rank ); }
#define BOOST_PRIVATE_UINT_EXACT_BUILDER(Type, Rank) \
template < > \
struct uint_exact_rank_helper<std::numeric_limits< Type >::digits> \
{ BOOST_STATIC_CONSTANT( int, rank = Rank ); }
#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX)
BOOST_PRIVATE_INT_EXACT_BUILDER( xint_t, 1 );
BOOST_PRIVATE_UINT_EXACT_BUILDER( uxint_t, 1 );
#if ULONG_MAX != UINT_MAX
template <> struct exact_signed_base_helper<sizeof(long)* CHAR_BIT> { typedef long exact; };
template <> struct exact_unsigned_base_helper<sizeof(unsigned long)* CHAR_BIT> { typedef unsigned long exact; };
#endif
#if ULONG_MAX > UINT_MAX
BOOST_PRIVATE_INT_EXACT_BUILDER( long, 2 );
BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned long, 2 );
#if defined(BOOST_HAS_LONG_LONG) &&\
((defined(ULLONG_MAX) && (ULLONG_MAX != ULONG_MAX)) ||\
(defined(ULONG_LONG_MAX) && (ULONG_LONG_MAX != ULONG_MAX)) ||\
(defined(ULONGLONG_MAX) && (ULONGLONG_MAX != ULONG_MAX)) ||\
(defined(_ULLONG_MAX) && (_ULLONG_MAX != ULONG_MAX)))
template <> struct exact_signed_base_helper<sizeof(boost::long_long_type)* CHAR_BIT> { typedef boost::long_long_type exact; };
template <> struct exact_unsigned_base_helper<sizeof(boost::ulong_long_type)* CHAR_BIT> { typedef boost::ulong_long_type exact; };
#endif
#if UINT_MAX > USHRT_MAX
BOOST_PRIVATE_INT_EXACT_BUILDER( int, 3 );
BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned, 3 );
#endif
#if USHRT_MAX > UCHAR_MAX
BOOST_PRIVATE_INT_EXACT_BUILDER( short, 4 );
BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned short, 4 );
#endif
BOOST_PRIVATE_INT_EXACT_BUILDER( signed char, 5 );
BOOST_PRIVATE_UINT_EXACT_BUILDER( unsigned char, 5 );
#undef BOOST_PRIVATE_INT_EXACT_BUILDER
#undef BOOST_PRIVATE_UINT_EXACT_BUILDER
// map an extreme value to a category
template < intmax_t MaxValue >
struct int_max_rank_helper
{
#if BOOST_HAS_XINT
BOOST_STATIC_CONSTANT( int, extended_ = (MaxValue <=
boost::integer_traits< xint_t >::const_max) );
#else
BOOST_STATIC_CONSTANT( int, extended_ = 1 );
#endif
BOOST_STATIC_CONSTANT( int, rank = (MaxValue > 0) * (extended_ +
(MaxValue <= boost::integer_traits< long >::const_max) +
(MaxValue <= boost::integer_traits< int >::const_max) +
(MaxValue <= boost::integer_traits< short >::const_max) +
(MaxValue <= boost::integer_traits< signed char >::const_max)) );
};
template < intmax_t MinValue >
struct int_min_rank_helper
{
#if BOOST_HAS_XINT
BOOST_STATIC_CONSTANT( int, extended_ = (MinValue >=
boost::integer_traits< xint_t >::const_min) );
#else
BOOST_STATIC_CONSTANT( int, extended_ = 1 );
#endif
BOOST_STATIC_CONSTANT( int, rank = (MinValue < 0) * (extended_ +
(MinValue >= boost::integer_traits< long >::const_min) +
(MinValue >= boost::integer_traits< int >::const_min) +
(MinValue >= boost::integer_traits< short >::const_min) +
(MinValue >= boost::integer_traits< signed char >::const_min)) );
};
template < uintmax_t Value >
struct uint_max_rank_helper
{
#if BOOST_HAS_XINT
BOOST_STATIC_CONSTANT( int, extended_ = (Value <= boost::integer_traits<
uxint_t >::const_max) );
#else
BOOST_STATIC_CONSTANT( int, extended_ = 1 );
#endif
BOOST_STATIC_CONSTANT( int, rank = extended_ +
(Value <= boost::integer_traits< unsigned long >::const_max) +
(Value <= boost::integer_traits< unsigned int >::const_max) +
(Value <= boost::integer_traits< unsigned short >::const_max) +
(Value <= boost::integer_traits< unsigned char >::const_max) );
};
// convert rank to type, Boost.MPL-style
template < int Rank, typename Signedness, class Enable = void >
struct integral_rank_to_type
{
BOOST_STATIC_CONSTANT( bool, is_specialized = false );
// No "signed" nor "type" here
};
template < int Rank >
struct integral_rank_to_type< Rank, signed, typename
enable_if_c<(lowest_integral_rank <= Rank) && (Rank <=
highest_integral_rank)>::type >
{
BOOST_STATIC_CONSTANT( bool, is_specialized = true );
BOOST_STATIC_CONSTANT( bool, is_signed = true );
typedef typename int_least_helper< Rank, signed >::least type;
};
template < int Rank >
struct integral_rank_to_type< Rank, unsigned, typename
enable_if_c<(lowest_integral_rank <= Rank) && (Rank <=
highest_integral_rank)>::type >
{
BOOST_STATIC_CONSTANT( bool, is_specialized = true );
BOOST_STATIC_CONSTANT( bool, is_signed = false );
typedef typename int_least_helper< Rank, unsigned >::least type;
};
} // namespace detail
// MPL-compatible integer-mapping class templates ------------------------//
// minimum number of bits
template < int Bits, typename Signedness >
struct sized_integral
{
BOOST_STATIC_CONSTANT( bool, is_specialized = false );
BOOST_STATIC_CONSTANT( int, bit_count = Bits );
};
template < int BitsIncludingSign >
struct sized_integral< BitsIncludingSign, signed >
: detail::integral_rank_to_type<
detail::int_rank_helper<BitsIncludingSign>::rank, signed >
{
BOOST_STATIC_CONSTANT( int, bit_count = BitsIncludingSign );
};
template < int Bits >
struct sized_integral< Bits, unsigned >
: detail::integral_rank_to_type<
detail::uint_rank_helper<Bits>::rank, unsigned >
{
BOOST_STATIC_CONSTANT( int, bit_count = Bits );
};
// exact number of bits
template < int Bits, typename Signedness >
struct exact_integral
{
BOOST_STATIC_CONSTANT( bool, is_specialized = false );
BOOST_STATIC_CONSTANT( int, bit_count = Bits );
};
template < int BitsIncludingSign >
struct exact_integral< BitsIncludingSign, signed >
: detail::integral_rank_to_type<
detail::int_exact_rank_helper<BitsIncludingSign>::rank, signed >
{
BOOST_STATIC_CONSTANT( int, bit_count = BitsIncludingSign );
};
template < int Bits >
struct exact_integral< Bits, unsigned >
: detail::integral_rank_to_type<
detail::uint_exact_rank_helper<Bits>::rank, unsigned >
{
BOOST_STATIC_CONSTANT( int, bit_count = Bits );
};
// maximum supported (positive) value, signed
template < intmax_t MaxValue >
struct maximum_signed_integral
: detail::integral_rank_to_type<
detail::int_max_rank_helper<MaxValue>::rank, signed >
{
BOOST_STATIC_CONSTANT( intmax_t, bound = MaxValue );
};
// minimum supported (negative) value
template < intmax_t MinValue >
struct minimum_signed_integral
: detail::integral_rank_to_type<
detail::int_min_rank_helper<MinValue>::rank, signed >
{
BOOST_STATIC_CONSTANT( intmax_t, bound = MinValue );
};
// maximum supported (nonnegative) value, unsigned
template < uintmax_t Value >
struct maximum_unsigned_integral
: detail::integral_rank_to_type<
detail::uint_max_rank_helper<Value>::rank, unsigned >
{
BOOST_STATIC_CONSTANT( uintmax_t, bound = Value );
};
} // namespace detail
// integer templates specifying number of bits ---------------------------//
// signed
template< int Bits > // minimum bits (including sign) required
struct int_t
template< int Bits > // bits (including sign) required
struct int_t : public detail::exact_signed_base_helper<Bits>
{
typedef typename sized_integral<Bits, signed>::type least;
typedef typename int_fast_t<least>::fast fast;
};
template< int Bits > // exact bits (including sign) desired
struct int_exact_t
{
typedef typename exact_integral<Bits, signed>::type exact;
typedef typename detail::int_least_helper
<
#ifdef BOOST_HAS_LONG_LONG
(Bits <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +
#else
1 +
#endif
(Bits-1 <= ::std::numeric_limits<long>::digits) +
(Bits-1 <= ::std::numeric_limits<int>::digits) +
(Bits-1 <= ::std::numeric_limits<short>::digits) +
(Bits-1 <= ::std::numeric_limits<signed char>::digits)
>::least least;
typedef typename int_fast_t<least>::type fast;
};
// unsigned
template< int Bits > // minimum bits required
struct uint_t
template< int Bits > // bits required
struct uint_t : public detail::exact_unsigned_base_helper<Bits>
{
typedef typename sized_integral<Bits, unsigned>::type least;
typedef typename int_fast_t<least>::fast fast;
#if (defined(__BORLANDC__) || defined(__CODEGEAR__)) && defined(BOOST_NO_INTEGRAL_INT64_T)
// It's really not clear why this workaround should be needed... shrug I guess! JM
BOOST_STATIC_CONSTANT(int, s =
6 +
(Bits <= ::std::numeric_limits<unsigned long>::digits) +
(Bits <= ::std::numeric_limits<unsigned int>::digits) +
(Bits <= ::std::numeric_limits<unsigned short>::digits) +
(Bits <= ::std::numeric_limits<unsigned char>::digits));
typedef typename detail::int_least_helper< ::boost::uint_t<Bits>::s>::least least;
#else
typedef typename detail::int_least_helper
<
5 +
#ifdef BOOST_HAS_LONG_LONG
(Bits <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +
#else
1 +
#endif
(Bits <= ::std::numeric_limits<unsigned long>::digits) +
(Bits <= ::std::numeric_limits<unsigned int>::digits) +
(Bits <= ::std::numeric_limits<unsigned short>::digits) +
(Bits <= ::std::numeric_limits<unsigned char>::digits)
>::least least;
#endif
typedef typename int_fast_t<least>::type fast;
// int_fast_t<> works correctly for unsigned too, in spite of the name.
};
template< int Bits > // exact bits desired
struct uint_exact_t
{
typedef typename exact_integral<Bits, unsigned>::type exact;
};
// integer templates specifying extreme value ----------------------------//
// signed
template< intmax_t MaxValue > // maximum value to require support
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
template< boost::long_long_type MaxValue > // maximum value to require support
#else
template< long MaxValue > // maximum value to require support
#endif
struct int_max_value_t
{
typedef typename maximum_signed_integral<MaxValue>::type least;
typedef typename int_fast_t<least>::fast fast;
typedef typename detail::int_least_helper
<
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
(MaxValue <= ::boost::integer_traits<boost::long_long_type>::const_max) +
#else
1 +
#endif
(MaxValue <= ::boost::integer_traits<long>::const_max) +
(MaxValue <= ::boost::integer_traits<int>::const_max) +
(MaxValue <= ::boost::integer_traits<short>::const_max) +
(MaxValue <= ::boost::integer_traits<signed char>::const_max)
>::least least;
typedef typename int_fast_t<least>::type fast;
};
template< intmax_t MinValue > // minimum value to require support
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
template< boost::long_long_type MinValue > // minimum value to require support
#else
template< long MinValue > // minimum value to require support
#endif
struct int_min_value_t
{
typedef typename minimum_signed_integral<MinValue>::type least;
typedef typename int_fast_t<least>::fast fast;
typedef typename detail::int_least_helper
<
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
(MinValue >= ::boost::integer_traits<boost::long_long_type>::const_min) +
#else
1 +
#endif
(MinValue >= ::boost::integer_traits<long>::const_min) +
(MinValue >= ::boost::integer_traits<int>::const_min) +
(MinValue >= ::boost::integer_traits<short>::const_min) +
(MinValue >= ::boost::integer_traits<signed char>::const_min)
>::least least;
typedef typename int_fast_t<least>::type fast;
};
// unsigned
template< uintmax_t Value > // maximum value to require support
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
template< boost::ulong_long_type MaxValue > // minimum value to require support
#else
template< unsigned long MaxValue > // minimum value to require support
#endif
struct uint_value_t
{
typedef typename maximum_unsigned_integral<Value>::type least;
typedef typename int_fast_t<least>::fast fast;
#if (defined(__BORLANDC__) || defined(__CODEGEAR__))
// It's really not clear why this workaround should be needed... shrug I guess! JM
#if defined(BOOST_NO_INTEGRAL_INT64_T)
BOOST_STATIC_CONSTANT(unsigned, which =
6 +
(MaxValue <= ::boost::integer_traits<unsigned long>::const_max) +
(MaxValue <= ::boost::integer_traits<unsigned int>::const_max) +
(MaxValue <= ::boost::integer_traits<unsigned short>::const_max) +
(MaxValue <= ::boost::integer_traits<unsigned char>::const_max));
typedef typename detail::int_least_helper< ::boost::uint_value_t<MaxValue>::which>::least least;
#else // BOOST_NO_INTEGRAL_INT64_T
BOOST_STATIC_CONSTANT(unsigned, which =
5 +
(MaxValue <= ::boost::integer_traits<boost::ulong_long_type>::const_max) +
(MaxValue <= ::boost::integer_traits<unsigned long>::const_max) +
(MaxValue <= ::boost::integer_traits<unsigned int>::const_max) +
(MaxValue <= ::boost::integer_traits<unsigned short>::const_max) +
(MaxValue <= ::boost::integer_traits<unsigned char>::const_max));
typedef typename detail::int_least_helper< ::boost::uint_value_t<MaxValue>::which>::least least;
#endif // BOOST_NO_INTEGRAL_INT64_T
#else
typedef typename detail::int_least_helper
<
5 +
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
(MaxValue <= ::boost::integer_traits<boost::ulong_long_type>::const_max) +
#else
1 +
#endif
(MaxValue <= ::boost::integer_traits<unsigned long>::const_max) +
(MaxValue <= ::boost::integer_traits<unsigned int>::const_max) +
(MaxValue <= ::boost::integer_traits<unsigned short>::const_max) +
(MaxValue <= ::boost::integer_traits<unsigned char>::const_max)
>::least least;
#endif
typedef typename int_fast_t<least>::type fast;
};

View File

@ -12,192 +12,114 @@
#include <boost/integer_fwd.hpp> // self include
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
#include <boost/cstdint.hpp> // for boost::uintmax_t
#include <boost/integer.hpp> // for boost::sized_integral
#include <boost/limits.hpp> // for std::numeric_limits
#include <boost/mpl/and.hpp> // for boost::mpl::and_
#include <boost/mpl/bitwise.hpp> // for boost::mpl::bitor_, shift_left
#include <boost/mpl/bool.hpp> // for boost::mpl::true_
#include <boost/mpl/comparison.hpp> // for boost::mpl::greater_equal, etc.
#include <boost/mpl/empty_base.hpp> // for boost::mpl::empty_base
#include <boost/mpl/if.hpp> // for boost::mpl::if_
#include <boost/mpl/int.hpp> // for boost::mpl::int_
#include <boost/mpl/integral_c.hpp> // for boost::integral_c
#include <boost/mpl/next_prior.hpp> // for boost::mpl::next, prior
#include <boost/utility/enable_if.hpp> // for boost::enable_if
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
#include <boost/integer.hpp> // for boost::uint_t
#include <climits> // for UCHAR_MAX, etc.
#include <cstddef> // for std::size_t
#include <boost/limits.hpp> // for std::numeric_limits
//
// We simply cannot include this header on gcc without getting copious warnings of the kind:
//
// boost/integer/integer_mask.hpp:93:35: warning: use of C99 long long integer constant
//
// And yet there is no other reasonable implementation, so we declare this a system header
// to suppress these warnings.
//
#if defined(__GNUC__) && (__GNUC__ >= 4)
#pragma GCC system_header
#endif
namespace boost
{
namespace detail
{
// Helper templates --------------------------------------------------------//
template < int Bits >
struct hi_integer_mask_builder1
{
typedef boost::mpl::int_<Bits> bit_count_type;
typedef typename boost::mpl::next<bit_count_type>::type
mask_length_type;
typedef boost::sized_integral<mask_length_type::value, unsigned>
mask_type;
typedef boost::mpl::integral_c<typename mask_type::type, 1> one_type;
typedef boost::mpl::shift_left<one_type, bit_count_type> result_type;
};
template < int Bits >
struct hi_integer_mask_builder2
{
typedef boost::mpl::int_<Bits> bit_count_type;
typedef boost::mpl::greater_equal< bit_count_type, boost::mpl::int_<0> >
lo_bound_type;
typedef boost::mpl::less< bit_count_type,
boost::mpl::int_<std::numeric_limits<boost::uintmax_t>::digits> >
hi_bound_type;
typedef boost::mpl::and_<lo_bound_type, hi_bound_type> count_valid_type;
};
template < int Bits, class Enable = void >
struct hi_integer_mask_builder3
{
BOOST_STATIC_CONSTANT( bool, is_specialized = false );
};
template < int Bits >
struct hi_integer_mask_builder3< Bits, typename boost::enable_if<typename
hi_integer_mask_builder2<Bits>::count_valid_type>::type >
: hi_integer_mask_builder1<Bits>::result_type
{
BOOST_STATIC_CONSTANT( bool, is_specialized = true );
};
template < int Bits >
struct lo_integer_mask_builder1
{
typedef boost::mpl::int_<Bits> bit_count_type;
typedef typename boost::mpl::prior<bit_count_type>::type
shift_length_type;
typedef boost::sized_integral<bit_count_type::value, unsigned>
mask_type;
typedef boost::mpl::integral_c<typename mask_type::type, 1> one_type;
typedef boost::mpl::shift_left<one_type, shift_length_type>
high_bit_type;
typedef typename boost::mpl::prior<high_bit_type>::type low_bits_type;
typedef boost::mpl::bitor_<high_bit_type, low_bits_type> result_type;
};
template < >
struct lo_integer_mask_builder1< 0 >
{
// Let's not deal with negative interim values....
typedef boost::mpl::integral_c<unsigned char, 0u> result_type;
};
template < int Bits >
struct lo_integer_mask_builder2
{
typedef boost::mpl::int_<Bits> bit_count_type;
typedef boost::mpl::greater_equal< bit_count_type, boost::mpl::int_<0> >
lo_bound_type;
typedef boost::mpl::less_equal< bit_count_type,
boost::mpl::int_<std::numeric_limits<boost::uintmax_t>::digits> >
hi_bound_type;
typedef boost::mpl::and_<lo_bound_type, hi_bound_type> count_valid_type;
};
template < >
struct lo_integer_mask_builder2< 0 >
{
typedef boost::mpl::true_ count_valid_type;
};
template < int Bits, class Enable = void >
struct lo_integer_mask_builder3
{
BOOST_STATIC_CONSTANT( bool, is_specialized = false );
// No MPL Integral Constant to inherit from
};
template < int Bits >
struct lo_integer_mask_builder3< Bits, typename enable_if<typename
lo_integer_mask_builder2<Bits>::count_valid_type>::type >
: lo_integer_mask_builder1<Bits>::result_type
{
BOOST_STATIC_CONSTANT( bool, is_specialized = true );
};
} // namespace detail
// MPL-compatible integer mask class templates -----------------------------//
// Displaced single-bit mask, 1 << Offset, 0 <= Offset < BitLengthOf(uintmax_t)
template < int Offset >
struct integer_hi_mask
: detail::hi_integer_mask_builder3<Offset>
{
BOOST_STATIC_CONSTANT( int, bit_offset = Offset );
};
// Lowest bit-group mask, 2**Length - 1, 0 <= Length <= BitLengthOf(uintmax_t)
template < int Length >
struct integer_lo_mask
: detail::lo_integer_mask_builder3<Length>
{
BOOST_STATIC_CONSTANT( int, bit_count = Length );
};
// Specified single-bit mask class declaration -----------------------------//
// (Lowest bit starts counting at 0.)
template < std::size_t Bit >
class high_bit_mask_t
struct high_bit_mask_t
{
typedef integer_hi_mask<Bit> impl_type;
typedef typename uint_t<(Bit + 1)>::least least;
typedef typename uint_t<(Bit + 1)>::fast fast;
public:
typedef typename impl_type::value_type least;
typedef typename int_fast_t<least>::fast fast;
BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << Bit) );
BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << Bit) );
BOOST_STATIC_CONSTANT( least, high_bit = impl_type::value );
BOOST_STATIC_CONSTANT( fast, high_bit_fast = impl_type::value );
BOOST_STATIC_CONSTANT( std::size_t, bit_position = impl_type::bit_offset );
BOOST_STATIC_CONSTANT( std::size_t, bit_position = Bit );
}; // boost::high_bit_mask_t
// Specified bit-block mask class declaration ------------------------------//
// Makes masks for the lowest N bits
// (Specializations are needed when N fills up a type.)
template < std::size_t Bits >
class low_bits_mask_t
struct low_bits_mask_t
{
typedef integer_lo_mask<Bits> impl_type;
typedef typename uint_t<Bits>::least least;
typedef typename uint_t<Bits>::fast fast;
public:
typedef typename impl_type::value_type least;
typedef typename int_fast_t<least>::fast fast;
BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) );
BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) );
BOOST_STATIC_CONSTANT( least, sig_bits = impl_type::value );
BOOST_STATIC_CONSTANT( fast, sig_bits_fast = impl_type::value );
BOOST_STATIC_CONSTANT( std::size_t, bit_count = impl_type::bit_count );
BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits );
}; // boost::low_bits_mask_t
#define BOOST_LOW_BITS_MASK_SPECIALIZE( Type ) \
template < > struct low_bits_mask_t< std::numeric_limits<Type>::digits > { \
typedef std::numeric_limits<Type> limits_type; \
typedef uint_t<limits_type::digits>::least least; \
typedef uint_t<limits_type::digits>::fast fast; \
BOOST_STATIC_CONSTANT( least, sig_bits = (~( least(0u) )) ); \
BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); \
BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits ); \
}
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4245) // 'initializing' : conversion from 'int' to 'const boost::low_bits_mask_t<8>::least', signed/unsigned mismatch
#endif
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char );
#if USHRT_MAX > UCHAR_MAX
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned short );
#endif
#if UINT_MAX > USHRT_MAX
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int );
#endif
#if ULONG_MAX > UINT_MAX
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long );
#endif
#if defined(BOOST_HAS_LONG_LONG)
#if ((defined(ULLONG_MAX) && (ULLONG_MAX > ULONG_MAX)) ||\
(defined(ULONG_LONG_MAX) && (ULONG_LONG_MAX > ULONG_MAX)) ||\
(defined(ULONGLONG_MAX) && (ULONGLONG_MAX > ULONG_MAX)) ||\
(defined(_ULLONG_MAX) && (_ULLONG_MAX > ULONG_MAX)))
BOOST_LOW_BITS_MASK_SPECIALIZE( boost::ulong_long_type );
#endif
#elif defined(BOOST_HAS_MS_INT64)
#if 18446744073709551615ui64 > ULONG_MAX
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned __int64 );
#endif
#endif
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#undef BOOST_LOW_BITS_MASK_SPECIALIZE
} // namespace boost

View File

@ -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,14 +41,13 @@ 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 {
enum { c = (argument_type(1) << n << n) != 0 };
BOOST_STATIC_CONSTANT(bool, c = (argument_type(1) << n << n) != 0);
BOOST_STATIC_CONSTANT(
result_type,
value = !c*n + choose_initial_n<2*c*n>::value
@ -85,7 +84,7 @@ namespace boost {
template <argument_type x, result_type n = initial_n>
struct static_log2_impl {
enum { c = (x >> n) > 0 }; // x >= 2**n ?
BOOST_STATIC_CONSTANT(bool, c = (x >> n) > 0); // x >= 2**n ?
BOOST_STATIC_CONSTANT(
result_type,
value = c*n + (static_log2_impl< (x>>c*n), n/2 >::value)
@ -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 {

View File

@ -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 );
};

View File

@ -9,29 +9,33 @@
#ifndef BOOST_INTEGER_FWD_HPP
#define BOOST_INTEGER_FWD_HPP
#include <climits> // for UCHAR_MAX, etc.
#include <cstddef> // for std::size_t
#include <boost/config.hpp> // for BOOST_NO_INTRINSIC_WCHAR_T, etc.
#include <boost/cstdint.hpp> // for boost::uintmax_t, intmax_t
#include <boost/detail/extended_integer.hpp> // for BOOST_HAS_XINT, etc.
#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> ------------------------------------------------//
// Only has typedefs or using statements, with #conditionals
// ALERT: the forward declarations of items in <boost/integer.hpp> need items
// from this header. That means that <boost/cstdint.hpp> cannot #include this
// forwarding header, to avoid infinite recursion! One day, maybe
// boost::uintmax_t and boost::intmax_t could be segregated into their own
// header file (which can't #include this header), <boost/integer.hpp> will use
// that header, and <boost/cstdint.hpp> could refer to <boost/integer.hpp>.
// From <boost/integer_traits.hpp> -----------------------------------------//
@ -73,99 +77,87 @@ template < >
template < >
class integer_traits< unsigned long >;
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && BOOST_HAS_XINT
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && defined(BOOST_HAS_LONG_LONG)
template < >
class integer_traits< ::boost::detail::xint_t >;
class integer_traits< ::boost::long_long_type>;
template < >
class integer_traits< ::boost::detail::uxint_t >;
class integer_traits< ::boost::ulong_long_type >;
#elif !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && defined(BOOST_HAS_MS_INT64)
template < >
class integer_traits<__int64>;
template < >
class integer_traits<unsigned __int64>;
#endif
// From <boost/integer.hpp> ------------------------------------------------//
template < typename BaseInt >
struct fast_integral;
template < typename LeastInt >
struct int_fast_t;
template < int Bits, typename Signedness >
struct sized_integral;
template < int Bits, typename Signedness >
struct exact_integral;
template < intmax_t MaxValue >
struct maximum_signed_integral;
template < intmax_t MinValue >
struct minimum_signed_integral;
template < uintmax_t Value >
struct maximum_unsigned_integral;
template< int Bits >
struct int_t;
template< int Bits >
struct int_exact_t;
template< int Bits >
struct uint_t;
template< int Bits >
struct uint_exact_t;
template< intmax_t MaxValue >
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
template< boost::long_long_type MaxValue > // maximum value to require support
#else
template< long MaxValue > // maximum value to require support
#endif
struct int_max_value_t;
template< intmax_t MinValue >
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
template< boost::long_long_type MinValue > // minimum value to require support
#else
template< long MinValue > // minimum value to require support
#endif
struct int_min_value_t;
template< uintmax_t Value >
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
template< boost::ulong_long_type MaxValue > // maximum value to require support
#else
template< unsigned long MaxValue > // maximum value to require support
#endif
struct uint_value_t;
// From <boost/integer/integer_mask.hpp> -----------------------------------//
template < int Offset >
struct integer_hi_mask;
template < int Length >
struct integer_lo_mask;
template < std::size_t Bit >
class high_bit_mask_t;
struct high_bit_mask_t;
template < std::size_t Bits >
class low_bits_mask_t;
struct low_bits_mask_t;
template < >
struct low_bits_mask_t< ::std::numeric_limits<unsigned char>::digits >;
// 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

View File

@ -27,8 +27,17 @@
#include <wchar.h>
#endif
#include <boost/detail/extended_integer.hpp> // for BOOST_HAS_XINT, etc.
//
// We simply cannot include this header on gcc without getting copious warnings of the kind:
//
// ../../../boost/integer_traits.hpp:164:66: warning: use of C99 long long integer constant
//
// And yet there is no other reasonable implementation, so we declare this a system header
// to suppress these warnings.
//
#if defined(__GNUC__) && (__GNUC__ >= 4)
#pragma GCC system_header
#endif
namespace boost {
template<class T>
@ -157,18 +166,91 @@ class integer_traits<unsigned long>
public detail::integer_traits_base<unsigned long, 0, ULONG_MAX>
{ };
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && BOOST_HAS_XINT
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T)
#if defined(ULLONG_MAX) && defined(BOOST_HAS_LONG_LONG)
template<>
class integer_traits< detail::xint_t >
: public std::numeric_limits< detail::xint_t >,
public detail::integer_traits_base< detail::xint_t, BOOST_XINT_MIN, BOOST_XINT_MAX >
class integer_traits< ::boost::long_long_type>
: public std::numeric_limits< ::boost::long_long_type>,
public detail::integer_traits_base< ::boost::long_long_type, LLONG_MIN, LLONG_MAX>
{ };
template<>
class integer_traits< detail::uxint_t >
: public std::numeric_limits< detail::uxint_t >,
public detail::integer_traits_base< detail::uxint_t, 0u, BOOST_UXINT_MAX >
class integer_traits< ::boost::ulong_long_type>
: public std::numeric_limits< ::boost::ulong_long_type>,
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULLONG_MAX>
{ };
#elif defined(ULONG_LONG_MAX) && defined(BOOST_HAS_LONG_LONG)
template<>
class integer_traits< ::boost::long_long_type> : public std::numeric_limits< ::boost::long_long_type>, public detail::integer_traits_base< ::boost::long_long_type, LONG_LONG_MIN, LONG_LONG_MAX>{ };
template<>
class integer_traits< ::boost::ulong_long_type>
: public std::numeric_limits< ::boost::ulong_long_type>,
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONG_LONG_MAX>
{ };
#elif defined(ULONGLONG_MAX) && defined(BOOST_HAS_LONG_LONG)
template<>
class integer_traits< ::boost::long_long_type>
: public std::numeric_limits< ::boost::long_long_type>,
public detail::integer_traits_base< ::boost::long_long_type, LONGLONG_MIN, LONGLONG_MAX>
{ };
template<>
class integer_traits< ::boost::ulong_long_type>
: public std::numeric_limits< ::boost::ulong_long_type>,
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONGLONG_MAX>
{ };
#elif defined(_LLONG_MAX) && defined(_C2) && defined(BOOST_HAS_LONG_LONG)
template<>
class integer_traits< ::boost::long_long_type>
: public std::numeric_limits< ::boost::long_long_type>,
public detail::integer_traits_base< ::boost::long_long_type, -_LLONG_MAX - _C2, _LLONG_MAX>
{ };
template<>
class integer_traits< ::boost::ulong_long_type>
: public std::numeric_limits< ::boost::ulong_long_type>,
public detail::integer_traits_base< ::boost::ulong_long_type, 0, _ULLONG_MAX>
{ };
#elif defined(BOOST_HAS_LONG_LONG)
//
// we have long long but no constants, this happens for example with gcc in -ansi mode,
// we'll just have to work out the values for ourselves (assumes 2's compliment representation):
//
template<>
class integer_traits< ::boost::long_long_type>
: public std::numeric_limits< ::boost::long_long_type>,
public detail::integer_traits_base< ::boost::long_long_type, (1LL << (sizeof(::boost::long_long_type) * CHAR_BIT - 1)), ~(1LL << (sizeof(::boost::long_long_type) * CHAR_BIT - 1))>
{ };
template<>
class integer_traits< ::boost::ulong_long_type>
: public std::numeric_limits< ::boost::ulong_long_type>,
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ~0uLL>
{ };
#elif defined(BOOST_HAS_MS_INT64)
template<>
class integer_traits< __int64>
: public std::numeric_limits< __int64>,
public detail::integer_traits_base< __int64, _I64_MIN, _I64_MAX>
{ };
template<>
class integer_traits< unsigned __int64>
: public std::numeric_limits< unsigned __int64>,
public detail::integer_traits_base< unsigned __int64, 0, _UI64_MAX>
{ };
#endif
#endif
} // namespace boost

View File

@ -1,133 +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">&lt;boost/integer_fwd.hpp&gt;</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">&lt;boost/cstdint.hpp&gt;<br>
</a></code><a href="cstdint.htm"><br>
documentation</a>
</td>
<td valign="top">Typedef's based on the 1999 C Standard header &lt;<code>stdint.h&gt;</code>, wrapped in namespace boost.
This implementation may #include the compiler
supplied &lt;<code>stdint.h&gt;</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 &lt;<code>stdint.h&gt;</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">&lt;boost/integer_traits.hpp&gt;</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>.&nbsp;
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">&lt;boost/integer.hpp&gt;</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">&lt;boost/integer/integer_mask.hpp&gt;</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">&lt;boost/integer/static_log2.hpp&gt;</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">&lt;boost/integer/static_min_max.hpp&gt;</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>&lt;stdint.h&gt;</cite> types from the 1999 C
standard without resorting to undefined behavior in terms of the 1998
C++ standard. The header <cite>&lt;boost/cstdint.hpp&gt;</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>&lt;stdint.h&gt;</cite> and <cite>&lt;cstdint&gt;</cite>,
then <cite>&lt;boost/cstdint.hpp&gt;</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>&lt;limits.h&gt;</cite> macro names may possibly be visible to
users of <cite>&lt;boost/cstdint.hpp&gt;</cite>. Don't use these
macros; they are not part of any Boost-specified interface. Use
<code>boost::integer_traits&lt;&gt;</code> or
<code>std::numeric_limits&lt;&gt;</code> instead.</p>
<p>As another implementation artifact, certain C
<cite>&lt;stdint.h&gt;</cite> typedef names may possibly be visible in
the global namespace to users of <cite>&lt;boost/cstdint.hpp&gt;</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>
<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><EFBFBD> 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>

View File

@ -1,505 +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">&lt;boost/integer.hpp&gt;</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">Processor-Optimized Types</a></li>
<li><a href="#sized">Sized Types</a></li>
<li><a href="#mpl">MPL-Compatible Variants</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>
#include &lt;<a href="../../boost/integer_fwd.hpp">boost/integer_fwd.hpp</a>&gt; // forwarding header
#include &lt;<a href="cstdint.htm">boost/cstdint.hpp</a>&gt; // for boost::uintmax_t, intmax_t
namespace boost
{
// fast integers from least integers
template&lt; typename BaseInt &gt;
struct fast_integral
{
typedef <em>implementation_supplied</em> type;
};
template&lt; typename LeastInt &gt;
struct int_fast_t
{
typedef typename fast_integral&lt;LeastInt&gt;::type fast;
};
// MPL-compatible
template&lt; int Bits, typename Signedness &gt;
struct sized_integral
{
static bool const is_specialized = <em>implementation_supplied</em>;
static bool const is_signed = <em>implementation_supplied</em>;
static int const bit_count = Bits;
typedef <em>implementation_supplied</em> type;
};
template&lt; int Bits, typename Signedness &gt;
struct exact_integral
{
static bool const is_specialized = <em>implementation_supplied</em>;
static bool const is_signed = <em>implementation_supplied</em>;
static int const bit_count = Bits;
typedef <em>implementation_supplied</em> type;
};
template&lt; intmax_t MaxValue &gt;
struct maximum_signed_integral
{
static bool const is_specialized = <em>implementation_supplied</em>;
static bool const is_signed = true;
static intmax_t const bound = MaxValue;
typedef <em>implementation_supplied</em> type;
};
template&lt; intmax_t MinValue &gt;
struct minimum_signed_integral
{
static bool const is_specialized = <em>implementation_supplied</em>;
static bool const is_signed = true;
static intmax_t const bound = MinValue;
typedef <em>implementation_supplied</em> type;
};
template&lt; uintmax_t Value &gt;
struct maximum_unsigned_integral
{
static bool const is_specialized = <em>implementation_supplied</em>;
static bool const is_signed = false;
static uintmax_t const bound = Value;
typedef <em>implementation_supplied</em> type;
};
// signed
template&lt; int Bits &gt;
struct int_t
{
typedef typename sized_integral&lt;Bits, signed&gt;::type least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
template&lt; int Bits &gt;
struct int_exact_t
{
typedef typename exact_integral&lt;Bits, signed&gt;::type exact;
};
// unsigned
template&lt; int Bits &gt;
struct uint_t
{
typedef typename sized_integral&lt;Bits, unsigned&gt;::type least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
template&lt; int Bits &gt;
struct uint_exact_t
{
typedef typename exact_integral&lt;Bits, unsigned&gt;::type exact;
};
// signed
template&lt; intmax_t MaxValue &gt;
struct int_max_value_t
{
typedef typename maximum_signed_integral&lt;MaxValue&gt;::type least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
template&lt; intmax_t MinValue &gt;
struct int_min_value_t
{
typedef typename minimum_signed_integral&lt;MinValue&gt;::type least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
// unsigned
template&lt; uintmax_t Value &gt;
struct uint_value_t
{
typedef typename maximum_unsigned_integral&lt;Value&gt;::type least;
typedef int_fast_t&lt;least&gt;::fast fast;
};
} // namespace boost
</pre></blockquote>
<h2><a name="easy">Processor-Optimized Types</a></h2>
<p>The <code>fast_integral</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, can be any built-in
integral type besides <code>bool</code>. The output type is given as the class
member <code>type</code>.</p>
<p>The <code>int_fast_t</code> class template is the classic meta-function for
this operation. Despite the name, it works for unsigned integral types just
like it works for the signed integral types. The output type is given as the
class member <code>fast</code>, defined to be the same as the corresponding
result from the <code>fast_integral</code> meta-function.</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>int_exact_t</code>, <code>uint_t</code>,
<code>uint_exact_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 appropriate built-in integral type for the given template parameter.
This type is given by the class member <code>least</code> or <code>exact</code>.
For the non-exact class templates, 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="2" cellpadding="5">
<caption>Criteria for the Sized Type Class Templates</caption>
<tr>
<th>Class Template (all in name-space <code>boost</code>)</th>
<th>Template Parameter Mapping</th>
</tr>
<tr>
<td><code>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
<em>must</em> be a positive number. A compile-time error results if
the parameter is larger than the number of bits in a
<code>boost::intmax_t</code>.</td>
</tr>
<tr>
<td><code>int_exact_t</code></td>
<td>The smallest built-in signed integral type with exactly the
given number of bits, including the sign bit. A compile-time error
results if no qualifying type exists.</td>
</tr>
<tr>
<td><code>uint_t</code></td>
<td>The smallest built-in unsigned integral type with at least
the given number of bits. The parameter <em>must</em> be a
non-negative number. A compile-time error results if the parameter
is larger than the number of bits in a
<code>boost::uintmax_t</code>.</td>
</tr>
<tr>
<td><code>uint_exact_t</code></td>
<td>The smallest built-in unsigned integral type with exactly the given
number of bits. A compile-time error results if no qualifying type
exists.</td>
</tr>
<tr>
<td><code>int_max_value_t</code></td>
<td>The smallest built-in signed integral type that supports the
given value as a maximum. The parameter <em>must</em> be a
positive number.</td>
</tr>
<tr>
<td><code>int_min_value_t</code></td>
<td>The smallest built-in signed integral type that supports the
given value as a minimum. The parameter <em>must</em> be a
negative number.</td>
</tr>
<tr>
<td><code>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="mpl">MPL-Compatible Variants</a></h2>
<p>The bit-length sized-type class templates have several drawbacks:</p>
<ul>
<li>You must know the valid bit-lengths in advance.</li>
<li>There is no way to inspect the parameter used after a size-type template
class is aliased.</li>
<li>Using an inappropriate parameter value results in a compiler
diagnostic.</li>
<li>The type names used are inconsistent with other transformations in
Boost, like in <a href="../mpl/">MPL</a>.</li>
<li>The above two facts make use of the size-type class templates
incompatible with template meta-programming techniques.</li>
</ul>
<p>The <code>sized_integral</code>, <code>exact_integral</code>,
<code>maximum_signed_integral</code>, <code>minimum_signed_integral</code>, and
<code>maximum_unsigned_integral</code> class templates provide MPL-compatible
alternatives. These alternatives generally have the form:</p>
<blockquote><pre>
template&lt; <var>SwitchType</var> <var>SwitchValue</var>, typename Signedness &gt;
struct <var>name</var>
{
static bool const is_specialized = <em>implementation_supplied</em>;
static bool const is_signed = <em>implementation_supplied</em>;
static <var>SwitchType</var> const <var>switch_id</var> = <var>SwitchValue</var>;
typedef <em>implementation_supplied</em> type;
};
</pre></blockquote>
<p>Each member, if present, is defined by:</p>
<table border="2" cellpadding="5">
<caption>Members in MPL-Compatible Class Templates</caption>
<tr>
<th>Class Template Member</th>
<th>When Defined</th>
<th>Meaning</th>
</tr>
<tr>
<td><code>is_specialized</code></td>
<td>Always</td>
<td>Flag indicating when a particular template class instantiation is a
valid meta-function (<code>true</code>) or not (<code>false</code>).</td>
</tr>
<tr>
<td><code>is_signed</code></td>
<td><code>is_specialized == true</code></td>
<td>Flag indicating whether the signed-variant (<code>true</code>) or
the unsigned-variant (<code>false</code>) of the meta-function is
used. This is controlled by the <code>Signedness</code> template
parameter:
<table border="1" cellpadding="3" align="center">
<caption>Effect of <code>Signedness</code> Setting</caption>
<tr>
<th><code>Signedness</code> Type</th>
<th><code>is_signed</code></th>
</tr>
<tr>
<td><code>signed</code></td>
<td><code>true</code></td>
</tr>
<tr>
<td><code>unsigned</code></td>
<td><code>false</code></td>
</tr>
<tr>
<td>anything else</td>
<td><em>not defined</em></td>
</tr>
</table>
The type used is a programmer mnemonic; the compiler cannot prevent
someone from using <code>int</code> or <code>signed int</code>
instead of <code>signed</code>, or <code>unsigned int</code> instead
of <code>unsigned</code>.</td>
</tr>
<tr>
<td><code><var>switch_id</var></code> (Actual name is template-specific.)</td>
<td>Always</td>
<td>The value of the main control parameter, accessible even if the
template class instantiation is aliased.</td>
</tr>
<tr>
<td><code>type</code></td>
<td><code>is_specialized == true</code></td>
<td>The meta-function's result. It appears only if the input parameters
satisfy the template's requirements. Its presence, or lack thereof,
enables &quot;Substitution Failure Is Not An Error&quot; (SFINAE)
techniques, instead of a hard compiler diagnostic.</td>
</tr>
</table>
<p>The exceptions are the extreme-value class templates
(<code>maximum_signed_integral</code>, <code>minimum_signed_integral</code>, and
<code>maximum_unsigned_integral</code>), which do not take a <var>Signedness</var>
template parameter because the meta-functions already inherently have signedness.
<p>The following table describes each template's criteria. The classic signed
and unsigned equivalents are the sized-type class templates that each
MPL-compatible class template emulates. (The setting of <var>Signedness</var>
controls the appropriate emulation.)</p>
<table border="2" cellpadding="5">
<caption>Criteria for the MPL-Compatible Class Templates</caption>
<tr>
<th rowspan="2">Class Template (all in name-space <code>boost</code>)</th>
<th rowspan="2">Parameter Type (in name-space <code>boost</code> as needed)</th>
<th rowspan="2">Parameter Member ID</th>
<th colspan="2">Classic Equivalent</th>
<th rowspan="2" colspan="2">Template Parameter Mapping (when <code>type</code> is defined)</th>
</tr>
<tr>
<th>Signed</th>
<th>Unsigned</th>
</tr>
<tr>
<td><code>sized_integral</code></td>
<td><code>int</code></td>
<td><code>bit_count</code></td>
<td><code>int_t</code></td>
<td><code>uint_t</code></td>
<td colspan="2">The smallest built-in integral type with at least
<code>bit_count</code> bits (including the sign bit when
<var>Signedness</var> is <code>signed</code>). Not present if no
type qualifies.</td>
</tr>
<tr>
<td><code>exact_integral</code></td>
<td><code>int</code></td>
<td><code>bit_count</code></td>
<td><code>int_exact_t</code></td>
<td><code>uint_exact_t</code></td>
<td colspan="2">The smallest built-in integral type with exactly
<code>bit_count</code> bits (including the sign bit when
<var>Signedness</var> is <code>signed</code>). Not present if no
type qualifies.</td>
</tr>
<tr>
<td><code>maximum_signed_integral</code></td>
<td><code>intmax_t</code></td>
<td><code>bound</code></td>
<td colspan="2"><code>int_max_value_t</code></td>
<td>The smallest built-in integral type that can perserve the value in
<code>bound</code>. Not present if <code>bound</code> is non-positive.</td>
<td rowspan="3">It is possible for a <code>type</code> to be absent if
a platform supports really-extended integral types (beyond <code>long
long</code> or <code>__int64</code>), support for those types goes
into &lt;<a href="../../boost/cstdint.hpp">boost/cstdint.hpp</a>&gt;,
but said support hadn't yet been added to &lt;<a
href="../../boost/integer.hpp">boost/integer.hpp</a>&gt;</td>
</tr>
<tr>
<td><code>minimum_signed_integral</code></td>
<td><code>intmax_t</code></td>
<td><code>bound</code></td>
<td colspan="2"><code>int_min_value_t</code></td>
<td>The smallest built-in integral type that can perserve the value in
<code>bound</code>. Not present if <code>bound</code> is non-negative.</td>
</tr>
<tr>
<td><code>maximum_unsigned_integral</code></td>
<td><code>uintmax_t</code></td>
<td><code>bound</code></td>
<td colspan="2"><code>uint_value_t</code></td>
<td>The smallest built-in integral type that can perserve the value in
<code>bound</code>. Should always be present.</td>
</tr>
</table>
<h2><a name="example">Example</a></h2>
<blockquote><pre>
#include &lt;<a href="../../boost/integer.hpp">boost/integer.hpp</a>&gt;
#include &lt;<a href="../../boost/mpl/int.hpp">boost/mpl/int.hpp</a>&gt;
#include &lt;iostream&gt;
#include &lt;ostream&gt;
//...
template &lt; int Bits &gt;
bool
fit_exactly( boost::mpl::int_&lt;Bits&gt; const &amp;x,
typename boost::exact_integral&lt;Bits, signed&gt;::type *unused = 0 )
{
return true;
}
template &lt; typename T &gt;
bool
fit_exactly( T const &amp;x )
{
return false;
}
//...
int main()
{
typedef boost::mpl::int_&lt;24&gt; twenty_four;
boost::int_t&lt;twenty_four::value&gt;::least my_var;
//...
std::cout &lt;&lt; &quot;my_var &quot; &lt;&lt; ( fit_exactly(twenty_four()) ? &quot;does&quot; :
&quot;does not&quot; ) &lt;&lt; &quot; fit its type exactly.&quot; &lt;&lt; std::endl;
//...
}
</pre></blockquote>
<h2><a name="demo">Demonstration Program</a></h2>
<p>The program <a href="test/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">&lt;boost/cstdint.hpp&gt;</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
exact and value-based sized templates, and the MPL-compatible templates.</p>
<hr>
<p>Revised July 16, 2008</p>
<p>&copy; 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 &lt;<a
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>&gt;.)</p>
</body>
</html>

View File

@ -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 &lt;limits&gt; header supplies a class template
numeric_limits&lt;&gt; with specializations for each fundamental
type.</p>
<p>
For integer types, the interesting members of std::numeric_limits&lt;&gt; 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&lt;class T&gt;
class integer_traits : public std::numeric_limits&lt;T&gt;
{
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&lt;T&gt;::min()</code></td></tr>
<tr><td><code>const_max</code></td><td><code>T</code></td><td>equivalent
to <code>std::numeric_limits&lt;T&gt;::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&lt;&gt;::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="test/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><EFBFBD> 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>

View File

@ -4,17 +4,22 @@
import testing ;
project : requirements <warnings>all <toolset>gcc:<cxxflags>-Wextra ;
test-suite integer
: [ run cstdint_test.cpp ]
[ run integer_test.cpp
/boost/test//boost_unit_test_framework ]
[ run integer_traits_test.cpp
/boost/test//boost_test_exec_monitor/<link>static ]
[ run integer_mask_test.cpp
/boost/test//boost_unit_test_framework ]
[ run static_log2_test.cpp
/boost/test//boost_test_exec_monitor/<link>static ]
[ run static_min_max_test.cpp
/boost/test//boost_test_exec_monitor/<link>static ]
[ compile issue_2134.cpp ]
:
[ run cstdint_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-long-long <toolset>darwin:<cxxflags>-Wno-long-long ]
[ run cstdint_test2.cpp : : : <toolset>gcc:<cxxflags>-Wno-long-long <toolset>darwin:<cxxflags>-Wno-long-long ]
[ run integer_traits_test.cpp ]
[ run integer_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-long-long <toolset>darwin:<cxxflags>-Wno-long-long <toolset>sun:<cxxflags>"-Qoption ccfe -tmpldepth=128" ]
[ run integer_mask_test.cpp ]
[ run static_log2_test.cpp ]
[ run static_min_max_test.cpp ]
[ compile cstdint_include_test.cpp ]
[ compile integer_traits_include_test.cpp ]
[ compile integer_include_test.cpp ]
[ compile integer_mask_include_test.cpp ]
[ compile static_log2_include_test.cpp ]
[ compile static_min_max_include_test.cpp ]
[ compile integer_fwd_include_test.cpp ]
;

View File

@ -0,0 +1,69 @@
// Copyright John Maddock 2009.
// 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)
#define __STDC_CONSTANT_MACROS
#include <boost/cstdint.hpp> // must be the only #include!
int main()
{
boost::int8_t i8 = INT8_C(0);
(void)i8;
boost::uint8_t ui8 = UINT8_C(0);
(void)ui8;
boost::int16_t i16 = INT16_C(0);
(void)i16;
boost::uint16_t ui16 = UINT16_C(0);
(void)ui16;
boost::int32_t i32 = INT32_C(0);
(void)i32;
boost::uint32_t ui32 = UINT32_C(0);
(void)ui32;
#ifndef BOOST_NO_INT64_T
boost::int64_t i64 = 0;
(void)i64;
boost::uint64_t ui64 = 0;
(void)ui64;
#endif
boost::int_least8_t i8least = INT8_C(0);
(void)i8least;
boost::uint_least8_t ui8least = UINT8_C(0);
(void)ui8least;
boost::int_least16_t i16least = INT16_C(0);
(void)i16least;
boost::uint_least16_t ui16least = UINT16_C(0);
(void)ui16least;
boost::int_least32_t i32least = INT32_C(0);
(void)i32least;
boost::uint_least32_t ui32least = UINT32_C(0);
(void)ui32least;
#ifndef BOOST_NO_INT64_T
boost::int_least64_t i64least = 0;
(void)i64least;
boost::uint_least64_t ui64least = 0;
(void)ui64least;
#endif
boost::int_fast8_t i8fast = INT8_C(0);
(void)i8fast;
boost::uint_fast8_t ui8fast = UINT8_C(0);
(void)ui8fast;
boost::int_fast16_t i16fast = INT16_C(0);
(void)i16fast;
boost::uint_fast16_t ui16fast = UINT16_C(0);
(void)ui16fast;
boost::int_fast32_t i32fast = INT32_C(0);
(void)i32fast;
boost::uint_fast32_t ui32fast = UINT32_C(0);
(void)ui32fast;
#ifndef BOOST_NO_INT64_T
boost::int_fast64_t i64fast = 0;
(void)i64fast;
boost::uint_fast64_t ui64fast = 0;
(void)ui64fast;
#endif
boost::intmax_t im = 0;
(void)im;
boost::uintmax_t uim = 0;
(void)uim;
}

View File

@ -12,18 +12,24 @@
// 12 Nov 00 Adapted to merged <boost/cstdint.hpp>
// 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock).
// 28 Jun 00 Initial version
#define __STDC_CONSTANT_MACROS
#include <cassert>
#include <iostream>
#include <boost/cstdint.hpp>
#ifdef NDEBUG
int main()
{
std::cout << "This test makes no sense with NDEBUG defined.\n";
return 0;
}
#else
//
// There are two ways to test this: in version 1, we include cstdint.hpp as the first
// include, which means we get decide whether __STDC_CONSTANT_MACROS is defined.
// In version two we include stdint.h with __STDC_CONSTANT_MACROS *NOT* defined first,
// and check that we still end up with compatible definitions for the INT#_C macros.
//
// This is version 1.
//
#if defined(__GNUC__) && (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))
// We can't suppress this warning on the command line as not all GCC versions support -Wno-type-limits :
#pragma GCC diagnostic ignored "-Wtype-limits"
#endif
#include <boost/cstdint.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <iostream>
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
//
@ -62,24 +68,24 @@ struct integral_constant_checker
void integral_constant_checker::check()
{
assert( int8 == -127 );
assert( int_least8 == -127 );
assert( int_fast8 == -127 );
assert( uint8 == 255u );
assert( uint_least8 == 255u );
assert( uint_fast8 == 255u );
assert( int16 == -32767 );
assert( int_least16 == -32767 );
assert( int_fast16 == -32767 );
assert( uint16 == 65535u );
assert( uint_least16 == 65535u );
assert( uint_fast16 == 65535u );
assert( int32 == -2147483647 );
assert( int_least32 == -2147483647 );
assert( int_fast32 == -2147483647 );
assert( uint32 == 4294967295u );
assert( uint_least32 == 4294967295u );
assert( uint_fast32 == 4294967295u );
BOOST_TEST( int8 == -127 );
BOOST_TEST( int_least8 == -127 );
BOOST_TEST( int_fast8 == -127 );
BOOST_TEST( uint8 == 255u );
BOOST_TEST( uint_least8 == 255u );
BOOST_TEST( uint_fast8 == 255u );
BOOST_TEST( int16 == -32767 );
BOOST_TEST( int_least16 == -32767 );
BOOST_TEST( int_fast16 == -32767 );
BOOST_TEST( uint16 == 65535u );
BOOST_TEST( uint_least16 == 65535u );
BOOST_TEST( uint_fast16 == 65535u );
BOOST_TEST( int32 == -2147483647 );
BOOST_TEST( int_least32 == -2147483647 );
BOOST_TEST( int_fast32 == -2147483647 );
BOOST_TEST( uint32 == 4294967295u );
BOOST_TEST( uint_least32 == 4294967295u );
BOOST_TEST( uint_fast32 == 4294967295u );
}
#endif // BOOST_NO_INCLASS_MEMBER_INITIALIZATION
@ -108,10 +114,10 @@ void integral_constant_type_check(T1, T2)
// if we have a native stdint.h
// then the INTXX_C macros may define
// a type that's wider than required:
assert(sizeof(T1) <= sizeof(T2));
BOOST_TEST(sizeof(T1) <= sizeof(T2));
#else
assert(sizeof(T1) == sizeof(T2));
assert(t1 == t2);
BOOST_TEST(sizeof(T1) == sizeof(T2));
BOOST_TEST(t1 == t2);
#endif
#if defined(BOOST_HAS_STDINT_H)
// native headers are permitted to promote small
@ -119,22 +125,22 @@ void integral_constant_type_check(T1, T2)
if(sizeof(T1) >= sizeof(int))
{
if(t1 > 0)
assert(t2 > 0);
BOOST_TEST(t2 > 0);
else
assert(!(t2 > 0));
BOOST_TEST(!(t2 > 0));
}
else if(t1 < 0)
assert(!(t2 > 0));
BOOST_TEST(!(t2 > 0));
#else
if(t1 > 0)
assert(t2 > 0);
BOOST_TEST(t2 > 0);
else
assert(!(t2 > 0));
BOOST_TEST(!(t2 > 0));
#endif
}
int main()
int main(int, char*[])
{
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
integral_constant_checker::check();
@ -193,41 +199,40 @@ int main()
boost::uintmax_t uintmax = UINTMAX_C(4294967295);
#endif
assert( int8 == -127 );
assert( int_least8 == -127 );
assert( int_fast8 == -127 );
assert( uint8 == 255u );
assert( uint_least8 == 255u );
assert( uint_fast8 == 255u );
assert( int16 == -32767 );
assert( int_least16 == -32767 );
assert( int_fast16 == -32767 );
assert( uint16 == 65535u );
assert( uint_least16 == 65535u );
assert( uint_fast16 == 65535u );
assert( int32 == -2147483647 );
assert( int_least32 == -2147483647 );
assert( int_fast32 == -2147483647 );
assert( uint32 == 4294967295u );
assert( uint_least32 == 4294967295u );
assert( uint_fast32 == 4294967295u );
BOOST_TEST( int8 == -127 );
BOOST_TEST( int_least8 == -127 );
BOOST_TEST( int_fast8 == -127 );
BOOST_TEST( uint8 == 255u );
BOOST_TEST( uint_least8 == 255u );
BOOST_TEST( uint_fast8 == 255u );
BOOST_TEST( int16 == -32767 );
BOOST_TEST( int_least16 == -32767 );
BOOST_TEST( int_fast16 == -32767 );
BOOST_TEST( uint16 == 65535u );
BOOST_TEST( uint_least16 == 65535u );
BOOST_TEST( uint_fast16 == 65535u );
BOOST_TEST( int32 == -2147483647 );
BOOST_TEST( int_least32 == -2147483647 );
BOOST_TEST( int_fast32 == -2147483647 );
BOOST_TEST( uint32 == 4294967295u );
BOOST_TEST( uint_least32 == 4294967295u );
BOOST_TEST( uint_fast32 == 4294967295u );
#ifndef BOOST_NO_INT64_T
assert( int64 == INT64_C(-9223372036854775807) );
assert( int_least64 == INT64_C(-9223372036854775807) );
assert( int_fast64 == INT64_C(-9223372036854775807) );
assert( uint64 == UINT64_C(18446744073709551615) );
assert( uint_least64 == UINT64_C(18446744073709551615) );
assert( uint_fast64 == UINT64_C(18446744073709551615) );
assert( intmax == INT64_C(-9223372036854775807) );
assert( uintmax == UINT64_C(18446744073709551615) );
BOOST_TEST( int64 == INT64_C(-9223372036854775807) );
BOOST_TEST( int_least64 == INT64_C(-9223372036854775807) );
BOOST_TEST( int_fast64 == INT64_C(-9223372036854775807) );
BOOST_TEST( uint64 == UINT64_C(18446744073709551615) );
BOOST_TEST( uint_least64 == UINT64_C(18446744073709551615) );
BOOST_TEST( uint_fast64 == UINT64_C(18446744073709551615) );
BOOST_TEST( intmax == INT64_C(-9223372036854775807) );
BOOST_TEST( uintmax == UINT64_C(18446744073709551615) );
#else
assert( intmax == -2147483647 );
assert( uintmax == 4294967295u );
BOOST_TEST( intmax == -2147483647 );
BOOST_TEST( uintmax == 4294967295u );
#endif
std::cout << "OK\n";
return 0;
return boost::report_errors();
}
#endif

248
test/cstdint_test2.cpp Normal file
View File

@ -0,0 +1,248 @@
// boost cstdint.hpp test program ------------------------------------------//
// Copyright Beman Dawes 2000. 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)
// See http://www.boost.org/libs/integer for documentation.
// Revision History
// 11 Sep 01 Adapted to work with macros defined in native stdint.h (John Maddock)
// 12 Nov 00 Adapted to merged <boost/cstdint.hpp>
// 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock).
// 28 Jun 00 Initial version
//
// There are two ways to test this: in version 1, we include cstdint.hpp as the first
// include, which means we get decide whether __STDC_CONSTANT_MACROS is defined.
// In version two we include stdint.h with __STDC_CONSTANT_MACROS *NOT* defined first,
// and check that we still end up with compatible definitions for the INT#_C macros.
//
// This is version 2.
//
#if defined(__GNUC__) && (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))
// We can't suppress this warning on the command line as not all GCC versions support -Wno-type-limits :
#pragma GCC diagnostic ignored "-Wtype-limits"
#endif
#include <boost/config.hpp>
#ifdef BOOST_HAS_STDINT_H
#ifdef __hpux
# include <inttypes.h>
#else
# include <stdint.h>
#endif
#endif
#include <boost/cstdint.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <iostream>
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
//
// the following class is designed to verify
// that the various INTXX_C macros can be used
// in integral constant expressions:
//
struct integral_constant_checker
{
static const boost::int8_t int8 = INT8_C(-127);
static const boost::int_least8_t int_least8 = INT8_C(-127);
static const boost::int_fast8_t int_fast8 = INT8_C(-127);
static const boost::uint8_t uint8 = UINT8_C(255);
static const boost::uint_least8_t uint_least8 = UINT8_C(255);
static const boost::uint_fast8_t uint_fast8 = UINT8_C(255);
static const boost::int16_t int16 = INT16_C(-32767);
static const boost::int_least16_t int_least16 = INT16_C(-32767);
static const boost::int_fast16_t int_fast16 = INT16_C(-32767);
static const boost::uint16_t uint16 = UINT16_C(65535);
static const boost::uint_least16_t uint_least16 = UINT16_C(65535);
static const boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
static const boost::int32_t int32 = INT32_C(-2147483647);
static const boost::int_least32_t int_least32 = INT32_C(-2147483647);
static const boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
static const boost::uint32_t uint32 = UINT32_C(4294967295);
static const boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
static const boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
static void check();
};
void integral_constant_checker::check()
{
BOOST_TEST( int8 == -127 );
BOOST_TEST( int_least8 == -127 );
BOOST_TEST( int_fast8 == -127 );
BOOST_TEST( uint8 == 255u );
BOOST_TEST( uint_least8 == 255u );
BOOST_TEST( uint_fast8 == 255u );
BOOST_TEST( int16 == -32767 );
BOOST_TEST( int_least16 == -32767 );
BOOST_TEST( int_fast16 == -32767 );
BOOST_TEST( uint16 == 65535u );
BOOST_TEST( uint_least16 == 65535u );
BOOST_TEST( uint_fast16 == 65535u );
BOOST_TEST( int32 == -2147483647 );
BOOST_TEST( int_least32 == -2147483647 );
BOOST_TEST( int_fast32 == -2147483647 );
BOOST_TEST( uint32 == 4294967295u );
BOOST_TEST( uint_least32 == 4294967295u );
BOOST_TEST( uint_fast32 == 4294967295u );
}
#endif // BOOST_NO_INCLASS_MEMBER_INITIALIZATION
//
// the following function simply verifies that the type
// of an integral constant is correctly defined:
//
#ifdef __BORLANDC__
#pragma option -w-8008
#pragma option -w-8066
#endif
template <class T1, class T2>
void integral_constant_type_check(T1, T2)
{
//
// the types T1 and T2 may not be exactly
// the same type, but they should be the
// same size and signedness. We could use
// numeric_limits to verify this, but
// numeric_limits implementations currently
// vary too much, or are incomplete or missing.
//
T1 t1 = static_cast<T1>(-1); // cast suppresses warnings
T2 t2 = static_cast<T2>(-1); // ditto
#if defined(BOOST_HAS_STDINT_H)
// if we have a native stdint.h
// then the INTXX_C macros may define
// a type that's wider than required:
BOOST_TEST(sizeof(T1) <= sizeof(T2));
#else
BOOST_TEST(sizeof(T1) == sizeof(T2));
BOOST_TEST(t1 == t2);
#endif
#if defined(BOOST_HAS_STDINT_H)
// native headers are permitted to promote small
// unsigned types to type int:
if(sizeof(T1) >= sizeof(int))
{
if(t1 > 0)
BOOST_TEST(t2 > 0);
else
BOOST_TEST(!(t2 > 0));
}
else if(t1 < 0)
BOOST_TEST(!(t2 > 0));
#else
if(t1 > 0)
BOOST_TEST(t2 > 0);
else
BOOST_TEST(!(t2 > 0));
#endif
}
int main(int, char*[])
{
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
integral_constant_checker::check();
#endif
//
// verify the types of the integral constants:
//
integral_constant_type_check(boost::int8_t(0), INT8_C(0));
integral_constant_type_check(boost::uint8_t(0), UINT8_C(0));
integral_constant_type_check(boost::int16_t(0), INT16_C(0));
integral_constant_type_check(boost::uint16_t(0), UINT16_C(0));
integral_constant_type_check(boost::int32_t(0), INT32_C(0));
integral_constant_type_check(boost::uint32_t(0), UINT32_C(0));
#ifndef BOOST_NO_INT64_T
integral_constant_type_check(boost::int64_t(0), INT64_C(0));
integral_constant_type_check(boost::uint64_t(0), UINT64_C(0));
#endif
//
boost::int8_t int8 = INT8_C(-127);
boost::int_least8_t int_least8 = INT8_C(-127);
boost::int_fast8_t int_fast8 = INT8_C(-127);
boost::uint8_t uint8 = UINT8_C(255);
boost::uint_least8_t uint_least8 = UINT8_C(255);
boost::uint_fast8_t uint_fast8 = UINT8_C(255);
boost::int16_t int16 = INT16_C(-32767);
boost::int_least16_t int_least16 = INT16_C(-32767);
boost::int_fast16_t int_fast16 = INT16_C(-32767);
boost::uint16_t uint16 = UINT16_C(65535);
boost::uint_least16_t uint_least16 = UINT16_C(65535);
boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
boost::int32_t int32 = INT32_C(-2147483647);
boost::int_least32_t int_least32 = INT32_C(-2147483647);
boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
boost::uint32_t uint32 = UINT32_C(4294967295);
boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
#ifndef BOOST_NO_INT64_T
boost::int64_t int64 = INT64_C(-9223372036854775807);
boost::int_least64_t int_least64 = INT64_C(-9223372036854775807);
boost::int_fast64_t int_fast64 = INT64_C(-9223372036854775807);
boost::uint64_t uint64 = UINT64_C(18446744073709551615);
boost::uint_least64_t uint_least64 = UINT64_C(18446744073709551615);
boost::uint_fast64_t uint_fast64 = UINT64_C(18446744073709551615);
boost::intmax_t intmax = INTMAX_C(-9223372036854775807);
boost::uintmax_t uintmax = UINTMAX_C(18446744073709551615);
#else
boost::intmax_t intmax = INTMAX_C(-2147483647);
boost::uintmax_t uintmax = UINTMAX_C(4294967295);
#endif
BOOST_TEST( int8 == -127 );
BOOST_TEST( int_least8 == -127 );
BOOST_TEST( int_fast8 == -127 );
BOOST_TEST( uint8 == 255u );
BOOST_TEST( uint_least8 == 255u );
BOOST_TEST( uint_fast8 == 255u );
BOOST_TEST( int16 == -32767 );
BOOST_TEST( int_least16 == -32767 );
BOOST_TEST( int_fast16 == -32767 );
BOOST_TEST( uint16 == 65535u );
BOOST_TEST( uint_least16 == 65535u );
BOOST_TEST( uint_fast16 == 65535u );
BOOST_TEST( int32 == -2147483647 );
BOOST_TEST( int_least32 == -2147483647 );
BOOST_TEST( int_fast32 == -2147483647 );
BOOST_TEST( uint32 == 4294967295u );
BOOST_TEST( uint_least32 == 4294967295u );
BOOST_TEST( uint_fast32 == 4294967295u );
#ifndef BOOST_NO_INT64_T
BOOST_TEST( int64 == INT64_C(-9223372036854775807) );
BOOST_TEST( int_least64 == INT64_C(-9223372036854775807) );
BOOST_TEST( int_fast64 == INT64_C(-9223372036854775807) );
BOOST_TEST( uint64 == UINT64_C(18446744073709551615) );
BOOST_TEST( uint_least64 == UINT64_C(18446744073709551615) );
BOOST_TEST( uint_fast64 == UINT64_C(18446744073709551615) );
BOOST_TEST( intmax == INT64_C(-9223372036854775807) );
BOOST_TEST( uintmax == UINT64_C(18446744073709551615) );
#else
BOOST_TEST( intmax == -2147483647 );
BOOST_TEST( uintmax == 4294967295u );
#endif
std::cout << "OK\n";
return boost::report_errors();
}

View File

@ -0,0 +1,22 @@
// Copyright John Maddock 2009.
// 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)
#include <boost/integer_fwd.hpp> // must be the only #include!
// just declare some functions that use the incomplete types in the header:
void f1(const boost::integer_traits<char>*);
void f2(const boost::int_fast_t<char>*);
void f3(const boost::int_t<12>*);
void f4(const boost::uint_t<31>*);
void f5(const boost::int_max_value_t<100>*);
void f6(const boost::int_min_value_t<-100>*);
void f7(const boost::uint_value_t<100>*);
void f8(const boost::high_bit_mask_t<10>*);
void f9(const boost::low_bits_mask_t<10>*);
void f10(boost::static_log2_argument_type, boost::static_log2_result_type, boost::static_log2<10>*);
void f11(boost::static_min_max_signed_type, boost::static_min_max_unsigned_type);
void f12(boost::static_signed_min<1, 2>*, boost::static_signed_max<1,2>*);
void f13(boost::static_unsigned_min<1,2>*, boost::static_unsigned_min<1,2>*);

View File

@ -0,0 +1,36 @@
// Copyright John Maddock 2009.
// 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)
#include <boost/integer.hpp> // must be the only #include!
int main()
{
boost::int_fast_t<char>::fast f = 0;
(void)f;
boost::int_t<16>::fast f2 = 0;
(void)f2;
boost::int_t<32>::exact e = 0;
(void)e;
boost::int_t<12>::least l = 0;
(void)l;
boost::uint_t<16>::fast uf2 = 0;
(void)uf2;
boost::uint_t<32>::exact ue = 0;
(void)ue;
boost::uint_t<12>::least ul = 0;
(void)ul;
boost::int_max_value_t<200>::fast v1 = 0;
(void)v1;
boost::int_max_value_t<2000>::least v2 = 0;
(void)v2;
boost::int_min_value_t<-200>::fast v3 = 0;
(void)v3;
boost::int_min_value_t<-2000>::least v4 = 0;
(void)v4;
boost::uint_value_t<200>::fast v5 = 0;
(void)v5;
boost::uint_value_t<2000>::least v6 = 0;
(void)v6;
}

View File

@ -0,0 +1,18 @@
// Copyright John Maddock 2009.
// 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)
#include <boost/integer/integer_mask.hpp> // must be the only #include!
int main()
{
boost::high_bit_mask_t<20>::least l = boost::high_bit_mask_t<20>::high_bit;
boost::high_bit_mask_t<12>::fast f = boost::high_bit_mask_t<12>::high_bit_fast;
l += f + boost::high_bit_mask_t<12>::bit_position;
(void)l;
boost::low_bits_mask_t<20>::least l2 = boost::low_bits_mask_t<20>::sig_bits;
boost::low_bits_mask_t<12>::fast f2 = boost::low_bits_mask_t<12>::sig_bits_fast;
l2 += f2 + boost::low_bits_mask_t<12>::bit_count;
(void)l2;
}

View File

@ -8,164 +8,196 @@
// See http://www.boost.org for most recent version including documentation.
// Revision History
// 29 Jul 2008 Added MPL-compatible variants of the integer-mask templates.
// (Daryle Walker)
// 27 Jul 2008 Changed tests to use the unit-test system; added
// extended-integer support. (Daryle Walker)
// 23 Sep 2001 Initial version (Daryle Walker)
#define BOOST_TEST_MODULE "Integer mask tests"
#include <boost/test/unit_test.hpp> // unit testing framework
#include <boost/detail/lightweight_test.hpp>
#include <boost/cstdint.hpp> // for boost::uintmax_t
#include <boost/cstdlib.hpp> // for boost::exit_success
#include <boost/integer/integer_mask.hpp> // for boost::high_bit_mask_t, etc.
#include <boost/limits.hpp> // for std::numeric_limits
#include <boost/mpl/assert.hpp> // for BOOST_MPL_ASSERT_RELATION,etc.
#include <boost/mpl/bool.hpp> // for boost::mpl::bool_
#include <boost/mpl/bitwise.hpp> // for boost::mpl::bitor_, shift_left
#include <boost/mpl/equal_to.hpp> // for boost::mpl::equal_to
#include <boost/mpl/int.hpp> // for boost::mpl::int_
#include <boost/mpl/integral_c.hpp> // for boost::mpl::integral_c
#include <boost/mpl/next_prior.hpp> // for boost::mpl::prior
#include <boost/mpl/range_c.hpp> // for boost::mpl::range_c
#include <cstddef> // for std::size_t
#include <ios> // for std::hex
#include <iostream> // for std::cout
#include <ostream> // for std::endl
#include <iostream> // for std::cout (std::endl indirectly)
// Control if events will be printed conventionally, or just logged.
#ifndef CONTROL_SHOW_TYPES
#define CONTROL_SHOW_TYPES 0
#ifdef BOOST_MSVC
#pragma warning(disable:4127) // conditional expression is constant
#endif
// Logging
#if CONTROL_SHOW_TYPES
#define PRIVATE_SHOW_MESSAGE( m ) std::cout << m << std::endl
#if defined(BOOST_HAS_LONG_LONG)
#define MASK_TYPE ::boost::ulong_long_type
#elif defined(BOOST_HAS_MS_INT64)
#define MASK_TYPE unsigned __int64
#else
#define PRIVATE_SHOW_MESSAGE( m ) BOOST_TEST_MESSAGE( m )
#define MASK_TYPE unsigned long
#endif
#define ONE (static_cast<MASK_TYPE>(1))
// Custom types/templates, helper functions, and objects
namespace
#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \
(v) >::high_bit == (ONE << (v)) );
#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \
(v) >::high_bit_fast == (ONE << (v)) );
#define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \
PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false)
#define PRIVATE_LOW_BITS_SLOW_TEST(v) \
do{ \
MASK_TYPE mask = 0;\
if(v > 0)\
{ mask = ((ONE << (v-1)) - 1); mask <<= 1; mask |= 1; }\
BOOST_TEST( ::boost::low_bits_mask_t< (v) >::sig_bits == mask); \
}while(false);
#define PRIVATE_LOW_BITS_FAST_TEST(v) \
do{ \
MASK_TYPE mask = 0;\
if(v > 0)\
{ mask = ((ONE << (v-1)) - 1); mask <<= 1; mask |= 1; }\
BOOST_TEST( ::boost::low_bits_mask_t< (v) >::sig_bits_fast == mask);\
}while(false);
#define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \
PRIVATE_LOW_BITS_FAST_TEST(v); } while (false)
int main( int, char*[] )
{
using std::cout;
using std::endl;
// List the ranges of template parameters tests (ranges are half-open)
int const max_offset = std::numeric_limits<boost::uintmax_t>::digits;
cout << "Doing high_bit_mask_t tests." << endl;
typedef boost::mpl::range_c<int, 0, max_offset> high_bit_offsets;
typedef boost::mpl::range_c<int, 0, max_offset + 1> low_bit_lengths;
typedef boost::mpl::range_c<int, 1, max_offset + 1> special_low_bit_lengths;
#if defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)
PRIVATE_HIGH_BIT_TEST( 63 );
PRIVATE_HIGH_BIT_TEST( 62 );
PRIVATE_HIGH_BIT_TEST( 61 );
PRIVATE_HIGH_BIT_TEST( 60 );
PRIVATE_HIGH_BIT_TEST( 59 );
PRIVATE_HIGH_BIT_TEST( 58 );
PRIVATE_HIGH_BIT_TEST( 57 );
PRIVATE_HIGH_BIT_TEST( 56 );
PRIVATE_HIGH_BIT_TEST( 55 );
PRIVATE_HIGH_BIT_TEST( 54 );
PRIVATE_HIGH_BIT_TEST( 53 );
PRIVATE_HIGH_BIT_TEST( 52 );
PRIVATE_HIGH_BIT_TEST( 51 );
PRIVATE_HIGH_BIT_TEST( 50 );
PRIVATE_HIGH_BIT_TEST( 49 );
PRIVATE_HIGH_BIT_TEST( 48 );
PRIVATE_HIGH_BIT_TEST( 47 );
PRIVATE_HIGH_BIT_TEST( 46 );
PRIVATE_HIGH_BIT_TEST( 45 );
PRIVATE_HIGH_BIT_TEST( 44 );
PRIVATE_HIGH_BIT_TEST( 43 );
PRIVATE_HIGH_BIT_TEST( 42 );
PRIVATE_HIGH_BIT_TEST( 41 );
PRIVATE_HIGH_BIT_TEST( 40 );
PRIVATE_HIGH_BIT_TEST( 39 );
PRIVATE_HIGH_BIT_TEST( 38 );
PRIVATE_HIGH_BIT_TEST( 37 );
PRIVATE_HIGH_BIT_TEST( 36 );
PRIVATE_HIGH_BIT_TEST( 35 );
PRIVATE_HIGH_BIT_TEST( 34 );
PRIVATE_HIGH_BIT_TEST( 33 );
PRIVATE_HIGH_BIT_TEST( 32 );
#endif
PRIVATE_HIGH_BIT_TEST( 31 );
PRIVATE_HIGH_BIT_TEST( 30 );
PRIVATE_HIGH_BIT_TEST( 29 );
PRIVATE_HIGH_BIT_TEST( 28 );
PRIVATE_HIGH_BIT_TEST( 27 );
PRIVATE_HIGH_BIT_TEST( 26 );
PRIVATE_HIGH_BIT_TEST( 25 );
PRIVATE_HIGH_BIT_TEST( 24 );
PRIVATE_HIGH_BIT_TEST( 23 );
PRIVATE_HIGH_BIT_TEST( 22 );
PRIVATE_HIGH_BIT_TEST( 21 );
PRIVATE_HIGH_BIT_TEST( 20 );
PRIVATE_HIGH_BIT_TEST( 19 );
PRIVATE_HIGH_BIT_TEST( 18 );
PRIVATE_HIGH_BIT_TEST( 17 );
PRIVATE_HIGH_BIT_TEST( 16 );
PRIVATE_HIGH_BIT_TEST( 15 );
PRIVATE_HIGH_BIT_TEST( 14 );
PRIVATE_HIGH_BIT_TEST( 13 );
PRIVATE_HIGH_BIT_TEST( 12 );
PRIVATE_HIGH_BIT_TEST( 11 );
PRIVATE_HIGH_BIT_TEST( 10 );
PRIVATE_HIGH_BIT_TEST( 9 );
PRIVATE_HIGH_BIT_TEST( 8 );
PRIVATE_HIGH_BIT_TEST( 7 );
PRIVATE_HIGH_BIT_TEST( 6 );
PRIVATE_HIGH_BIT_TEST( 5 );
PRIVATE_HIGH_BIT_TEST( 4 );
PRIVATE_HIGH_BIT_TEST( 3 );
PRIVATE_HIGH_BIT_TEST( 2 );
PRIVATE_HIGH_BIT_TEST( 1 );
PRIVATE_HIGH_BIT_TEST( 0 );
// List a range with out-of-service values
typedef boost::mpl::range_c<int, -10, max_offset + 11> wild_bit_lengths;
cout << "Doing low_bits_mask_t tests." << endl;
// Use SFINAE to check if a particular parameter is supported
template < typename ValueT, template<ValueT> class Tmpl, ValueT Value >
bool
print_out_template( Tmpl<Value> const &, ValueT setting, char const
*template_name, typename Tmpl<Value>::type *unused = 0 )
{
// Too bad the type-id expression couldn't use the compact form "*unused",
// but type-ids of dereferenced null pointers throw by order of C++ 2003,
// sect. 5.2.8, para. 2 (although the result is not conceptually needed).
PRIVATE_SHOW_MESSAGE( "There is an " << template_name << "<" << setting <<
"> specialization with type '" << typeid(typename
Tmpl<Value>::value_type).name() << "' and value '" << std::hex <<
Tmpl<Value>::value << "'." );
return true;
#if defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)
PRIVATE_LOW_BITS_TEST( 64 );
PRIVATE_LOW_BITS_TEST( 63 );
PRIVATE_LOW_BITS_TEST( 62 );
PRIVATE_LOW_BITS_TEST( 61 );
PRIVATE_LOW_BITS_TEST( 60 );
PRIVATE_LOW_BITS_TEST( 59 );
PRIVATE_LOW_BITS_TEST( 58 );
PRIVATE_LOW_BITS_TEST( 57 );
PRIVATE_LOW_BITS_TEST( 56 );
PRIVATE_LOW_BITS_TEST( 55 );
PRIVATE_LOW_BITS_TEST( 54 );
PRIVATE_LOW_BITS_TEST( 53 );
PRIVATE_LOW_BITS_TEST( 52 );
PRIVATE_LOW_BITS_TEST( 51 );
PRIVATE_LOW_BITS_TEST( 50 );
PRIVATE_LOW_BITS_TEST( 49 );
PRIVATE_LOW_BITS_TEST( 48 );
PRIVATE_LOW_BITS_TEST( 47 );
PRIVATE_LOW_BITS_TEST( 46 );
PRIVATE_LOW_BITS_TEST( 45 );
PRIVATE_LOW_BITS_TEST( 44 );
PRIVATE_LOW_BITS_TEST( 43 );
PRIVATE_LOW_BITS_TEST( 42 );
PRIVATE_LOW_BITS_TEST( 41 );
PRIVATE_LOW_BITS_TEST( 40 );
PRIVATE_LOW_BITS_TEST( 39 );
PRIVATE_LOW_BITS_TEST( 38 );
PRIVATE_LOW_BITS_TEST( 37 );
PRIVATE_LOW_BITS_TEST( 36 );
PRIVATE_LOW_BITS_TEST( 35 );
PRIVATE_LOW_BITS_TEST( 34 );
PRIVATE_LOW_BITS_TEST( 33 );
#endif
PRIVATE_LOW_BITS_TEST( 32 );
PRIVATE_LOW_BITS_TEST( 31 );
PRIVATE_LOW_BITS_TEST( 30 );
PRIVATE_LOW_BITS_TEST( 29 );
PRIVATE_LOW_BITS_TEST( 28 );
PRIVATE_LOW_BITS_TEST( 27 );
PRIVATE_LOW_BITS_TEST( 26 );
PRIVATE_LOW_BITS_TEST( 25 );
PRIVATE_LOW_BITS_TEST( 24 );
PRIVATE_LOW_BITS_TEST( 23 );
PRIVATE_LOW_BITS_TEST( 22 );
PRIVATE_LOW_BITS_TEST( 21 );
PRIVATE_LOW_BITS_TEST( 20 );
PRIVATE_LOW_BITS_TEST( 19 );
PRIVATE_LOW_BITS_TEST( 18 );
PRIVATE_LOW_BITS_TEST( 17 );
PRIVATE_LOW_BITS_TEST( 16 );
PRIVATE_LOW_BITS_TEST( 15 );
PRIVATE_LOW_BITS_TEST( 14 );
PRIVATE_LOW_BITS_TEST( 13 );
PRIVATE_LOW_BITS_TEST( 12 );
PRIVATE_LOW_BITS_TEST( 11 );
PRIVATE_LOW_BITS_TEST( 10 );
PRIVATE_LOW_BITS_TEST( 9 );
PRIVATE_LOW_BITS_TEST( 8 );
PRIVATE_LOW_BITS_TEST( 7 );
PRIVATE_LOW_BITS_TEST( 6 );
PRIVATE_LOW_BITS_TEST( 5 );
PRIVATE_LOW_BITS_TEST( 4 );
PRIVATE_LOW_BITS_TEST( 3 );
PRIVATE_LOW_BITS_TEST( 2 );
PRIVATE_LOW_BITS_TEST( 1 );
return boost::report_errors();
}
template < typename ValueT, typename T >
bool
print_out_template( T const &, ValueT setting, char const *template_name )
{
PRIVATE_SHOW_MESSAGE( "There is no " << template_name << "<" << setting <<
"> specialization." );
return false;
}
} // unnamed namespace
// Check the various integer-valued bit-masks
BOOST_AUTO_TEST_SUITE( integer_mask_tests )
// Check the bit-masks of one offset bit
BOOST_AUTO_TEST_CASE_TEMPLATE( high_bit_mask_test, T, high_bit_offsets )
{
typedef boost::mpl::integral_c<typename
boost::high_bit_mask_t<T::value>::least, 1u> one_type;
typedef boost::mpl::shift_left<one_type, T> result_type;
BOOST_MPL_ASSERT_RELATION( boost::high_bit_mask_t<T::value>::high_bit, ==,
result_type::value );
BOOST_MPL_ASSERT_RELATION( boost::high_bit_mask_t<T::value>::high_bit_fast,
==, result_type::value );
}
// Check the bit-masks of a block of low-valued bits, non-zero block-lengths
BOOST_AUTO_TEST_CASE_TEMPLATE( low_bits_mask_test, T, special_low_bit_lengths )
{
// One can express (2^x - 1) in two ways
// 1. (1 << x) - 1
// 2. (1 << (x-1)) | ((1 << (x-1)) - 1)
// Since unsigneds have modulo arithmetic, [1] gives the right answer even
// when x is the number of bits in the register. However, that last case
// gives warnings about the sole bit flowing past the register. Applying
// distributive property backwards gives [2], which works without overflow.
typedef typename boost::mpl::prior<T>::type shift_type;
typedef boost::mpl::integral_c<typename
boost::low_bits_mask_t<T::value>::least, 1u> one_type;
typedef boost::mpl::shift_left<one_type, shift_type> high_bit_type;
typedef typename boost::mpl::prior<high_bit_type>::type low_bits_type;
typedef boost::mpl::bitor_<high_bit_type, low_bits_type> result_type;
BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t<T::value>::sig_bits, ==,
result_type::value );
BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t<T::value>::sig_bits_fast,
==, result_type::value );
}
// Check the bit-masks of a block of low-valued bits, zero block-length
BOOST_AUTO_TEST_CASE( special_low_bits_mask_test )
{
// Just like "low_bits_mask_test" above, except that the shifts are negative
// when the bit-count is zero. That causes a lot of warnings and errors, so
// special-case that bit-count.
BOOST_MPL_ASSERT_RELATION( boost::low_bits_mask_t<0u>::sig_bits, ==, 0 );
BOOST_MPL_ASSERT_RELATION(boost::low_bits_mask_t<0u>::sig_bits_fast, ==, 0);
}
// Check the specialization type status of given bit-offsets/lengths
BOOST_AUTO_TEST_CASE_TEMPLATE( confirm_bounds_test, T, wild_bit_lengths )
{
typedef boost::integer_hi_mask<T::value> hi_type;
typedef boost::mpl::int_<hi_type::bit_offset> hi_offset_type;
typedef boost::mpl::bool_<hi_type::is_specialized> special_hi_type;
BOOST_MPL_ASSERT( (boost::mpl::equal_to< hi_offset_type, T >) );
BOOST_MPL_ASSERT( (boost::mpl::equal_to< special_hi_type,
boost::mpl::bool_<(T::value >= 0) && (T::value < max_offset)> >) );
BOOST_CHECK_EQUAL( print_out_template(hi_type(), hi_offset_type::value,
"integer_hi_mask"), special_hi_type::value );
typedef boost::integer_lo_mask<T::value> lo_type;
typedef boost::mpl::int_<lo_type::bit_count> lo_length_type;
typedef boost::mpl::bool_<lo_type::is_specialized> special_lo_type;
BOOST_MPL_ASSERT( (boost::mpl::equal_to< lo_length_type, T >) );
BOOST_MPL_ASSERT( (boost::mpl::equal_to< special_lo_type,
boost::mpl::bool_<(T::value >= 0) && (T::value <= max_offset)> >) );
BOOST_CHECK_EQUAL( print_out_template(lo_type(), lo_length_type::value,
"integer_lo_mask"), special_lo_type::value );
}
BOOST_AUTO_TEST_SUITE_END()
// Verification of bugs and their fixes
BOOST_AUTO_TEST_SUITE( bug_fix_tests )
BOOST_AUTO_TEST_SUITE_END()

View File

@ -1,685 +1,263 @@
// boost integer.hpp test program ------------------------------------------//
// Copyright Beman Dawes 1999. Distributed under the Boost
// Copyright Beman Dawes 1999.
// Copyright Daryle Walker 2001.
// Copyright John Maddock 2009.
// 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)
// See http://www.boost.org/libs/integer for documentation.
// Revision History
// 16 Jul 08 Added MPL-compatible variants of the minimum-size and value-
// based integer templates. (Daryle Walker)
// 15 Jul 08 Added exact-integer templates; added MPL-compatible variant of
// processor-optimized integer template. (Daryle Walker)
// 14 Jul 08 Improved testing of processor-optimized integer template; added
// extended-integer support. (Daryle Walker)
// 13 Jul 08 Modernized tests w/ MPL instead of giant macros (Daryle Walker)
// 07 Jul 08 Changed tests to use the unit-test system (Daryle Walker)
// 04 Oct 01 Added tests for new templates; rewrote code (Daryle Walker)
// 10 Mar 01 Boost Test Library now used for tests (Beman Dawes)
// 31 Aug 99 Initial version
#define BOOST_TEST_MODULE "Integer size-selection tests"
#include <boost/detail/lightweight_test.hpp> // for main, BOOST_TEST
#include <boost/integer.hpp> // for boost::int_t, boost::uint_t
#include <boost/type_traits/is_same.hpp>
#include <boost/test/unit_test.hpp> // unit testing framework
#include <climits> // for ULONG_MAX, LONG_MAX, LONG_MIN
#include <iostream> // for std::cout (std::endl indirectly)
#include <typeinfo> // for std::type_info
#include <boost/config.hpp> // for BOOST_NO_SFINAE
#include <boost/cstdint.hpp> // for boost::uintmax_t, intmax_t
#include <boost/integer.hpp> // for boost::int_t, boost::uint_t, etc.
#include <boost/integer_traits.hpp> // for boost::integer_traits
#include <boost/limits.hpp> // for std::numeric_limits
#include <boost/detail/extended_integer.hpp> // BOOST_HAS_XINT, BOOST_UXINT_MAX
#include <boost/mpl/arithmetic.hpp> // for boost::mpl::plus, divides
#include <boost/mpl/assert.hpp> // for BOOST_MPL_ASSERT_RELATION, etc.
#include <boost/mpl/back.hpp> // for boost::mpl::back
#include <boost/mpl/copy.hpp> // for boost::mpl::copy
#include <boost/mpl/equal.hpp> // for boost::mpl::equal
#include <boost/mpl/front_inserter.hpp> // for boost::mpl::front_inserter
#include <boost/mpl/int.hpp> // for boost::mpl::int_
#include <boost/mpl/integral_c.hpp> // for boost::mpl::integral_c
#include <boost/mpl/joint_view.hpp> // for boost::mpl::joint_view
#include <boost/mpl/pop_back.hpp> // for boost::mpl::pop_back
#include <boost/mpl/push_back.hpp> // for boost::mpl::push_back
#include <boost/mpl/push_front.hpp> // for boost::mpl::push_front
#include <boost/mpl/range_c.hpp> // for boost::mpl::range_c
#include <boost/mpl/shift_right.hpp> // for boost::mpl::shift_right
#include <boost/mpl/sort.hpp> // for boost::mpl::sort
#include <boost/mpl/transform.hpp> // for boost::mpl::transform
#include <boost/mpl/transform_view.hpp> // for boost::mpl::transform_view
#include <boost/mpl/unpack_args.hpp> // for boost::mpl::unpack_args
#include <boost/mpl/vector.hpp> // for boost::mpl::vector
#include <boost/mpl/zip_view.hpp> // for boost::mpl::zip_view
#include <boost/type_traits/is_same.hpp> // for boost::is_same
#include <boost/type_traits/make_signed.hpp> // for boost::make_signed
#include <algorithm> // for std::binary_search
#include <climits> // for ULONG_MAX, LONG_MAX, LONG_MIN, etc.
#include <cstddef> // for std::size_t
#include <iostream> // for std::cout
#include <ostream> // for std::endl
#include <typeinfo> // for std::type_info
// Control what the "fast" specialization of "short" is
#ifndef CONTROL_FAST_SHORT
#define CONTROL_FAST_SHORT long
#ifdef BOOST_MSVC
#pragma warning(disable:4127) // conditional expression is constant
#endif
#if defined( __BORLANDC__ )
# pragma option -w-8008 -w-8066 // condition is always true
#endif
// Control if the names of the types for each version
// of the integer templates will be printed.
#ifndef CONTROL_SHOW_TYPES
#define CONTROL_SHOW_TYPES 0
//
// Keep track of error count, so we can print out detailed
// info only if we need it:
//
int last_error_count = 0;
//
// Helpers to print out the name of a type,
// we use these as typeid(X).name() doesn't always
// return a human readable string:
//
template <class T> const char* get_name_of_type(T){ return typeid(T).name(); }
const char* get_name_of_type(signed char){ return "signed char"; }
const char* get_name_of_type(unsigned char){ return "unsigned char"; }
const char* get_name_of_type(short){ return "short"; }
const char* get_name_of_type(unsigned short){ return "unsigned short"; }
const char* get_name_of_type(int){ return "int"; }
const char* get_name_of_type(unsigned int){ return "unsigned int"; }
const char* get_name_of_type(long){ return "long"; }
const char* get_name_of_type(unsigned long){ return "unsigned long"; }
#ifdef BOOST_HAS_LONG_LONG
const char* get_name_of_type(boost::long_long_type){ return "boost::long_long_type"; }
const char* get_name_of_type(boost::ulong_long_type){ return "boost::ulong_long_type"; }
#endif
// Control if every potential bit-count is used, or only a selection
// For me, full counts increase compile time from 90 seconds to 20 minutes!
#ifndef CONTROL_FULL_COUNTS
#define CONTROL_FULL_COUNTS 1
#endif
// If specializations have not already been done, then we can confirm
// the effects of the fast types by making a specialization. If there
// is a specialization for "short," make sure that CONTROL_FAST_SHORT
// is set to a type distinct from "short" and the default implementation.
namespace boost
template <int Bits>
void do_test_exact(boost::mpl::true_ const&)
{
template < >
struct fast_integral< short >
{
typedef CONTROL_FAST_SHORT type;
};
// Test the ::exact member:
typedef typename boost::int_t<Bits>::exact int_exact;
typedef typename boost::uint_t<Bits>::exact uint_exact;
typedef typename boost::int_t<Bits>::least least_int;
typedef typename boost::uint_t<Bits>::least least_uint;
BOOST_TEST((boost::is_same<int_exact, least_int>::value));
BOOST_TEST((boost::is_same<uint_exact, least_uint>::value));
}
template <int Bits>
void do_test_exact(boost::mpl::false_ const&)
{
// Nothing to do, type does not have an ::extact member.
}
// Logging
#if CONTROL_SHOW_TYPES
#define PRIVATE_SHOW_MESSAGE( m ) std::cout << m << std::endl
#else
#define PRIVATE_SHOW_MESSAGE( m ) BOOST_TEST_MESSAGE( m )
#endif
// Custom types/templates, helper functions, and objects
namespace
template <int Bits>
void do_test_bits()
{
//
// Recurse to next smallest number of bits:
//
do_test_bits<Bits - 1>();
//
// Test exact types if we have them:
//
do_test_exact<Bits>(
boost::mpl::bool_<
(sizeof(unsigned char) * CHAR_BIT == Bits)
|| (sizeof(unsigned short) * CHAR_BIT == Bits)
|| (sizeof(unsigned int) * CHAR_BIT == Bits)
|| (sizeof(unsigned long) * CHAR_BIT == Bits)
#ifdef BOOST_HAS_LONG_LONG
|| (sizeof(boost::ulong_long_type) * CHAR_BIT == Bits)
#endif
>());
//
// We need to check all aspects of the members of int_t<Bits> and uint_t<Bits>:
//
typedef typename boost::int_t<Bits>::least least_int;
typedef typename boost::int_t<Bits>::least fast_int;
typedef typename boost::uint_t<Bits>::least least_uint;
typedef typename boost::uint_t<Bits>::fast fast_uint;
// List the built-in integral types, excluding the ones that are strong-typedefs
// of a lower type.
typedef boost::mpl::vector<
unsigned char
#if USHRT_MAX > UCHAR_MAX
, unsigned short
#endif
#if UINT_MAX > USHRT_MAX
, unsigned int
#endif
#if ULONG_MAX > UINT_MAX
, unsigned long
#endif
#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX)
, boost::detail::uxint_t
#endif
> distinct_unsigned_types;
if(std::numeric_limits<least_int>::is_specialized)
{
BOOST_TEST(std::numeric_limits<least_int>::digits + 1 >= Bits);
}
if(std::numeric_limits<least_uint>::is_specialized)
{
BOOST_TEST(std::numeric_limits<least_uint>::digits >= Bits);
}
BOOST_TEST(sizeof(least_int) * CHAR_BIT >= Bits);
BOOST_TEST(sizeof(least_uint) * CHAR_BIT >= Bits);
BOOST_TEST(sizeof(fast_int) >= sizeof(least_int));
BOOST_TEST(sizeof(fast_uint) >= sizeof(least_uint));
//
// There should be no type smaller than least_* that also has enough bits:
//
if(!boost::is_same<signed char, least_int>::value)
{
BOOST_TEST(std::numeric_limits<signed char>::digits < Bits);
if(!boost::is_same<short, least_int>::value)
{
BOOST_TEST(std::numeric_limits<short>::digits < Bits);
if(!boost::is_same<int, least_int>::value)
{
BOOST_TEST(std::numeric_limits<int>::digits < Bits);
if(!boost::is_same<long, least_int>::value)
{
BOOST_TEST(std::numeric_limits<long>::digits < Bits);
}
}
}
}
// And again, but unsigned:
if(!boost::is_same<unsigned char, least_uint>::value)
{
BOOST_TEST(std::numeric_limits<unsigned char>::digits < Bits);
if(!boost::is_same<unsigned short, least_uint>::value)
{
BOOST_TEST(std::numeric_limits<unsigned short>::digits < Bits);
if(!boost::is_same<unsigned int, least_uint>::value)
{
BOOST_TEST(std::numeric_limits<unsigned int>::digits < Bits);
if(!boost::is_same<unsigned long, least_uint>::value)
{
BOOST_TEST(std::numeric_limits<unsigned long>::digits < Bits);
}
}
}
}
typedef boost::mpl::transform<
distinct_unsigned_types,
boost::make_signed< boost::mpl::_1 >
>::type distinct_signed_types;
// List the digit counts for each integral type
template < typename T >
struct digits_of
: boost::mpl::int_< std::numeric_limits<T>::digits >
if(boost::detail::test_errors() != last_error_count)
{
last_error_count = boost::detail::test_errors();
std::cout << "Errors occurred while testing with bit count = " << Bits << std::endl;
std::cout << "Type int_t<" << Bits << ">::least was " << get_name_of_type(least_int(0)) << std::endl;
std::cout << "Type int_t<" << Bits << ">::fast was " << get_name_of_type(fast_int(0)) << std::endl;
std::cout << "Type uint_t<" << Bits << ">::least was " << get_name_of_type(least_uint(0)) << std::endl;
std::cout << "Type uint_t<" << Bits << ">::fast was " << get_name_of_type(fast_uint(0)) << std::endl;
}
}
template <>
void do_test_bits<-1>()
{
};
typedef boost::mpl::transform<
distinct_unsigned_types,
digits_of< boost::mpl::_1 >
>::type distinct_integral_bit_counts;
// Make list of bit counts between each offical point, plus CHAR_BIT/2
typedef boost::mpl::transform_view<
boost::mpl::zip_view<
boost::mpl::vector<
boost::mpl::push_front<
boost::mpl::pop_back< distinct_integral_bit_counts >::type,
boost::mpl::integral_c< int, 0 >
>::type,
distinct_integral_bit_counts
>
>,
boost::mpl::unpack_args<
boost::mpl::divides<
boost::mpl::plus< boost::mpl::_1, boost::mpl::_2 >,
boost::mpl::integral_c< int, 2 >
>
>
> median_bit_counts;
// Maximum number of bits allowed
typedef std::numeric_limits<boost:: intmax_t> intmax_limits;
typedef std::numeric_limits<boost::uintmax_t> uintmax_limits;
int const intmax_bits = intmax_limits::digits + 1;
int const uintmax_bits = uintmax_limits::digits;
// Make master lists including an outlier beyond all valid bit counts
#if CONTROL_FULL_COUNTS
typedef boost::mpl::range_c<int, 0, uintmax_bits + 2> bits_list;
#else
typedef boost::mpl::sort<
boost::mpl::copy<
boost::mpl::joint_view<
distinct_integral_bit_counts,
median_bit_counts
>,
boost::mpl::front_inserter<
boost::mpl::vector<
boost::mpl::integral_c<int, uintmax_bits + 1>
>
>
>::type
>::type bits_list;
#endif
// Remove the outlier when all bits counts must be valid
#if CONTROL_FULL_COUNTS
typedef boost::mpl::range_c<int, 0, uintmax_bits + 1> valid_bits_list;
#else
typedef boost::mpl::pop_back<bits_list>::type valid_bits_list;
#endif
// Replace the minimum bit count with one more, so right-shifting by a stored
// value doesn't give an invalid result
#if CONTROL_FULL_COUNTS
typedef boost::mpl::range_c<int, 1, uintmax_bits + 1>
valid_to_decrease_bits_list;
#else
typedef valid_bits_list valid_to_decrease_bits_list;
#endif
// Replace the maximum bit count with one less, so left-shifting by a stored
// value doesn't give an invalid result
#if CONTROL_FULL_COUNTS
typedef boost::mpl::range_c<int, 0, uintmax_bits> valid_to_increase_ubits_list;
#else
typedef boost::mpl::push_back<
boost::mpl::pop_back< valid_bits_list >::type,
boost::mpl::integral_c< int, uintmax_bits - 1 >
>::type valid_to_increase_ubits_list;
#endif
// Do it again for signed types since they have one-less bit to use for the
// mantissa (don't want to shift into the sign bit)
#if CONTROL_FULL_COUNTS
typedef boost::mpl::range_c<int, 0, intmax_bits - 2>
valid_to_increase_sbits_list;
#else
typedef boost::mpl::push_back<
boost::mpl::pop_back< valid_bits_list >::type,
boost::mpl::integral_c< int, intmax_bits - 3 >
>::type valid_to_increase_sbits_list;
#endif
// List the digit counts for each integral type, this time as an object, an
// array working as a sorted list
int const integral_bit_lengths[] = {
std::numeric_limits< unsigned char >::digits
#if USHRT_MAX > UCHAR_MAX
, std::numeric_limits< unsigned short >::digits
#endif
#if UINT_MAX > USHRT_MAX
, std::numeric_limits< unsigned int >::digits
#endif
#if ULONG_MAX > UINT_MAX
, std::numeric_limits< unsigned long >::digits
#endif
#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX)
, std::numeric_limits< boost::detail::uxint_t >::digits
#endif
};
std::size_t const integral_type_count = sizeof(integral_bit_lengths) /
sizeof(integral_bit_lengths[0]);
// "Template-typedefs" to reduce two-argument templates to single-argument.
// This way, all the MPL-compatible templates have the same form, for below.
template < int Bits >
struct signed_sized_integral : boost::sized_integral<Bits, signed> {};
template < int Bits >
struct unsigned_sized_integral : boost::sized_integral<Bits, unsigned> {};
template < int Bits >
struct signed_exact_integral : boost::exact_integral<Bits, signed> {};
template < int Bits >
struct unsigned_exact_integral : boost::exact_integral<Bits, unsigned> {};
// Use SFINAE to check if a particular parameter is supported
#ifndef BOOST_NO_SFINAE
template < typename ValueT, template<ValueT> class Tmpl, ValueT Value >
bool
print_out_template( Tmpl<Value> const &, ValueT setting, char const
*template_pre_name, char const *template_post_name, typename Tmpl<Value>::type
*unused = 0 )
{
// Too bad the type-id expression couldn't use the compact form "*unused",
// but type-ids of dereferenced null pointers throw by order of C++ 2003,
// sect. 5.2.8, para. 2 (although the result is not conceptually needed).
PRIVATE_SHOW_MESSAGE( "This is " << template_pre_name << setting
<< template_post_name << " specialization, with type '" << typeid(typename
Tmpl<Value>::type).name() << "'." );
return true;
// Nothing to do here!!
}
template < typename ValueT, typename T >
bool
print_out_template( T const &, ValueT setting, char const *template_pre_name,
char const *template_post_name )
template <class Traits, class Expected>
void test_min_max_type(Expected val)
{
PRIVATE_SHOW_MESSAGE( "Looking for " << template_pre_name << setting
<< template_post_name << " specialization? It doesn't exist." );
return false;
typedef typename Traits::least least_type;
typedef typename Traits::fast fast_type;
BOOST_TEST((boost::is_same<least_type, Expected>::value));
BOOST_TEST(sizeof(fast_type) >= sizeof(least_type));
BOOST_TEST((std::numeric_limits<least_type>::min)() <= val);
BOOST_TEST((std::numeric_limits<least_type>::max)() >= val);
if(boost::detail::test_errors() != last_error_count)
{
last_error_count = boost::detail::test_errors();
std::cout << "Traits type is: " << typeid(Traits).name() << std::endl;
std::cout << "Least type is: " << get_name_of_type(least_type(0)) << std::endl;
std::cout << "Fast type is: " << get_name_of_type(fast_type(0)) << std::endl;
std::cout << "Expected type is: " << get_name_of_type(Expected(0)) << std::endl;
std::cout << "Required value is: " << val << std::endl;
}
}
#else
#error "These tests cannot work without Substitution-Failure-Is-Not-An-Error"
// Test program
int main(int, char*[])
{
// Test int_t and unint_t first:
if(std::numeric_limits<boost::intmax_t>::is_specialized)
do_test_bits<std::numeric_limits<boost::uintmax_t>::digits>();
else
do_test_bits<std::numeric_limits<long>::digits>();
//
// Test min and max value types:
//
test_min_max_type<boost::int_max_value_t<SCHAR_MAX>, signed char>(SCHAR_MAX);
test_min_max_type<boost::int_min_value_t<SCHAR_MIN>, signed char>(SCHAR_MIN);
test_min_max_type<boost::uint_value_t<UCHAR_MAX>, unsigned char>(UCHAR_MAX);
#if(USHRT_MAX != UCHAR_MAX)
test_min_max_type<boost::int_max_value_t<SCHAR_MAX+1>, short>(SCHAR_MAX+1);
test_min_max_type<boost::int_min_value_t<SCHAR_MIN-1>, short>(SCHAR_MIN-1);
test_min_max_type<boost::uint_value_t<UCHAR_MAX+1>, unsigned short>(UCHAR_MAX+1);
test_min_max_type<boost::int_max_value_t<SHRT_MAX>, short>(SHRT_MAX);
test_min_max_type<boost::int_min_value_t<SHRT_MIN>, short>(SHRT_MIN);
test_min_max_type<boost::uint_value_t<USHRT_MAX>, unsigned short>(USHRT_MAX);
#endif
// Get the extreme values for each integral type
template < typename T >
struct minimum_of
: boost::mpl::integral_c< T, boost::integer_traits<T>::const_min >
{
};
template < typename T >
struct maximum_of
: boost::mpl::integral_c< T, boost::integer_traits<T>::const_max >
{
};
} // unnamed namespace
// Check the processor-optimzed type system
BOOST_AUTO_TEST_SUITE( optimized_type_tests )
// Check the optimzed type override of a given type
BOOST_AUTO_TEST_CASE( fast_type_test )
{
typedef short least_type;
typedef boost::int_fast_t<least_type>::fast fast_type;
typedef std::numeric_limits<least_type> least_limits;
typedef std::numeric_limits<fast_type> fast_limits;
typedef boost::fast_integral<least_type>::type real_fast_type;
BOOST_MPL_ASSERT_RELATION( (boost::is_same<least_type, fast_type>::value),
==, false );
BOOST_MPL_ASSERT_RELATION( (boost::is_same<fast_type,
real_fast_type>::value), ==, true );
BOOST_MPL_ASSERT_RELATION( fast_limits::is_specialized, ==, true );
BOOST_MPL_ASSERT_RELATION( fast_limits::is_signed &&
fast_limits::is_bounded, ==, true );
BOOST_MPL_ASSERT_RELATION( fast_limits::radix, ==, 2 );
BOOST_MPL_ASSERT_RELATION( fast_limits::digits, >=, least_limits::digits );
#if(UINT_MAX != USHRT_MAX)
test_min_max_type<boost::int_max_value_t<SHRT_MAX+1>, int>(SHRT_MAX+1);
test_min_max_type<boost::int_min_value_t<SHRT_MIN-1>, int>(SHRT_MIN-1);
test_min_max_type<boost::uint_value_t<USHRT_MAX+1>, unsigned int>(USHRT_MAX+1);
test_min_max_type<boost::int_max_value_t<INT_MAX>, int>(INT_MAX);
test_min_max_type<boost::int_min_value_t<INT_MIN>, int>(INT_MIN);
test_min_max_type<boost::uint_value_t<UINT_MAX>, unsigned int>(UINT_MAX);
#endif
#if(ULONG_MAX != UINT_MAX)
test_min_max_type<boost::int_max_value_t<INT_MAX+1L>, long>(INT_MAX+1L);
test_min_max_type<boost::int_min_value_t<INT_MIN-1L>, long>(INT_MIN-1L);
test_min_max_type<boost::uint_value_t<UINT_MAX+1uL>, unsigned long>(UINT_MAX+1uL);
test_min_max_type<boost::int_max_value_t<LONG_MAX>, long>(LONG_MAX);
test_min_max_type<boost::int_min_value_t<LONG_MIN>, long>(LONG_MIN);
test_min_max_type<boost::uint_value_t<ULONG_MAX>, unsigned long>(ULONG_MAX);
#endif
#ifndef BOOST_NO_INTEGRAL_INT64_T
#if defined(BOOST_HAS_LONG_LONG) && (defined(ULLONG_MAX) && (ULLONG_MAX != ULONG_MAX))
test_min_max_type<boost::int_max_value_t<LONG_MAX+1LL>, boost::long_long_type>(LONG_MAX+1LL);
test_min_max_type<boost::int_min_value_t<LONG_MIN-1LL>, boost::long_long_type>(LONG_MIN-1LL);
test_min_max_type<boost::uint_value_t<ULONG_MAX+1uLL>, boost::ulong_long_type>(ULONG_MAX+1uLL);
test_min_max_type<boost::int_max_value_t<LLONG_MAX>, boost::long_long_type>(LLONG_MAX);
test_min_max_type<boost::int_min_value_t<LLONG_MIN>, boost::long_long_type>(LLONG_MIN);
test_min_max_type<boost::uint_value_t<ULLONG_MAX>, boost::ulong_long_type>(ULLONG_MAX);
#endif
#if defined(BOOST_HAS_LONG_LONG) && (defined(ULONG_LONG_MAX) && (ULONG_LONG_MAX != ULONG_MAX))
test_min_max_type<boost::int_max_value_t<LONG_MAX+1LL>, boost::long_long_type>(LONG_MAX+1LL);
test_min_max_type<boost::int_min_value_t<LONG_MIN-1LL>, boost::long_long_type>(LONG_MIN-1LL);
test_min_max_type<boost::uint_value_t<ULONG_MAX+1uLL>, boost::ulong_long_type>(ULONG_MAX+1uLL);
test_min_max_type<boost::int_max_value_t<LONG_LONG_MAX>, boost::long_long_type>(LONG_LONG_MAX);
test_min_max_type<boost::int_min_value_t<LONG_LONG_MIN>, boost::long_long_type>(LONG_LONG_MIN);
test_min_max_type<boost::uint_value_t<ULONG_LONG_MAX>, boost::ulong_long_type>(ULONG_LONG_MAX);
#endif
#if defined(BOOST_HAS_LONG_LONG) && (defined(ULONGLONG_MAX) && (ULONGLONG_MAX != ULONG_MAX))
test_min_max_type<boost::int_max_value_t<LONG_MAX+1LL>, boost::long_long_type>(LONG_MAX+1LL);
test_min_max_type<boost::int_min_value_t<LONG_MIN-1LL>, boost::long_long_type>(LONG_MIN-1LL);
test_min_max_type<boost::uint_value_t<ULONG_MAX+1uLL>, boost::ulong_long_type>(ULONG_MAX+1uLL);
test_min_max_type<boost::int_max_value_t<LONGLONG_MAX>, boost::long_long_type>(LONGLONG_MAX);
test_min_max_type<boost::int_min_value_t<LONGLONG_MIN>, boost::long_long_type>(LONGLONG_MAX);
test_min_max_type<boost::uint_value_t<ULONGLONG_MAX>, boost::ulong_long_type>(ULONGLONG_MAX);
#endif
#if defined(BOOST_HAS_LONG_LONG) && (defined(_ULLONG_MAX) && defined(_LLONG_MIN) && (_ULLONG_MAX != ULONG_MAX))
test_min_max_type<boost::int_max_value_t<LONG_MAX+1LL>, boost::long_long_type>(LONG_MAX+1LL);
test_min_max_type<boost::int_min_value_t<LONG_MIN-1LL>, boost::long_long_type>(LONG_MIN-1LL);
test_min_max_type<boost::uint_value_t<ULONG_MAX+1uLL>, boost::ulong_long_type>(ULONG_MAX+1uLL);
test_min_max_type<boost::int_max_value_t<_LLONG_MAX>, boost::long_long_type>(_LLONG_MAX);
test_min_max_type<boost::int_min_value_t<_LLONG_MIN>, boost::long_long_type>(_LLONG_MIN);
test_min_max_type<boost::uint_value_t<_ULLONG_MAX>, boost::ulong_long_type>(_ULLONG_MAX);
#endif // BOOST_HAS_LONG_LONG
#endif // BOOST_NO_INTEGRAL_INT64_T
return boost::report_errors();
}
BOOST_AUTO_TEST_SUITE_END()
// Check if given types can support given size parameters
BOOST_AUTO_TEST_SUITE( show_type_tests )
// Check the specialization type status of given bit lengths, minimum
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_lengths_test, T, bits_list )
{
BOOST_CHECK_EQUAL( print_out_template(signed_sized_integral<T::value>(),
T::value, "a sized_integral<", ", signed>"), T::value && (T::value <=
intmax_bits) );
BOOST_CHECK_EQUAL( print_out_template(unsigned_sized_integral<T::value>(),
T::value, "a sized_integral<", ", unsigned>"), T::value <= uintmax_bits );
}
// Check the classic specialization type status of given bit lengths, minimum,
// unsigned
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_unsigned_test, T,
valid_bits_list )
{
// This test is supposed to replace the following printouts given in
// puesdo-code by:
// Routine: Template, Type
// for N := 32 downto 0
// cout << "Type '" << Template << "<" N << ">::" << Type << "' is '"
// << typeid(Template<N>::Type).name << ".'\n"
// end for
// end Routine
// with Template = {int_t, uint_t}; Type = {least, fast}
// But now we'll use template meta-programming instead of macros. The limit
// of type-lists is usually less than 32 (not to mention 64) elements, so we
// have to take selected values. The only interesting part is if the bit
// count is too large, and we can't check that yet.
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
boost::uint_t<T::value>::least>::digits, >=, T::value );
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
boost::uint_t<T::value>::fast>::digits, >=, T::value );
}
// Check the classic specialization type status of given bit lengths, minimum,
// signed
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_signed_test, T,
valid_to_decrease_bits_list )
{
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
boost::int_t<T::value>::least>::digits, >=, T::value - 1 );
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
boost::int_t<T::value>::fast>::digits, >=, T::value - 1 );
}
// Check size comparisons of given value support, unsigned
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_unsigned_values_test, T,
valid_to_increase_ubits_list )
{
// This test is supposed to replace the following printouts given in
// puesdo-code by:
// Routine: Type
// for N := 30 downto 0
// cout << "Type '" << uint_value_t << "<" (1ul << N) << ">::" << Type
// << "' is '"<< typeid(uint_value_t<(1ul << N)>::Type).name << ".'\n"
// end for
// end Routine
// with Type = {least, fast}
// But now we'll use template meta-programming instead of macros. The limit
// of type-lists is usually less than 32 (not to mention 64) elements, so we
// have to take selected values. The interesting parts are where N is the
// length of a integral type, so 1 << N would have to fit in the next larger
// type. (This is why N can't be more than bitlength(uintmax_t) - 1.)
boost::uintmax_t const one = 1u;
BOOST_MPL_ASSERT( (boost::mpl::equal< boost::maximum_unsigned_integral<(one
<< T::value)>, unsigned_sized_integral<T::value + 1> >) );
}
// Check size comparisons of given value support, signed
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_signed_values_test, T,
valid_to_increase_sbits_list )
{
// This test is supposed to replace the following printouts given in
// puesdo-code by:
// Routine: Type
// for N := 30 downto 0
// cout << "Type '" << int_max_value_t << "<" +(1ul << N) << ">::" <<
// Type << "' is '" << typeid(int_max_value_t<+(1ul << N)>::Type).name
// << ".'\n"
// cout << "Type '" << int_min_value_t << "<" -(1ul << N) << ">::" <<
// Type << "' is '" << typeid(int_min_value_t<-(1ul << N)>::Type).name
// << ".'\n"
// end for
// end Routine
// with Type = {least, fast}
// But now we'll use template meta-programming instead of macros. The limit
// of type-lists is usually less than 32 (not to mention 64) elements, so we
// have to take selected values. The interesting parts are where N is the
// length of a integral type, so 1 << N would have to fit in the next larger
// type. (This is why N can't be more than bitlength(intmax_t) - 1. Note
// that bitlength(intmax_t) + 1 == bitlength(uintmax_t).)
static boost::intmax_t const one = 1;
BOOST_MPL_ASSERT( (boost::mpl::equal< boost::maximum_signed_integral<+(one
<< T::value)>, signed_sized_integral<T::value + 1> >) );
BOOST_MPL_ASSERT( (boost::mpl::equal< boost::minimum_signed_integral<-(one
<< T::value)>, signed_sized_integral<T::value + 1> >) );
}
// Check the specialization type status of given bit lengths, exact only
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_exact_lengths_test, T, bits_list )
{
bool const is_exact_length = std::binary_search( integral_bit_lengths,
integral_bit_lengths + integral_type_count, T::value );
BOOST_CHECK_EQUAL( print_out_template(signed_exact_integral<T::value>(),
T::value, "an exact_integral<", ", signed>"), is_exact_length );
BOOST_CHECK_EQUAL( print_out_template(unsigned_exact_integral<T::value>(),
T::value, "an exact_integral<", ", unsigned>"), is_exact_length );
}
// Check the classic specialization type status of given bit lengths, exact only
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_exact_lengths_test, T,
distinct_integral_bit_counts )
{
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
boost::int_exact_t<T::value>::exact>::digits, ==, T::value - 1 );
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
boost::uint_exact_t<T::value>::exact>::digits, ==, T::value );
}
// Check if MPL-compatible templates give bad returns for out-of-range values
BOOST_AUTO_TEST_CASE( show_not_type_for_parameter_test )
{
typedef signed_sized_integral< 3> ssz3_type;
typedef signed_sized_integral< 0> ssz0_type;
typedef signed_sized_integral<-3> ssz3n_type;
BOOST_CHECK( print_out_template(ssz3_type(), ssz3_type::bit_count,
"a sized_integral<", ", signed>") );
BOOST_CHECK( !print_out_template(ssz0_type(), ssz0_type::bit_count,
"a sized_integral<", ", signed>") );
BOOST_CHECK( !print_out_template(ssz3n_type(), ssz3n_type::bit_count,
"a sized_integral<", ", signed>") );
typedef unsigned_sized_integral< 3> usz3_type;
typedef unsigned_sized_integral< 0> usz0_type;
typedef unsigned_sized_integral<-3> usz3n_type;
BOOST_CHECK( print_out_template(usz3_type(), usz3_type::bit_count,
"a sized_integral<", ", unsigned>") );
BOOST_CHECK( print_out_template(usz0_type(), usz0_type::bit_count,
"a sized_integral<", ", unsigned>") );
BOOST_CHECK( !print_out_template(usz3n_type(), usz3n_type::bit_count,
"a sized_integral<", ", unsigned>") );
typedef signed_exact_integral< CHAR_BIT > se8_type;
typedef signed_exact_integral< 3> se3_type;
typedef signed_exact_integral< 0> se0_type;
typedef signed_exact_integral<-3> se3n_type;
typedef signed_exact_integral< - CHAR_BIT > se8n_type;
BOOST_CHECK( print_out_template(se8_type(), se8_type::bit_count,
"an exact_integral<", ", signed>") );
BOOST_CHECK( !print_out_template(se3_type(), se3_type::bit_count,
"an exact_integral<", ", signed>") );
BOOST_CHECK( !print_out_template(se0_type(), se0_type::bit_count,
"an exact_integral<", ", signed>") );
BOOST_CHECK( !print_out_template(se3n_type(), se3n_type::bit_count,
"an exact_integral<", ", signed>") );
BOOST_CHECK( !print_out_template(se8n_type(), se8n_type::bit_count,
"an exact_integral<", ", signed>") );
typedef unsigned_exact_integral< CHAR_BIT > ue8_type;
typedef unsigned_exact_integral< 3> ue3_type;
typedef unsigned_exact_integral< 0> ue0_type;
typedef unsigned_exact_integral<-3> ue3n_type;
typedef unsigned_exact_integral< - CHAR_BIT > ue8n_type;
BOOST_CHECK( print_out_template(ue8_type(), ue8_type::bit_count,
"an exact_integral<", ", unsigned>") );
BOOST_CHECK( !print_out_template(ue3_type(), ue3_type::bit_count,
"an exact_integral<", ", unsigned>") );
BOOST_CHECK( !print_out_template(ue0_type(), ue0_type::bit_count,
"an exact_integral<", ", unsigned>") );
BOOST_CHECK( !print_out_template(ue3n_type(), ue3n_type::bit_count,
"an exact_integral<", ", unsigned>") );
BOOST_CHECK( !print_out_template(ue8n_type(), ue8n_type::bit_count,
"an exact_integral<", ", unsigned>") );
typedef boost::maximum_signed_integral< 15> max15_type;
typedef boost::maximum_signed_integral< 0> max0_type;
typedef boost::maximum_signed_integral<-15> max15n_type;
BOOST_CHECK( print_out_template(max15_type(), max15_type::bound,
"a maximum_signed_integral<", ">") );
BOOST_CHECK( !print_out_template(max0_type(), max0_type::bound,
"a maximum_signed_integral<", ">") );
BOOST_CHECK( !print_out_template(max15n_type(), max15n_type::bound,
"a maximum_signed_integral<", ">") );
typedef boost::minimum_signed_integral< 15> min15_type;
typedef boost::minimum_signed_integral< 0> min0_type;
typedef boost::minimum_signed_integral<-15> min15n_type;
BOOST_CHECK( !print_out_template(min15_type(), min15_type::bound,
"a minimum_signed_integral<", ">") );
BOOST_CHECK( !print_out_template(min0_type(), min0_type::bound,
"a minimum_signed_integral<", ">") );
BOOST_CHECK( print_out_template(min15n_type(), min15n_type::bound,
"a minimum_signed_integral<", ">") );
typedef boost::maximum_unsigned_integral<15> umax15_type;
typedef boost::maximum_unsigned_integral< 0> umax0_type;
BOOST_CHECK( print_out_template(umax15_type(), umax15_type::bound,
"a maximum_unsigned_integral<", ">") );
BOOST_CHECK( print_out_template(umax0_type(), umax0_type::bound,
"a maximum_unsigned_integral<", ">") );
}
BOOST_AUTO_TEST_SUITE_END()
// Check if given constants can fit in given types
BOOST_AUTO_TEST_SUITE( fit_type_tests )
// Check if large value can fit its minimum required size, by size
BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_masked_values_test, T,
valid_to_decrease_bits_list )
{
// This test is supposed to replace the following checks given in
// puesdo-code by:
// Routine: Template, Type
// for ( N = 32, V = Template:Max ; N >= 0 ; --N, V >>= 1 )
// Confirm( static_cast<typename Template<N>::Type>(V) == V );
// end for
// end Routine
// with Template = {int_t, uint_t}; Type = {least, fast};
// Template:Max = { intmax_t.Max for int_t, uintmax_t.Max for uint_t }
// In other words, the selected type doesn't mask out any bits it's not
// supposed to. But now we'll use template meta-programming instead of
// macros. The limit of type-lists is usually less than 32 (not to mention
// 64) elements, so we have to take selected values.
static int const count = T::value;
int const shift = uintmax_bits - count;
boost::uintmax_t const value_u = uintmax_limits::max
BOOST_PREVENT_MACRO_SUBSTITUTION () >> shift;
boost::intmax_t const value_s = intmax_limits::max
BOOST_PREVENT_MACRO_SUBSTITUTION () >> shift;
BOOST_CHECK_EQUAL( static_cast<typename
unsigned_sized_integral<count>::type>(value_u), value_u );
BOOST_CHECK_EQUAL( static_cast<typename
boost::uint_t<count>::least>(value_u), value_u );
BOOST_CHECK_EQUAL( static_cast<typename
boost::uint_t<count>::fast>(value_u), value_u );
BOOST_CHECK_EQUAL( static_cast<typename
signed_sized_integral<count>::type>(value_s), value_s );
BOOST_CHECK_EQUAL( static_cast<typename
boost::int_t<count>::least>(value_s), value_s );
BOOST_CHECK_EQUAL( static_cast<typename
boost::int_t<count>::fast>(value_s), value_s );
}
// Check if a large value can only fit of its exact bit length
BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_exact_lengths_test, T,
distinct_integral_bit_counts )
{
typename boost::exact_integral<T::value, unsigned>::type const one_u( 1u ),
high_bit_u( one_u << (T::value - 1) ), repeated_bits_u( (high_bit_u << 1) |
high_bit_u );
BOOST_CHECK( high_bit_u );
BOOST_CHECK_EQUAL( repeated_bits_u, high_bit_u );
typename boost::exact_integral<T::value, signed>::type const one_s( 1 ),
high_bit_s( one_s << (T::value - 2) ), repeated_bits_s( (high_bit_s << 1) |
high_bit_s ), repeated_2bits_s( (repeated_bits_s << 1) | high_bit_s );
BOOST_CHECK( high_bit_s > 0 );
BOOST_CHECK( repeated_bits_s < 0 );
BOOST_CHECK_EQUAL( repeated_bits_s, repeated_2bits_s );
}
// Check if large value can fit its minimum required size, by value, unsigned
BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_unsigned_values_test, T,
valid_to_increase_ubits_list )
{
// This test is supposed to replace the following checks given in
// puesdo-code by:
// Routine: Template, Type
// for ( N = 0, V = Template:Extreme ; N < 32 ; ++N, V >>= 1 )
// Confirm( static_cast<typename Template<V>::Type>(V) == V );
// end for
// end Routine
// with Template = {uint_value_t}; Type = {least, fast}; Template:Extreme =
// {uintmax_t.Max for uint_value_t}
// In other words, the selected type doesn't mask out any bits it's not
// supposed to. But now we'll use template meta-programming instead of
// macros. The limit of type-lists is usually less than 32 (not to mention
// 64) elements, so we have to take selected values.
using boost::uintmax_t;
typedef boost::mpl::shift_right<maximum_of<uintmax_t>, T> maxi_type;
uintmax_t const maxi = maxi_type::value;
BOOST_CHECK_EQUAL( static_cast<typename
boost::uint_value_t<maxi_type::value>::least>(maxi), maxi );
BOOST_CHECK_EQUAL( static_cast<typename
boost::uint_value_t<maxi_type::value>::fast>(maxi), maxi );
}
// Check if large value can fit its minimum required size, by value, signed
BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_signed_values_test, T,
valid_to_increase_sbits_list )
{
// This test is supposed to replace the following checks given in
// puesdo-code by:
// Routine: Template, Type
// for ( N = 0, V = Template:Extreme ; N < 32 ; ++N, V >>= 1 )
// Confirm( static_cast<typename Template<V>::Type>(V) == V );
// end for
// end Routine
// with Template = {int_max_value_t, int_min_value_t}; Type = {least, fast};
// Template:Extreme = {intmax_t.Min for int_min_value_t, intmax_t.Max
// for int_max_value_t}
// In other words, the selected type doesn't mask out any bits it's not
// supposed to. But now we'll use template meta-programming instead of
// macros. The limit of type-lists is usually less than 32 (not to mention
// 64) elements, so we have to take selected values.
using boost::intmax_t;
typedef boost::mpl::shift_right<minimum_of<intmax_t>, T> mini_type;
typedef boost::mpl::shift_right<maximum_of<intmax_t>, T> maxi_type;
intmax_t const maxi = maxi_type::value, mini = mini_type::value;
BOOST_CHECK_EQUAL( static_cast<typename
boost::int_max_value_t<maxi_type::value>::least>(maxi), maxi );
BOOST_CHECK_EQUAL( static_cast<typename
boost::int_max_value_t<maxi_type::value>::fast>(maxi), maxi );
BOOST_CHECK_EQUAL( static_cast<typename
boost::int_min_value_t<mini_type::value>::least>(mini), mini );
BOOST_CHECK_EQUAL( static_cast<typename
boost::int_min_value_t<mini_type::value>::fast>(mini), mini );
}
BOOST_AUTO_TEST_SUITE_END()
// Verification of bugs and their fixes
BOOST_AUTO_TEST_SUITE( bug_fix_tests )
BOOST_AUTO_TEST_SUITE_END()

View File

@ -0,0 +1,37 @@
// Copyright John Maddock 2009.
// 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)
#include <boost/integer_traits.hpp> // must be the only #include!
template <class T>
void check_numeric_limits_derived(const std::numeric_limits<T>&){}
template <class T>
void check()
{
typedef boost::integer_traits<T> traits;
check_numeric_limits_derived(traits());
bool b = traits::is_integral;
(void)b;
T v = traits::const_min + traits::const_max;
(void)v;
}
int main()
{
check<signed char>();
check<unsigned char>();
check<char>();
check<short>();
check<unsigned short>();
check<int>();
check<unsigned int>();
check<signed long>();
check<unsigned long>();
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
check<boost::long_long_type>();
check<boost::ulong_long_type>();
#endif
}

View File

@ -17,8 +17,7 @@
// use int64_t instead of long long for better portability
#include <boost/cstdint.hpp>
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
#include <boost/detail/lightweight_test.hpp>
/*
* General portability note:
@ -53,22 +52,22 @@ void runtest(const char * type, T)
<< "; min is " << make_char_numeric_for_streaming((traits::min)())
<< ", max is " << make_char_numeric_for_streaming((traits::max)())
<< std::endl;
BOOST_CHECK(traits::is_specialized);
BOOST_TEST(traits::is_specialized);
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1200)
// MSVC++ 6.0 issues a LNK1179 error (duplicate comdat) when the compiler
// generates different symbol names with a very long common prefix:
// the dummy "&& true" disambiguates between the symbols generated by this
// BOOST_CHECK instantiation and the preceding one.
BOOST_CHECK(traits::is_integer && true);
// BOOST_TEST instantiation and the preceding one.
BOOST_TEST(traits::is_integer && true);
#else
BOOST_CHECK(traits::is_integer);
BOOST_TEST(traits::is_integer);
#endif
BOOST_CHECK(traits::is_integral == true);
BOOST_CHECK(traits::const_min == (traits::min)());
BOOST_CHECK(traits::const_max == (traits::max)());
BOOST_TEST(traits::is_integral == true);
BOOST_TEST(traits::const_min == (traits::min)());
BOOST_TEST(traits::const_max == (traits::max)());
}
int test_main(int, char*[])
int main(int, char*[])
{
runtest("bool", bool());
runtest("char", char());
@ -86,7 +85,7 @@ int test_main(int, char*[])
runtest("long", long());
typedef unsigned long unsigned_long;
runtest("unsigned long", unsigned_long());
#if !defined(BOOST_NO_INT64_T) && (!defined(BOOST_MSVC) || BOOST_MSVC > 1300) && !defined(__BORLANDC__) && !defined(__BEOS__)
#ifndef BOOST_NO_INTEGRAL_INT64_T
//
// MS/Borland compilers can't support 64-bit member constants
// BeOS doesn't have specialisations for long long in SGI's <limits> header.
@ -97,6 +96,6 @@ int test_main(int, char*[])
#endif
// Some compilers don't pay attention to std:3.6.1/5 and issue a
// warning here if "return 0;" is omitted.
return 0;
return boost::report_errors();
}

View File

@ -1,33 +0,0 @@
// boost Issue #2134 test program ------------------------------------------//
// Copyright Daryle Walker 2008. Distributed under the Boost
// Software License, Version 1.0. (See the accompanying file
// LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
// See <http://www.boost.org/libs/integer> for documentation.
// See <http://svn.boost.org/trac/boost/ticket/2134> for the issue involved.
// Revision History
// 23 Jul 2008 Initial version
// Control if the inclusion error is triggered
#ifndef CONTROL_INCLUDE_TRAITS
#define CONTROL_INCLUDE_TRAITS 1
#endif
#if CONTROL_INCLUDE_TRAITS
// This file defines boost::detail::integer_traits.
#include <boost/detail/numeric_traits.hpp>
#endif
// This is the file with the issue. It has items within the boost::detail
// namespace that referenced an unadorned "integer_traits". This was meant to
// refer to boost::integer_traits. However, <boost/detail/numeric_traits.hpp>
// defines a boost::detail::integer_traits. If that header is #included before
// this one, then b.d.integer_traits (rightfully) took priority, which lead to a
// syntax error.
#include <boost/integer.hpp>
// Main program, minimal (since this is a compile test)
int main() { return 0; }

View File

@ -0,0 +1,14 @@
// Copyright John Maddock 2009.
// 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)
#include <boost/integer/static_log2.hpp> // must be the only #include!
int main()
{
boost::static_log2_argument_type arg = 0;
(void)arg;
boost::static_log2_result_type result = boost::static_log2<30>::value;
(void)result;
}

View File

@ -10,8 +10,7 @@
// Revision History
// 01 Oct 2001 Initial version (Daryle Walker)
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp> // for main
#include <boost/detail/lightweight_test.hpp> // for main
#include <boost/cstdlib.hpp> // for boost::exit_success
#include <boost/integer/static_log2.hpp> // for boost::static_log2
@ -20,7 +19,7 @@
// Macros to compact code
#define PRIVATE_LB_TEST( v, e ) BOOST_CHECK( ::boost::static_log2<v>::value == e )
#define PRIVATE_LB_TEST( v, e ) BOOST_TEST( ::boost::static_log2<v>::value == e )
#define PRIVATE_PRINT_LB( v ) ::std::cout << "boost::static_log2<" << (v) \
<< "> = " << ::boost::static_log2< (v) >::value << '.' << ::std::endl
@ -35,7 +34,7 @@
// Main testing function
int
test_main
main
(
int , // "argc" is unused
char * [] // "argv" is unused
@ -146,5 +145,5 @@ test_main
PRIVATE_LB_TEST( 65536, 16 );
PRIVATE_LB_TEST( 65537, 16 );
return boost::exit_success;
return boost::report_errors();
}

View File

@ -0,0 +1,14 @@
// Copyright John Maddock 2009.
// 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)
#include <boost/integer/static_min_max.hpp> // must be the only #include!
int main()
{
boost::static_min_max_signed_type m = boost::static_signed_min<2, 3>::value + boost::static_signed_max<2, 3>::value;
(void)m;
boost::static_min_max_unsigned_type u = boost::static_unsigned_min<2, 3>::value + boost::static_unsigned_max<2, 3>::value;
(void)u;
}

View File

@ -10,8 +10,7 @@
// Revision History
// 23 Sep 2001 Initial version (Daryle Walker)
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp> // for main, BOOST_CHECK
#include <boost/detail/lightweight_test.hpp> // for main, BOOST_TEST
#include <boost/cstdlib.hpp> // for boost::exit_success
#include <boost/integer/static_min_max.hpp> // for boost::static_signed_min, etc.
@ -21,7 +20,7 @@
// Main testing function
int
test_main
main
(
int , // "argc" is unused
char * [] // "argv" is unused
@ -37,57 +36,57 @@ test_main
// Two positives
cout << "Doing tests with two positive values." << endl;
BOOST_CHECK( (static_signed_min< 9, 14>::value) == 9 );
BOOST_CHECK( (static_signed_max< 9, 14>::value) == 14 );
BOOST_CHECK( (static_signed_min<14, 9>::value) == 9 );
BOOST_CHECK( (static_signed_max<14, 9>::value) == 14 );
BOOST_TEST( (static_signed_min< 9, 14>::value) == 9 );
BOOST_TEST( (static_signed_max< 9, 14>::value) == 14 );
BOOST_TEST( (static_signed_min<14, 9>::value) == 9 );
BOOST_TEST( (static_signed_max<14, 9>::value) == 14 );
BOOST_CHECK( (static_unsigned_min< 9, 14>::value) == 9 );
BOOST_CHECK( (static_unsigned_max< 9, 14>::value) == 14 );
BOOST_CHECK( (static_unsigned_min<14, 9>::value) == 9 );
BOOST_CHECK( (static_unsigned_max<14, 9>::value) == 14 );
BOOST_TEST( (static_unsigned_min< 9, 14>::value) == 9 );
BOOST_TEST( (static_unsigned_max< 9, 14>::value) == 14 );
BOOST_TEST( (static_unsigned_min<14, 9>::value) == 9 );
BOOST_TEST( (static_unsigned_max<14, 9>::value) == 14 );
// Two negatives
cout << "Doing tests with two negative values." << endl;
BOOST_CHECK( (static_signed_min< -8, -101>::value) == -101 );
BOOST_CHECK( (static_signed_max< -8, -101>::value) == -8 );
BOOST_CHECK( (static_signed_min<-101, -8>::value) == -101 );
BOOST_CHECK( (static_signed_max<-101, -8>::value) == -8 );
BOOST_TEST( (static_signed_min< -8, -101>::value) == -101 );
BOOST_TEST( (static_signed_max< -8, -101>::value) == -8 );
BOOST_TEST( (static_signed_min<-101, -8>::value) == -101 );
BOOST_TEST( (static_signed_max<-101, -8>::value) == -8 );
// With zero
cout << "Doing tests with zero and a positive or negative value." << endl;
BOOST_CHECK( (static_signed_min< 0, 14>::value) == 0 );
BOOST_CHECK( (static_signed_max< 0, 14>::value) == 14 );
BOOST_CHECK( (static_signed_min<14, 0>::value) == 0 );
BOOST_CHECK( (static_signed_max<14, 0>::value) == 14 );
BOOST_TEST( (static_signed_min< 0, 14>::value) == 0 );
BOOST_TEST( (static_signed_max< 0, 14>::value) == 14 );
BOOST_TEST( (static_signed_min<14, 0>::value) == 0 );
BOOST_TEST( (static_signed_max<14, 0>::value) == 14 );
BOOST_CHECK( (static_unsigned_min< 0, 14>::value) == 0 );
BOOST_CHECK( (static_unsigned_max< 0, 14>::value) == 14 );
BOOST_CHECK( (static_unsigned_min<14, 0>::value) == 0 );
BOOST_CHECK( (static_unsigned_max<14, 0>::value) == 14 );
BOOST_TEST( (static_unsigned_min< 0, 14>::value) == 0 );
BOOST_TEST( (static_unsigned_max< 0, 14>::value) == 14 );
BOOST_TEST( (static_unsigned_min<14, 0>::value) == 0 );
BOOST_TEST( (static_unsigned_max<14, 0>::value) == 14 );
BOOST_CHECK( (static_signed_min< 0, -101>::value) == -101 );
BOOST_CHECK( (static_signed_max< 0, -101>::value) == 0 );
BOOST_CHECK( (static_signed_min<-101, 0>::value) == -101 );
BOOST_CHECK( (static_signed_max<-101, 0>::value) == 0 );
BOOST_TEST( (static_signed_min< 0, -101>::value) == -101 );
BOOST_TEST( (static_signed_max< 0, -101>::value) == 0 );
BOOST_TEST( (static_signed_min<-101, 0>::value) == -101 );
BOOST_TEST( (static_signed_max<-101, 0>::value) == 0 );
// With identical
cout << "Doing tests with two identical values." << endl;
BOOST_CHECK( (static_signed_min<0, 0>::value) == 0 );
BOOST_CHECK( (static_signed_max<0, 0>::value) == 0 );
BOOST_CHECK( (static_unsigned_min<0, 0>::value) == 0 );
BOOST_CHECK( (static_unsigned_max<0, 0>::value) == 0 );
BOOST_TEST( (static_signed_min<0, 0>::value) == 0 );
BOOST_TEST( (static_signed_max<0, 0>::value) == 0 );
BOOST_TEST( (static_unsigned_min<0, 0>::value) == 0 );
BOOST_TEST( (static_unsigned_max<0, 0>::value) == 0 );
BOOST_CHECK( (static_signed_min<14, 14>::value) == 14 );
BOOST_CHECK( (static_signed_max<14, 14>::value) == 14 );
BOOST_CHECK( (static_unsigned_min<14, 14>::value) == 14 );
BOOST_CHECK( (static_unsigned_max<14, 14>::value) == 14 );
BOOST_TEST( (static_signed_min<14, 14>::value) == 14 );
BOOST_TEST( (static_signed_max<14, 14>::value) == 14 );
BOOST_TEST( (static_unsigned_min<14, 14>::value) == 14 );
BOOST_TEST( (static_unsigned_max<14, 14>::value) == 14 );
BOOST_CHECK( (static_signed_min< -101, -101>::value) == -101 );
BOOST_CHECK( (static_signed_max< -101, -101>::value) == -101 );
BOOST_TEST( (static_signed_min< -101, -101>::value) == -101 );
BOOST_TEST( (static_signed_max< -101, -101>::value) == -101 );
return boost::exit_success;
return boost::report_errors();
}