C++ Library Extensions 2022.12.09
To help learn modern C++ programming
021-safe_type.cpp
Go to the documentation of this file.
1#include <tpf_safe_type.hpp>
2#include <tpf_output.hpp>
3
6
7namespace sft = tpf::safe_type;
8namespace tps = tpf::types;
9
11{
12 try
13 {
14 int a = sft::limits_min<int>;
15 int b = sft::limits_min<int>;
16
17 stream << a << " + " << b
18 << " = " << sft::safe_add(a, b) << endl;
19 }
20 catch(std::exception& e)
21 {
22 stream << e << endl;
23 }
24}
25
27{
28 try
29 {
30 int a = sft::;
31 int b = 3;
32
33 stream << a << " * " << b
34 << " = " << sft::safe_mul(a, b) << endl;
35 }
36 catch(std::exception& e)
37 {
38 stream << e << endl;
39 }
40}
41
42int main()
43{
44 // test_safe_add();
46}
tpf::sstream stream
void test_safe_mul()
auto endl
int main()
void test_safe_add()
Defines safe type operation.
types::enable_if_signed_integral_t< Type > safe_add(Type a, Type b)
Safe addition of the signed integral types.
types::enable_if_integral_t< Type > safe_mul(Type a, Type b)
Safe multiplication of integral types.
Type to string name conversions are defined.
Definition: 31-visit.cpp:7
constexpr auto endl
Definition: tpf_output.hpp:973
Stream output operators << are implemented.
This file implements safe arithmetic.