Files
safe_numerics/doc/boostbook/automatic.xml
Robert Ramey 01a3af5cc3 progress on case study on motor.c
added intersection to interval
improved
2016-01-04 10:06:43 -08:00

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
&lt;boost/safe_numerics/automatic.hpp&gt; </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&lt;int&gt;</code>. </para>
<programlisting>#include &lt;boost/safe_numerics/safe_integer.hpp&gt;
#include &lt;boost/safe_numerics/automatic.hpp&gt;
int main(){
using namespace boost::numeric;
// use automatic promotion policy where C++ standard arithmetic might lead to incorrect results
using safe_t = safe&lt;std::int8_t, automatic&gt;;
// 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>