mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-23 03:52:23 +00:00
51 lines
1.6 KiB
XML
51 lines
1.6 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.automatic_policy">
|
|
<title>automatic</title>
|
|
|
|
<section>
|
|
<title>Description</title>
|
|
|
|
<para>This type contains the functions to return a type with sufficient
|
|
capacity to hold the result of a given arithmetic operation.</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Model of</title>
|
|
|
|
<para><link linkend="safe_numerics.promotion_policy">PromotionPolicy</link></para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Header</title>
|
|
|
|
<para><code><ulink url="../../include/automatic.hpp"><code>#include
|
|
<boost/safe_numerics/automatic.hpp> </code></ulink></code></para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Example of use</title>
|
|
|
|
<para>The following example illustrates the <code>automatic</code> type
|
|
being passed as a template parameter for the type
|
|
<code>safe<int></code>. </para>
|
|
|
|
<programlisting>#include <boost/safe_numerics/safe_integer.hpp>
|
|
#include <boost/safe_numerics/automatic.hpp>
|
|
|
|
int main(){
|
|
using namespace boost::numeric;
|
|
// use automatic promotion policy where C++ standard arithmetic might lead to incorrect results
|
|
using safe_t = safe<std::int8_t, automatic>;
|
|
|
|
// In such cases, there is no runtime overhead from using safe types.
|
|
safe_t x = 127;
|
|
safe_t y = 2;
|
|
auto z = x + y; // z is guarenteed correct without any runtime overhead or interrupt.
|
|
|
|
return 0;
|
|
}</programlisting>
|
|
</section>
|
|
</section>
|