mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-22 03:32:24 +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
124 lines
3.4 KiB
XML
124 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>
|
|
|
|
<?dbhtml stop-chunking?>
|
|
|
|
<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>
|