mirror of
https://github.com/boostorg/integer.git
synced 2025-07-16 06:02:08 +02:00
Fix issues in docs.
[SVN r58008]
This commit is contained in:
@ -49,10 +49,11 @@
|
|||||||
integer widths. All typedef's are in namespace boost.
|
integer widths. All typedef's are in namespace boost.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
The specifications are based on the ISO/IEC 9899:1999 C Language standard
|
The specifications for these types are based on the ISO/IEC 9899:1999 C Language
|
||||||
header <stdint.h>. The 64-bit types required by the C standard are
|
standard header <stdint.h>. The 64-bit types required by the C standard
|
||||||
not required in the boost header, and may not be supplied in all implementations,
|
are <span class="emphasis"><em>not required</em></span> in the boost header, and may not be
|
||||||
because <code class="literal">long long</code> is not [yet] included in the C++ standard.
|
supplied for all platforms/compilers, because <code class="literal">long long</code>
|
||||||
|
is not [yet] included in the C++ standard.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
See <a href="../../../test/cstdint_test.cpp" target="_top">cstdint_test.cpp</a> for
|
See <a href="../../../test/cstdint_test.cpp" target="_top">cstdint_test.cpp</a> for
|
||||||
@ -66,13 +67,13 @@
|
|||||||
<p>
|
<p>
|
||||||
The organization of the Boost.Integer headers and classes is designed to
|
The organization of the Boost.Integer headers and classes is designed to
|
||||||
take advantage of <stdint.h> types from the 1999 C standard without
|
take advantage of <stdint.h> types from the 1999 C standard without
|
||||||
resorting to undefined behavior in terms of the 1998 C++ standard. The header
|
causing undefined behavior in terms of the 1998 C++ standard. The header
|
||||||
<boost/cstdint.hpp> makes the standard integer types safely available
|
<boost/cstdint.hpp> makes the standard integer types safely available
|
||||||
in namespace <code class="literal">boost</code> without placing any names in namespace
|
in namespace <code class="literal">boost</code> without placing any names in namespace
|
||||||
<code class="literal">std</code>. As always, the intension is to complement rather
|
<code class="literal">std</code>. The intension is to complement rather than compete
|
||||||
than compete with the C++ Standard Library. Should some future C++ standard
|
with the C++ Standard Library. Should some future C++ standard include <stdint.h>
|
||||||
include <stdint.h> and <cstdint>, then <boost/cstdint.hpp>
|
and <cstdint>, then <boost/cstdint.hpp> will continue to function,
|
||||||
will continue to function, but will become redundant and may be safely deprecated.
|
but will become redundant and may be safely deprecated.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Because these are boost headers, their names conform to boost header naming
|
Because these are boost headers, their names conform to boost header naming
|
||||||
@ -108,9 +109,9 @@
|
|||||||
designates an unsigned integer type of exactly # bits.
|
designates an unsigned integer type of exactly # bits.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
These types are optional. However, if an implementation provides integer
|
These types are optional. However, if a platform supports integer types with
|
||||||
types with widths of 8, 16, 32, or 64 bits, it shall define the corresponding
|
widths of 8, 16, 32, 64, or any combination thereof, then <boost/cstdint.hpp>
|
||||||
typedef names.
|
does provide the corresponding typedefs.
|
||||||
</p>
|
</p>
|
||||||
<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>.
|
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>.
|
||||||
@ -125,14 +126,14 @@
|
|||||||
The typedef <code class="literal">int_least#_t</code>, with # replaced by the width,
|
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
|
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.
|
no signed integer type with lesser size has at least the specified width.
|
||||||
Thus, <code class="literal">int_least32_t</code> denotes a signed integer type with
|
Thus, <code class="literal">int_least32_t</code> denotes the smallest signed integer
|
||||||
a width of at least 32 bits. Similarly, the typedef name <code class="literal">uint_least#_t</code>
|
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
|
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
|
that no unsigned integer type with lesser size has at least the specified
|
||||||
width.
|
width.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Required minimum-width integer types:
|
The following minimum-width integer types are provided for all platforms:
|
||||||
</p>
|
</p>
|
||||||
<div class="itemizedlist"><ul type="disc">
|
<div class="itemizedlist"><ul type="disc">
|
||||||
<li><code class="literal">int_least8_t</code></li>
|
<li><code class="literal">int_least8_t</code></li>
|
||||||
@ -143,17 +144,13 @@
|
|||||||
<li><code class="literal">uint_least32_t</code></li>
|
<li><code class="literal">uint_least32_t</code></li>
|
||||||
</ul></div>
|
</ul></div>
|
||||||
<p>
|
<p>
|
||||||
The types:
|
The following types are available only if, after including <boost/cstdint.hpp>,
|
||||||
|
the macro BOOST_NO_INT64_T is not defined:
|
||||||
</p>
|
</p>
|
||||||
<div class="itemizedlist"><ul type="disc">
|
<div class="itemizedlist"><ul type="disc">
|
||||||
<li><code class="literal">int_least64_t</code></li>
|
<li><code class="literal">int_least64_t</code></li>
|
||||||
<li><code class="literal">uint_least64_t</code></li>
|
<li><code class="literal">uint_least64_t</code></li>
|
||||||
</ul></div>
|
</ul></div>
|
||||||
<p>
|
|
||||||
Are available only if, after inclusion of <code class="literal"><boost/cstdint.hpp></code>
|
|
||||||
the macro <code class="computeroutput"><span class="identifier">BOOST_NO_INT64_T</span></code>
|
|
||||||
is <span class="emphasis"><em><span class="bold"><strong>not defined</strong></span></em></span>.
|
|
||||||
</p>
|
|
||||||
<p>
|
<p>
|
||||||
All other minimum-width integer types are optional.
|
All other minimum-width integer types are optional.
|
||||||
</p>
|
</p>
|
||||||
@ -174,7 +171,7 @@
|
|||||||
case, however, they satisfy the signedness and width requirements.
|
case, however, they satisfy the signedness and width requirements.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Required fastest minimum-width integer types:
|
The following fastest minimum-width integer types are provided for all platforms:
|
||||||
</p>
|
</p>
|
||||||
<div class="itemizedlist"><ul type="disc">
|
<div class="itemizedlist"><ul type="disc">
|
||||||
<li><code class="literal">int_fast8_t</code></li>
|
<li><code class="literal">int_fast8_t</code></li>
|
||||||
@ -185,17 +182,13 @@
|
|||||||
<li><code class="literal">uint_fast32_t</code></li>
|
<li><code class="literal">uint_fast32_t</code></li>
|
||||||
</ul></div>
|
</ul></div>
|
||||||
<p>
|
<p>
|
||||||
The types:
|
The following types are available only if, after including <boost/cstdint.hpp>,
|
||||||
|
the macro BOOST_NO_INT64_T is not defined:
|
||||||
</p>
|
</p>
|
||||||
<div class="itemizedlist"><ul type="disc">
|
<div class="itemizedlist"><ul type="disc">
|
||||||
<li><code class="literal">int_fast64_t</code></li>
|
<li><code class="literal">int_fast64_t</code></li>
|
||||||
<li><code class="literal">uint_fast64_t</code></li>
|
<li><code class="literal">uint_fast64_t</code></li>
|
||||||
</ul></div>
|
</ul></div>
|
||||||
<p>
|
|
||||||
Are available only if, after inclusion of <code class="literal"><boost/cstdint.hpp></code>
|
|
||||||
the macro <code class="computeroutput"><span class="identifier">BOOST_NO_INT64_T</span></code>
|
|
||||||
is <span class="emphasis"><em><span class="bold"><strong>not defined</strong></span></em></span>.
|
|
||||||
</p>
|
|
||||||
<p>
|
<p>
|
||||||
All other fastest minimum-width integer types are optional.
|
All other fastest minimum-width integer types are optional.
|
||||||
</p>
|
</p>
|
||||||
@ -214,7 +207,7 @@
|
|||||||
capable of representing any value of any unsigned integer type.
|
capable of representing any value of any unsigned integer type.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
These types are required.
|
These types are provided for all platforms.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
<a name="boost_integer.history"></a><a class="link" href="history.html" title="History"> History</a>
|
<a name="boost_integer.history"></a><a class="link" href="history.html" title="History"> History</a>
|
||||||
</h2></div></div></div>
|
</h2></div></div></div>
|
||||||
<a name="boost_integer.history.1_42_0"></a><h5>
|
<a name="boost_integer.history.1_42_0"></a><h5>
|
||||||
<a name="id773547"></a>
|
<a name="id768488"></a>
|
||||||
<a class="link" href="history.html#boost_integer.history.1_42_0">1.42.0</a>
|
<a class="link" href="history.html#boost_integer.history.1_42_0">1.42.0</a>
|
||||||
</h5>
|
</h5>
|
||||||
<div class="itemizedlist"><ul type="disc">
|
<div class="itemizedlist"><ul type="disc">
|
||||||
@ -55,7 +55,7 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul></div>
|
</ul></div>
|
||||||
<a name="boost_integer.history.1_32_0"></a><h5>
|
<a name="boost_integer.history.1_32_0"></a><h5>
|
||||||
<a name="id773649"></a>
|
<a name="id768590"></a>
|
||||||
<a class="link" href="history.html#boost_integer.history.1_32_0">1.32.0</a>
|
<a class="link" href="history.html#boost_integer.history.1_32_0">1.32.0</a>
|
||||||
</h5>
|
</h5>
|
||||||
<div class="itemizedlist"><ul type="disc"><li>
|
<div class="itemizedlist"><ul type="disc"><li>
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">LeastInt</span><span class="special">></span>
|
</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">LeastInt</span><span class="special">></span>
|
||||||
<span class="keyword">struct</span> <span class="identifier">int_fast_t</span>
|
<span class="keyword">struct</span> <span class="identifier">int_fast_t</span>
|
||||||
<span class="special">{</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">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="special">};</span>
|
||||||
|
|
||||||
<span class="comment">// signed
|
<span class="comment">// signed
|
||||||
@ -115,13 +115,12 @@
|
|||||||
to <code class="literal">int</code> objects before processing. The input type, passed
|
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
|
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
|
<code class="literal">bool</code>. Unsigned integral types can be used, as well as
|
||||||
signed integral types, despite the name. The output type is given as the
|
signed integral types. The output type is given as the nested type <code class="literal">fast</code>.
|
||||||
class member <code class="literal">fast</code>.
|
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<span class="bold"><strong>Implementation Notes:</strong></span> By default, the output
|
<span class="bold"><strong>Implementation Notes:</strong></span> By default, the output
|
||||||
type is identical to the input type. Eventually, this code's implementation
|
type is identical to the input type. Eventually, this code's implementation
|
||||||
should be conditionalized for each platform to give accurate mappings between
|
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
|
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
|
is no guarantee that the output type actually is easier to manipulate than
|
||||||
the input type.
|
the input type.
|
||||||
@ -135,12 +134,12 @@
|
|||||||
The <code class="literal">int_t</code>, <code class="literal">uint_t</code>, <code class="literal">int_max_value_t</code>,
|
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
|
<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
|
templates find the most appropiate built-in integral type for the given template
|
||||||
parameter. This type is given by the class member <code class="literal">least</code>.
|
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 class member
|
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.
|
<code class="literal">fast</code>. The following table describes each template's criteria.
|
||||||
</p>
|
</p>
|
||||||
<div class="table">
|
<div class="table">
|
||||||
<a name="id768468"></a><p class="title"><b>Table 1. Criteria for the Sized Type Class Templates</b></p>
|
<a name="id764075"></a><p class="title"><b>Table 1. Criteria for the Sized Type Class Templates</b></p>
|
||||||
<div class="table-contents"><table class="table" summary="Criteria for the Sized Type Class Templates">
|
<div class="table-contents"><table class="table" summary="Criteria for the Sized Type Class Templates">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col>
|
<col>
|
||||||
@ -162,33 +161,91 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
<code class="literal">boost::int_t<N></code>
|
<code class="literal">boost::int_t<N>::least</code>
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
The smallest built-in signed integral type with at least <span class="emphasis"><em>N</em></span>
|
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.
|
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
|
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>
|
of bits in the largest integer type.
|
||||||
is defined <span class="bold"><strong>only</strong></span> if there is a type
|
|
||||||
with exactly N bits.
|
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
<code class="literal">boost::uint_t<N></code>
|
<code class="literal">boost::int_t<N>::fast</code>
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
The smallest built-in unsigned integral type with at least <span class="emphasis"><em>N</em></span>
|
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<N>::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<N>::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<N>::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<N>::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
|
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
|
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
|
integer type. Note that the member <span class="emphasis"><em>exact</em></span> is defined
|
||||||
<span class="bold"><strong>only</strong></span> if there is a type with exactly
|
<span class="bold"><strong>only</strong></span> if there exists a type with exactly
|
||||||
N bits.
|
N bits.
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
@ -196,45 +253,87 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
<code class="literal">boost::int_max_value_t<V></code>
|
<code class="literal">boost::int_max_value_t<V>::last</code>
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
The smallest built-in signed integral type that can hold all the values
|
The smallest, built-in, signed integral type that can hold all the
|
||||||
in the inclusive range <span class="emphasis"><em>0 - V</em></span>. The parameter should
|
values in the inclusive range <span class="emphasis"><em>0 - V</em></span>. The parameter
|
||||||
be a positive number.
|
should be a positive number.
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
<code class="literal">boost::int_min_value_t<V></code>
|
<code class="literal">boost::int_max_value_t<V>::fast</code>
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
The smallest built-in signed integral type that can hold all the values
|
The easiest-to-manipulate, built-in, signed integral type that can
|
||||||
in the inclusive range <span class="emphasis"><em>V-0</em></span>. The parameter should
|
hold all the values in the inclusive range <span class="emphasis"><em>0 - V</em></span>.
|
||||||
be a negative number.
|
The parameter should be a positive number.
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
<code class="literal">boost::uint_value_t<V></code>
|
<code class="literal">boost::int_min_value_t<V>::least</code>
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
The smallest built-in unsigned integral type that can hold all positive
|
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<V>::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<V>::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
|
values up to and including <span class="emphasis"><em>V</em></span>. The parameter should
|
||||||
be a positive number.
|
be a positive number.
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<p>
|
||||||
|
<code class="literal">boost::uint_value_t<V>::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>
|
</tbody>
|
||||||
</table></div>
|
</table></div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||||
<title>Compile time log2 Calculation</title>
|
<title>Compile Time log2 Calculation</title>
|
||||||
<link rel="stylesheet" href="../../../../../doc/html/boostbook.css" type="text/css">
|
<link rel="stylesheet" href="../../../../../doc/html/boostbook.css" type="text/css">
|
||||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||||
@ -24,12 +24,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="section" lang="en">
|
<div class="section" lang="en">
|
||||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
<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>
|
<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>
|
</h2></div></div></div>
|
||||||
<div class="toc"><dl>
|
<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.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.usage">Usage</a></span></dt>
|
||||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.example">Example</a></span></dt>
|
|
||||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.demonstration_program">Demonstration
|
<dt><span class="section"><a href="log2.html#boost_integer.log2.demonstration_program">Demonstration
|
||||||
Program</a></span></dt>
|
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.rationale">Rationale</a></span></dt>
|
||||||
@ -75,7 +74,7 @@
|
|||||||
The <code class="literal">boost::static_log2</code> class template takes one template
|
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>.
|
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 template only defines one member, <code class="literal">value</code>, which gives
|
||||||
the truncated base-two logarithm of the template argument.
|
the truncated, base-two logarithm of the template argument.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Since the logarithm of zero, for any base, is undefined, there is a specialization
|
Since the logarithm of zero, for any base, is undefined, there is a specialization
|
||||||
@ -99,38 +98,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="section" lang="en">
|
<div class="section" lang="en">
|
||||||
<div class="titlepage"><div><div><h3 class="title">
|
<div class="titlepage"><div><div><h3 class="title">
|
||||||
<a name="boost_integer.log2.example"></a><a class="link" href="log2.html#boost_integer.log2.example" title="Example">Example</a>
|
|
||||||
</h3></div></div></div>
|
|
||||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="string">"boost/integer/static_log2.hpp"</span>
|
|
||||||
|
|
||||||
|
|
||||||
<span class="keyword">template</span> <span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">static_log2_argument_type</span> <span class="identifier">value</span> <span class="special">></span>
|
|
||||||
<span class="keyword">bool</span> <span class="identifier">is_it_what</span><span class="special">()</span>
|
|
||||||
<span class="special">{</span>
|
|
||||||
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">static_log2</span><span class="special"><</span><span class="identifier">value</span><span class="special">></span> <span class="identifier">lb_type</span><span class="special">;</span>
|
|
||||||
|
|
||||||
<span class="keyword">int</span> <span class="identifier">temp</span> <span class="special">=</span> <span class="identifier">lb_type</span><span class="special">::</span><span class="identifier">value</span><span class="special">;</span>
|
|
||||||
<span class="comment">//...
|
|
||||||
</span> <span class="keyword">return</span> <span class="special">(</span><span class="identifier">temp</span> <span class="special">%</span> <span class="number">2</span><span class="special">)</span> <span class="special">!=</span> <span class="number">0</span><span class="special">;</span>
|
|
||||||
<span class="special">}</span>
|
|
||||||
|
|
||||||
<span class="comment">//...
|
|
||||||
</span>
|
|
||||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
|
||||||
<span class="special">{</span>
|
|
||||||
<span class="keyword">bool</span> <span class="identifier">temp</span> <span class="special">=</span> <span class="identifier">is_it_what</span><span class="special"><</span><span class="number">2000</span><span class="special">>();</span>
|
|
||||||
<span class="comment">//...
|
|
||||||
</span><span class="preprocessor"># if</span> <span class="number">0</span>
|
|
||||||
<span class="identifier">temp</span> <span class="special">=</span> <span class="identifier">is_it_what</span><span class="special"><</span><span class="number">0</span><span class="special">>();</span> <span class="comment">// would give an error
|
|
||||||
</span><span class="preprocessor"># endif</span>
|
|
||||||
<span class="comment">//...
|
|
||||||
</span> <span class="identifier">temp</span> <span class="special">=</span> <span class="identifier">is_it_what</span><span class="special"><</span><span class="number">24</span><span class="special">>();</span>
|
|
||||||
<span class="comment">//...
|
|
||||||
</span><span class="special">}</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
<div class="section" lang="en">
|
|
||||||
<div class="titlepage"><div><div><h3 class="title">
|
|
||||||
<a name="boost_integer.log2.demonstration_program"></a><a class="link" href="log2.html#boost_integer.log2.demonstration_program" title="Demonstration Program">Demonstration
|
<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>
|
Program</a>
|
||||||
</h3></div></div></div>
|
</h3></div></div></div>
|
||||||
@ -150,7 +117,7 @@
|
|||||||
can be considered the highest power-of-two in a value, which corresponds
|
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
|
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
|
position could be used in generic programming, which requires the position
|
||||||
to be statically (<span class="emphasis"><em>i.e.</em></span> at compile-time) available.
|
to be available statically (<span class="emphasis"><em>i.e.</em></span> at compile-time).
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" lang="en">
|
<div class="section" lang="en">
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||||
<link rel="up" 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="prev" href="integer.html" title="Integer Type Selection">
|
||||||
<link rel="next" href="log2.html" title="Compile time log2 Calculation">
|
<link rel="next" href="log2.html" title="Compile Time log2 Calculation">
|
||||||
</head>
|
</head>
|
||||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||||
<table cellpadding="2" width="100%"><tr>
|
<table cellpadding="2" width="100%"><tr>
|
||||||
@ -105,7 +105,7 @@
|
|||||||
of <code class="literal">high_bit_mask_t</code>.
|
of <code class="literal">high_bit_mask_t</code>.
|
||||||
</p>
|
</p>
|
||||||
<div class="table">
|
<div class="table">
|
||||||
<a name="id769480"></a><p class="title"><b>Table 2. Members of the `boost::high_bit_mask_t` Class Template</b></p>
|
<a name="id765275"></a><p class="title"><b>Table 2. Members of the `boost::high_bit_mask_t` Class Template</b></p>
|
||||||
<div class="table-contents"><table class="table" summary="Members of the `boost::high_bit_mask_t` Class Template">
|
<div class="table-contents"><table class="table" summary="Members of the `boost::high_bit_mask_t` Class Template">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col>
|
<col>
|
||||||
@ -132,7 +132,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
The smallest unsigned built-in type that supports the given bit position.
|
The smallest, unsigned, built-in type that supports the given bit position.
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -144,7 +144,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
The quick-to-manipulate analog of <code class="literal">least</code>.
|
The easiest-to-manipulate analog of <code class="literal">least</code>.
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -156,7 +156,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
A <code class="literal">least</code> constant of the desired bit-masking value.
|
A <code class="literal">least</code> constant of the value 2<sup>Bit</sup>.
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -197,15 +197,14 @@
|
|||||||
</h3></div></div></div>
|
</h3></div></div></div>
|
||||||
<p>
|
<p>
|
||||||
The <code class="literal">boost::low_bits_mask_t</code> class template provides constants
|
The <code class="literal">boost::low_bits_mask_t</code> class template provides constants
|
||||||
for bit masks representing the lowest bits of a certain amount. The masks
|
for bit masks equivalent to the value (2<sup>Bits</sup> - 1), where <code class="literal">Bits</code>
|
||||||
are equivalent to the value (2<sup>Bits</sup> - 1), where <code class="literal">Bits</code> is
|
is the template parameter. The parameter <code class="literal">Bits</code> must be
|
||||||
the template parameter. The bit amount must be a nonnegative number from
|
a non-negative integer from zero to <span class="emphasis"><em>Max</em></span>, where Max is
|
||||||
zero to <span class="emphasis"><em>Max</em></span>, where Max is the number of bits supported
|
the number of bits supported by the largest, unsigned, built-in integral
|
||||||
by the largest unsigned built-in integral type. The following table describes
|
type. The following table describes the members of <code class="literal">low_bits_mask_t</code>.
|
||||||
the members of an instantiation of <code class="literal">low_bits_mask_t</code>.
|
|
||||||
</p>
|
</p>
|
||||||
<div class="table">
|
<div class="table">
|
||||||
<a name="id769682"></a><p class="title"><b>Table 3. Members of the [^boost::low_bits_mask_t] Class Template</b></p>
|
<a name="id765484"></a><p class="title"><b>Table 3. Members of the [^boost::low_bits_mask_t] Class Template</b></p>
|
||||||
<div class="table-contents"><table class="table" summary="Members of the [^boost::low_bits_mask_t] Class Template">
|
<div class="table-contents"><table class="table" summary="Members of the [^boost::low_bits_mask_t] Class Template">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col>
|
<col>
|
||||||
@ -232,7 +231,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
The smallest unsigned built-in type that supports the given bit count.
|
The smallest, unsigned built-in type that supports the given bit count.
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -244,7 +243,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
The quick-to-manipulate analog of <code class="literal">least</code>.
|
The easiest-to-manipulate analog of <code class="literal">least</code>.
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||||
<link rel="up" 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="prev" href="log2.html" title="Compile Time log2 Calculation">
|
||||||
<link rel="next" href="history.html" title="History">
|
<link rel="next" href="history.html" title="History">
|
||||||
</head>
|
</head>
|
||||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||||
@ -71,10 +71,10 @@
|
|||||||
</h3></div></div></div>
|
</h3></div></div></div>
|
||||||
<p>
|
<p>
|
||||||
The four class templates provide the combinations for finding the minimum
|
The four class templates provide the combinations for finding the minimum
|
||||||
or maximum of two signed or <code class="literal">unsigned</code> (<code class="literal">long</code>)
|
or maximum of two <code class="literal">signed</code> or <code class="literal">unsigned</code>
|
||||||
parameters, Value1 and Value2, at compile-time. Each template has a single
|
(<code class="literal">long</code>) parameters, <span class="emphasis"><em>Value1</em></span> and <span class="emphasis"><em>Value2</em></span>,
|
||||||
static data member, <code class="literal">value</code>, which is set to the respective
|
at compile-time. Each template has a single static data member, <code class="literal">value</code>,
|
||||||
minimum or maximum of the template's parameters.
|
which is set to the respective minimum or maximum of the template's parameters.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" lang="en">
|
<div class="section" lang="en">
|
||||||
|
@ -70,6 +70,7 @@
|
|||||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
||||||
<span class="keyword">class</span> <span class="identifier">integer_traits</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span>
|
<span class="keyword">class</span> <span class="identifier">integer_traits</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span>
|
||||||
<span class="special">{</span>
|
<span class="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="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 class="comment">//
|
||||||
</span> <span class="comment">// These members are defined only if T is a built-in
|
</span> <span class="comment">// These members are defined only if T is a built-in
|
||||||
@ -87,9 +88,9 @@
|
|||||||
</h3></div></div></div>
|
</h3></div></div></div>
|
||||||
<p>
|
<p>
|
||||||
Template class <code class="literal">integer_traits</code> is derived from <code class="literal">std::numeric_limits</code>.
|
Template class <code class="literal">integer_traits</code> is derived from <code class="literal">std::numeric_limits</code>.
|
||||||
In general, it adds the single <code class="literal">bool</code> member <code class="literal">is_integral</code>
|
The primary specialization adds the single <code class="literal">bool</code> member
|
||||||
with the compile-time constant value <code class="literal">false</code>. However, for
|
<code class="literal">is_integral</code> with the compile-time constant value <code class="literal">false</code>.
|
||||||
all integral types <code class="literal">T</code> (std::3.9.1/7 [basic.fundamental]),
|
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
|
there are specializations provided with the following compile-time constants
|
||||||
defined:
|
defined:
|
||||||
</p>
|
</p>
|
||||||
@ -171,11 +172,11 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table></div>
|
</table></div>
|
||||||
<p>
|
<p>
|
||||||
Note: A flag <code class="literal">is_integral</code> is provided, because a user-defined
|
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<>::is_integer
|
integer class should specialize <code class="literal">std::numeric_limits<>::is_integer
|
||||||
= true</code>, nonetheless compile-time constants <code class="literal">const_min</code>
|
= true</code>, while compile-time constants <code class="literal">const_min</code>
|
||||||
and <code class="literal">const_max</code> cannot be provided for that user-defined
|
and <code class="literal">const_max</code> are not provided for that user-defined class,
|
||||||
class.
|
unless boost::integer_traits is also specialized.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" lang="en">
|
<div class="section" lang="en">
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
<div><p class="copyright">Copyright © 2001 -2009 Beman Dawes, Daryle Walker, Gennaro Prota,
|
<div><p class="copyright">Copyright © 2001 -2009 Beman Dawes, Daryle Walker, Gennaro Prota,
|
||||||
John Maddock</p></div>
|
John Maddock</p></div>
|
||||||
<div><div class="legalnotice">
|
<div><div class="legalnotice">
|
||||||
<a name="id758110"></a><p>
|
<a name="id753741"></a><p>
|
||||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
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>)
|
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>
|
</p>
|
||||||
@ -56,7 +56,7 @@
|
|||||||
<dt><span class="section"><a href="boost_integer/traits.html"> Integer Traits</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/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/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/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/minmax.html"> Compile time min/max calculation</a></span></dt>
|
||||||
<dt><span class="section"><a href="boost_integer/history.html"> History</a></span></dt>
|
<dt><span class="section"><a href="boost_integer/history.html"> History</a></span></dt>
|
||||||
</dl>
|
</dl>
|
||||||
@ -66,7 +66,15 @@
|
|||||||
<a name="boost_integer.overview"></a><a class="link" href="index.html#boost_integer.overview" title="Overview"> Overview</a>
|
<a name="boost_integer.overview"></a><a class="link" href="index.html#boost_integer.overview" title="Overview"> Overview</a>
|
||||||
</h2></div></div></div>
|
</h2></div></div></div>
|
||||||
<p>
|
<p>
|
||||||
Boost.Integer consists of the following components:
|
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 <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>
|
</p>
|
||||||
<div class="informaltable"><table class="table">
|
<div class="informaltable"><table class="table">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
@ -191,7 +199,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
<a class="link" href="boost_integer/log2.html" title="Compile time log2 Calculation">Compile time log2 Calculation</a>.
|
<a class="link" href="boost_integer/log2.html" title="Compile Time log2 Calculation">Compile time log2 Calculation</a>.
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@ -229,7 +237,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||||
<td align="left"><p><small>Last revised: November 27, 2009 at 11:11:24 GMT</small></p></td>
|
<td align="left"><p><small>Last revised: November 28, 2009 at 17:06:38 GMT</small></p></td>
|
||||||
<td align="right"><div class="copyright-footer"></div></td>
|
<td align="right"><div class="copyright-footer"></div></td>
|
||||||
</tr></table>
|
</tr></table>
|
||||||
<hr>
|
<hr>
|
||||||
|
182
doc/integer.qbk
182
doc/integer.qbk
@ -15,7 +15,13 @@
|
|||||||
|
|
||||||
[section:overview Overview]
|
[section:overview Overview]
|
||||||
|
|
||||||
Boost.Integer consists of the following components:
|
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
|
[table
|
||||||
[[Component][Header][Purpose]]
|
[[Component][Header][Purpose]]
|
||||||
@ -71,9 +77,9 @@ Boost.Integer consists of the following components:
|
|||||||
The header [^[@../../../../boost/cstdint.hpp <boost/cstdint.hpp>]] provides the typedef's useful
|
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.
|
for writing portable code that requires certain integer widths. All typedef's are in namespace boost.
|
||||||
|
|
||||||
The specifications are based on the ISO/IEC 9899:1999 C Language standard header <stdint.h>.
|
The 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,
|
The 64-bit types required by the C standard are ['not required] in the boost header,
|
||||||
and may not be supplied in all implementations, because [^long long] is not [yet] included in the C++ standard.
|
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.
|
See [@../../test/cstdint_test.cpp cstdint_test.cpp] for a test program.
|
||||||
|
|
||||||
@ -82,9 +88,9 @@ See [@../../test/cstdint_test.cpp cstdint_test.cpp] for a test program.
|
|||||||
[section:rationale Rationale]
|
[section:rationale Rationale]
|
||||||
|
|
||||||
The organization of the Boost.Integer headers and classes is designed to take advantage of <stdint.h> types from the
|
The organization of the Boost.Integer headers and classes is designed to take advantage of <stdint.h> types from the
|
||||||
1999 C standard without resorting to undefined behavior in terms of the 1998 C++ standard.
|
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]
|
The header <boost/cstdint.hpp> makes the standard integer types safely available in namespace [^boost]
|
||||||
without placing any names in namespace [^std]. As always, the intension is to complement rather than compete
|
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>,
|
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.
|
then <boost/cstdint.hpp> will continue to function, but will become redundant and may be safely deprecated.
|
||||||
|
|
||||||
@ -111,8 +117,9 @@ The typedef [^int#_t], with # replaced by the width, designates a signed integer
|
|||||||
for example [^int8_t] denotes an 8-bit signed integer type. Similarly, the typedef [^uint#_t] designates an unsigned
|
for example [^int8_t] denotes an 8-bit signed integer type. Similarly, the typedef [^uint#_t] designates an unsigned
|
||||||
integer type of exactly # bits.
|
integer type of exactly # bits.
|
||||||
|
|
||||||
These types are optional. However, if an implementation provides integer types with widths of 8, 16, 32, or 64 bits,
|
These types are optional. However, if a platform supports integer types with widths of
|
||||||
it shall define the corresponding typedef names.
|
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`.
|
The absence of int64_t and uint64_t is indicated by the macro `BOOST_NO_INT64_T`.
|
||||||
|
|
||||||
@ -122,11 +129,11 @@ The absence of int64_t and uint64_t is indicated by the macro `BOOST_NO_INT64_T`
|
|||||||
|
|
||||||
The typedef [^int_least#_t], with # replaced by the width, designates a signed integer type with a width
|
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.
|
of at least # bits, such that no signed integer type with lesser size has at least the specified width.
|
||||||
Thus, [^int_least32_t] denotes a signed integer type with a width of at least 32 bits.
|
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,
|
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.
|
such that no unsigned integer type with lesser size has at least the specified width.
|
||||||
|
|
||||||
Required minimum-width integer types:
|
The following minimum-width integer types are provided for all platforms:
|
||||||
|
|
||||||
* [^int_least8_t]
|
* [^int_least8_t]
|
||||||
* [^int_least16_t]
|
* [^int_least16_t]
|
||||||
@ -135,12 +142,11 @@ Required minimum-width integer types:
|
|||||||
* [^uint_least16_t]
|
* [^uint_least16_t]
|
||||||
* [^uint_least32_t]
|
* [^uint_least32_t]
|
||||||
|
|
||||||
The types:
|
The following types are available only if, after including <boost/cstdint.hpp>, the macro BOOST_NO_INT64_T is not defined:
|
||||||
|
|
||||||
* [^int_least64_t]
|
* [^int_least64_t]
|
||||||
* [^uint_least64_t]
|
* [^uint_least64_t]
|
||||||
|
|
||||||
Are available only if, after inclusion of [^<boost/cstdint.hpp>] the macro `BOOST_NO_INT64_T` is ['[*not defined]].
|
|
||||||
|
|
||||||
All other minimum-width integer types are optional.
|
All other minimum-width integer types are optional.
|
||||||
|
|
||||||
@ -155,7 +161,7 @@ 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
|
There is no guarantee that these types are fastest for all purposes. In any case, however, they satisfy
|
||||||
the signedness and width requirements.
|
the signedness and width requirements.
|
||||||
|
|
||||||
Required fastest minimum-width integer types:
|
The following fastest minimum-width integer types are provided for all platforms:
|
||||||
|
|
||||||
* [^int_fast8_t]
|
* [^int_fast8_t]
|
||||||
* [^int_fast16_t]
|
* [^int_fast16_t]
|
||||||
@ -164,13 +170,11 @@ Required fastest minimum-width integer types:
|
|||||||
* [^uint_fast16_t]
|
* [^uint_fast16_t]
|
||||||
* [^uint_fast32_t]
|
* [^uint_fast32_t]
|
||||||
|
|
||||||
The types:
|
The following types are available only if, after including <boost/cstdint.hpp>, the macro BOOST_NO_INT64_T is not defined:
|
||||||
|
|
||||||
* [^int_fast64_t]
|
* [^int_fast64_t]
|
||||||
* [^uint_fast64_t]
|
* [^uint_fast64_t]
|
||||||
|
|
||||||
Are available only if, after inclusion of [^<boost/cstdint.hpp>] the macro `BOOST_NO_INT64_T` is ['[*not defined]].
|
|
||||||
|
|
||||||
All other fastest minimum-width integer types are optional.
|
All other fastest minimum-width integer types are optional.
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
@ -181,7 +185,7 @@ The typedef [^intmax_t ]designates a signed integer type capable of representing
|
|||||||
|
|
||||||
The typedef [^uintmax_t] designates an unsigned integer type capable of representing any value of any unsigned integer type.
|
The typedef [^uintmax_t] designates an unsigned integer type capable of representing any value of any unsigned integer type.
|
||||||
|
|
||||||
These types are required.
|
These types are provided for all platforms.
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
[endsect]
|
[endsect]
|
||||||
@ -216,6 +220,7 @@ The template class [^integer_traits] addresses this problem.
|
|||||||
template<class T>
|
template<class T>
|
||||||
class integer_traits : public std::numeric_limits<T>
|
class integer_traits : public std::numeric_limits<T>
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
static const bool is_integral = false;
|
static const bool is_integral = false;
|
||||||
//
|
//
|
||||||
// These members are defined only if T is a built-in
|
// These members are defined only if T is a built-in
|
||||||
@ -230,7 +235,7 @@ The template class [^integer_traits] addresses this problem.
|
|||||||
|
|
||||||
[section Description]
|
[section Description]
|
||||||
|
|
||||||
Template class [^integer_traits] is derived from [^std::numeric_limits]. In general, it adds the single
|
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].
|
[^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
|
However, for all integral types [^T] (std::3.9.1/7 [basic.fundamental]), there are specializations
|
||||||
provided with the following compile-time constants defined:
|
provided with the following compile-time constants defined:
|
||||||
@ -242,9 +247,9 @@ provided with the following compile-time constants defined:
|
|||||||
[[[^const_max]][[^T]][equivalent to [^std::numeric_limits<T>::max()]]]
|
[[[^const_max]][[^T]][equivalent to [^std::numeric_limits<T>::max()]]]
|
||||||
]
|
]
|
||||||
|
|
||||||
Note: A flag [^is_integral] is provided, because a user-defined integer class should specialize
|
Note: The /is_integral/ flag is provided, because a user-defined integer class should specialize
|
||||||
[^std::numeric_limits<>::is_integer = true], nonetheless compile-time constants
|
[^std::numeric_limits<>::is_integer = true], while compile-time constants
|
||||||
[^const_min] and [^const_max] cannot be provided for that user-defined class.
|
[^const_min] and [^const_max] are not provided for that user-defined class, unless boost::integer_traits is also specialized.
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
@ -275,7 +280,7 @@ This facility is particularly useful for solving generic programming problems.
|
|||||||
template<typename LeastInt>
|
template<typename LeastInt>
|
||||||
struct int_fast_t
|
struct int_fast_t
|
||||||
{
|
{
|
||||||
typedef ``['implementation-defined-type]`` fast;
|
typedef ``['implementation-defined-type]`` type;
|
||||||
};
|
};
|
||||||
|
|
||||||
// signed
|
// signed
|
||||||
@ -330,12 +335,12 @@ The [^int_fast_t] class template maps its input type to the next-largest type th
|
|||||||
can manipulate the easiest, or to itself if the input type is already an easy-to-manipulate type.
|
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.
|
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].
|
The input type, passed as the only template parameter, must be a built-in integral type, except [^bool].
|
||||||
Unsigned integral types can be used, as well as signed integral types, despite the name.
|
Unsigned integral types can be used, as well as signed integral types.
|
||||||
The output type is given as the class member [^fast].
|
The output type is given as the nested type [^fast].
|
||||||
|
|
||||||
[*Implementation Notes:]
|
[*Implementation Notes:]
|
||||||
By default, the output type is identical to the input type. Eventually, this code's implementation should
|
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
|
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.
|
built-in types. Also, there is no guarantee that the output type actually is easier to manipulate than the input type.
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
@ -344,7 +349,7 @@ built-in types. Also, there is no guarantee that the output type actually is eas
|
|||||||
|
|
||||||
The [^int_t], [^uint_t], [^int_max_value_t], [^int_min_value_t], and [^uint_value_t] class templates find
|
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
|
the most appropiate built-in integral type for the given template parameter. This type is given by the
|
||||||
class member [^least]. The easiest-to-manipulate version of that type is given by the class member [^fast].
|
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.
|
The following table describes each template's criteria.
|
||||||
|
|
||||||
[table Criteria for the Sized Type Class Templates
|
[table Criteria for the Sized Type Class Templates
|
||||||
@ -352,33 +357,71 @@ The following table describes each template's criteria.
|
|||||||
[Class Template][Template Parameter Mapping]
|
[Class Template][Template Parameter Mapping]
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
[[^boost::int_t<N>]]
|
[[^boost::int_t<N>::least]]
|
||||||
[The smallest built-in signed integral type with at least /N/ bits, including the sign bit.
|
[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
|
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
|
larger than the number of bits in the largest integer type.]
|
||||||
[*only] if there is a type with exactly N bits.]
|
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
[[^boost::uint_t<N>]]
|
[[^boost::int_t<N>::fast]]
|
||||||
[The smallest built-in unsigned integral type with at least /N/ bits.
|
[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
|
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.
|
parameter is larger than the number of bits in the largest integer type.
|
||||||
Note that the member /exact/ is defined
|
Note that the member /exact/ is defined
|
||||||
[*only] if there is a type with exactly N bits.]
|
[*only] if there exists a type with exactly N bits.]
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
[[^boost::int_max_value_t<V>]]
|
[[^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 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.]
|
The parameter should be a positive number.]
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
[[^boost::int_min_value_t<V>]]
|
[[^boost::int_max_value_t<V>::fast]]
|
||||||
[The smallest built-in signed integral type that can hold all the values in the inclusive range ['V-0].
|
[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.]
|
The parameter should be a negative number.]
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
[[^boost::uint_value_t<V>]]
|
[[^boost::int_min_value_t<V>::fast]]
|
||||||
[The smallest built-in unsigned integral type that can hold all positive values
|
[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.]
|
up to and including /V/. The parameter should be a positive number.]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
@ -500,9 +543,9 @@ the members of an instantiation of [^high_bit_mask_t].
|
|||||||
|
|
||||||
[table Members of the `boost::high_bit_mask_t` Class Template
|
[table Members of the `boost::high_bit_mask_t` Class Template
|
||||||
[[Member][Meaning]]
|
[[Member][Meaning]]
|
||||||
[[[^least]][The smallest unsigned built-in type that supports the given bit position.]]
|
[[[^least]][The smallest, unsigned, built-in type that supports the given bit position.]]
|
||||||
[[[^fast]][The quick-to-manipulate analog of [^least].]]
|
[[[^fast]][The easiest-to-manipulate analog of [^least].]]
|
||||||
[[[^high_bit]][A [^least] constant of the desired bit-masking value.]]
|
[[[^high_bit]][A [^least] constant of the value 2[super Bit].]]
|
||||||
[[[^high_bit_fast]][A [^fast] analog of [^high_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.]]
|
[[[^bit_position]][The value of the template parameter, in case its needed from a renamed instantiation of the class template.]]
|
||||||
]
|
]
|
||||||
@ -511,16 +554,16 @@ the members of an instantiation of [^high_bit_mask_t].
|
|||||||
|
|
||||||
[section Group Bit-Mask Class Template]
|
[section Group Bit-Mask Class Template]
|
||||||
|
|
||||||
The [^boost::low_bits_mask_t] class template provides constants for bit masks representing the lowest
|
The [^boost::low_bits_mask_t] class template provides constants for bit masks
|
||||||
bits of a certain amount. The masks are equivalent to the value (2[super Bits] - 1),
|
equivalent to the value (2[super Bits] - 1), where [^Bits] is the template parameter.
|
||||||
where [^Bits] is the template parameter. The bit amount must be a nonnegative number from
|
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.
|
zero to ['Max], where Max is the number of bits supported by the largest, unsigned, built-in integral type.
|
||||||
The following table describes the members of an instantiation of [^low_bits_mask_t].
|
The following table describes the members of [^low_bits_mask_t].
|
||||||
|
|
||||||
[table Members of the [^boost::low_bits_mask_t] Class Template
|
[table Members of the [^boost::low_bits_mask_t] Class Template
|
||||||
[[Member][Meaning]]
|
[[Member][Meaning]]
|
||||||
[[[^least]][The smallest unsigned built-in type that supports the given bit count.]]
|
[[[^least]][The smallest, unsigned built-in type that supports the given bit count.]]
|
||||||
[[[^fast]][The quick-to-manipulate analog of [^least].]]
|
[[[^fast]][The easiest-to-manipulate analog of [^least].]]
|
||||||
[[[^sig_bits]][A [^least] constant of the desired bit-masking value.]]
|
[[[^sig_bits]][A [^least] constant of the desired bit-masking value.]]
|
||||||
[[[^sig_bits_fast]][A [^fast] analog of [^sig_bits].]]
|
[[[^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.]]
|
[[[^bit_count]][The value of the template parameter, in case its needed from a renamed instantiation of the class template.]]
|
||||||
@ -581,7 +624,7 @@ The author of the Boost bit mask class templates is [@http://www.boost.org/peopl
|
|||||||
[endsect]
|
[endsect]
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[section:log2 Compile time log2 Calculation]
|
[section:log2 Compile Time log2 Calculation]
|
||||||
|
|
||||||
The class template in [@../../../../boost/integer/static_log2.hpp <boost/integer/static_log2.hpp>]
|
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.
|
determines the position of the highest bit in a given value. This facility is useful for solving generic programming problems.
|
||||||
@ -616,7 +659,7 @@ determines the position of the highest bit in a given value. This facility is us
|
|||||||
|
|
||||||
The [^boost::static_log2] class template takes one template parameter, a value of type
|
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
|
[^static_log2_argument_type]. The template only defines one member, [^value], which gives the
|
||||||
truncated base-two logarithm of the template argument.
|
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]
|
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
|
for a template argument of zero. This specialization has no members, so an attempt to use the base-two
|
||||||
@ -629,37 +672,6 @@ Note:
|
|||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[section Example]
|
|
||||||
|
|
||||||
#include "boost/integer/static_log2.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
template < boost::static_log2_argument_type value >
|
|
||||||
bool is_it_what()
|
|
||||||
{
|
|
||||||
typedef boost::static_log2<value> lb_type;
|
|
||||||
|
|
||||||
int temp = lb_type::value;
|
|
||||||
//...
|
|
||||||
return (temp % 2) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//...
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
bool temp = is_it_what<2000>();
|
|
||||||
//...
|
|
||||||
# if 0
|
|
||||||
temp = is_it_what<0>(); // would give an error
|
|
||||||
# endif
|
|
||||||
//...
|
|
||||||
temp = is_it_what<24>();
|
|
||||||
//...
|
|
||||||
}
|
|
||||||
|
|
||||||
[endsect]
|
|
||||||
|
|
||||||
[section Demonstration Program]
|
[section Demonstration Program]
|
||||||
|
|
||||||
The program [@../../test/static_log2_test.cpp static_log2_test.cpp] is a simplistic
|
The program [@../../test/static_log2_test.cpp static_log2_test.cpp] is a simplistic
|
||||||
@ -672,7 +684,7 @@ demonstration of the results from instantiating various examples of the binary l
|
|||||||
The base-two (binary) logarithm, abbreviated lb, function is occasionally used to give order-estimates
|
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,
|
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
|
which corresponds to the value's highest set bit (for binary integers). Sometimes the highest-bit position
|
||||||
could be used in generic programming, which requires the position to be statically (['i.e.] at compile-time) available.
|
could be used in generic programming, which requires the position to be available statically (['i.e.] at compile-time).
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
@ -719,8 +731,8 @@ for generic programming problems.
|
|||||||
|
|
||||||
[section Usage]
|
[section Usage]
|
||||||
|
|
||||||
The four class templates provide the combinations for finding the minimum or maximum of two signed or
|
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,
|
[^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.
|
[^value], which is set to the respective minimum or maximum of the template's parameters.
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
Reference in New Issue
Block a user