mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-22 15:42:30 +00:00
a) made trap_exception work b) updated manual and examples to show how to use library to eliminate runtime penalty c) added in safe_literal d) made corrections of various types
122 lines
3.4 KiB
XML
122 lines
3.4 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.checked_integer_arithmetic">
|
|
<title>Checked Integer Arithmetic</title>
|
|
|
|
<section>
|
|
<title>Synopsis</title>
|
|
|
|
<programlisting>// safe casting on primitive types
|
|
template<class R, class T>
|
|
constexpr checked_result<R>
|
|
checked::cast(const T & t);
|
|
|
|
// safe addition on primitive types
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::add(const T & t, const U & u);
|
|
|
|
// safe subtraction on primitive types
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::subtract(const T & t, const U & u);
|
|
|
|
// safe multiplication on primitive types
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::multiply(const T & t, const U & u);
|
|
|
|
// safe division on unsafe types
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::divide(const T & t, const U & u);
|
|
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::divide_automatic(const T & t, const U & u);
|
|
|
|
// safe modulus on unsafe types
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::modulus(const T & t, const U & u);
|
|
|
|
// left shift
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::left_shift(const T & t, const U & u);
|
|
|
|
// right shift
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::right_shift(const T & t, const U & u);
|
|
|
|
// bitwise operations
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::bitwise_or(const T & t, const U & u);
|
|
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::bitwise_and(const T & t, const U & u);
|
|
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::bitwise_xor(const T & t, const U & u);
|
|
</programlisting>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Description</title>
|
|
|
|
<para>Perform binary operations on arithmetic types. Return either a valid
|
|
result or an error code. Under no circumstances should an incorrect result
|
|
be returned.</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Type requirements</title>
|
|
|
|
<para>All template parameters of the functions must model <link
|
|
linkend="safe_numerics.integer">Integer</link> type requirements.</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Complexity</title>
|
|
|
|
<para>Each function performs one and only one arithmetic operation</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Header</title>
|
|
|
|
<para><code>#include "checked.hpp" </code></para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Example of use</title>
|
|
|
|
<para>[A code fragment that illustrates how to use the function.]</para>
|
|
|
|
<programlisting>#include "checked.hpp"
|
|
|
|
checked_result<result_base_type> r = checked::multiply<int>(24, 42);
|
|
</programlisting>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Notes</title>
|
|
|
|
<para>Footnotes (if any) that are referred to by other parts of the
|
|
page.</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>See Also</title>
|
|
|
|
<para><link
|
|
linkend="safenumerics.checked_result">checked_result<typename
|
|
R></link></para>
|
|
</section>
|
|
</section>
|