mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-22 15:42:30 +00:00
improved TOC and chunking. This is complicated by the fact we that we desire different depths. put copies of boost logo in subdirectories
52 lines
1.6 KiB
XML
52 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.promotion_policies.automatic">
|
|
<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>
|