mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-25 16:42:33 +00:00
112 lines
2.8 KiB
XML
112 lines
2.8 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.1//EN"
|
|
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
|
<section id="safe_numerics.safe_signed_range">
|
|
<title>safe_signed_range<boost::intmax_t MIN,
|
|
boost::intmax_tMAX></title>
|
|
|
|
<section>
|
|
<title>Description</title>
|
|
|
|
<para>This type holds a integer in the range [MIN, MAX]. It will throw a
|
|
<code>std::out_of_range</code> exception for operation which would result
|
|
in assigning an integer value outside of this range.</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Template Parameters</title>
|
|
|
|
<informaltable>
|
|
<tgroup cols="3">
|
|
<colspec align="left"/>
|
|
|
|
<colspec align="left" colwidth="3*"/>
|
|
|
|
<colspec align="left" colwidth="3*"/>
|
|
|
|
<thead>
|
|
<row>
|
|
<entry align="left">Parameter</entry>
|
|
|
|
<entry align="left">Requirements</entry>
|
|
|
|
<entry>Description</entry>
|
|
</row>
|
|
</thead>
|
|
|
|
<tbody>
|
|
<row>
|
|
<entry><code>MIN</code></entry>
|
|
|
|
<entry>must be an integer literal</entry>
|
|
|
|
<entry>The minimum integer value that this type may hold</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>MAX</code></entry>
|
|
|
|
<entry>must be an integer literal</entry>
|
|
|
|
<entry>The maximum integer value that this type may hold</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code/></entry>
|
|
|
|
<entry>MIN < MAX</entry>
|
|
|
|
<entry/>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Model of</title>
|
|
|
|
<para><link linkend="safe_numerics.numeric">Numeric</link></para>
|
|
|
|
<para>The usage of this type in an arithmetic expression will result in
|
|
another type fulfilling the <link
|
|
linkend="safe_numerics.numeric">Numeric</link> concept. </para>
|
|
|
|
<para>Operations on safe_signed_range will result in the same</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Header</title>
|
|
|
|
<para><filename><ulink url="../../include/safe_range.hpp">#include
|
|
<boost/safe_numerics/safe_range.hpp></ulink></filename></para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Example of use</title>
|
|
|
|
<programlisting>#include <safe/numeric/safe_range.hpp>
|
|
|
|
void f(){
|
|
boost::numeric::safe_signed_range<7, 24> i;
|
|
i = 0; // error
|
|
i = 9; // ok
|
|
i *= 9; // throws overflow exception
|
|
|
|
std::int8_t j = 4;
|
|
auto k = i + j;
|
|
// since i can vary between 7 and 24 and j can vary between 0 and 255
|
|
// the smallest unsigned integer which can hold the result std::int16_t
|
|
// j will be of type std::int16_t
|
|
}</programlisting>
|
|
</section>
|
|
|
|
<section>
|
|
<title>See Also</title>
|
|
|
|
<para><code>std::out_of_range</code></para>
|
|
|
|
<para><code>safe_unsigned_range</code></para>
|
|
</section>
|
|
</section>
|