C++ Library Extensions 2022.12.09
To help learn modern C++ programming
016-debugging.cpp
Go to the documentation of this file.
1#include <tpf_output.hpp>
2
5
6template<typename Type1, typename Type2>
7Type1 divide(Type1 dividend, Type2 divisor)
8{
9 if(divisor == 0)
10 {
12
13 stream << "Division by Zero, divisor is " << divisor
14 << " is zero";
15
17 }
18 else
19 {
20 return dividend / divisor;
21 }
22}
23
24template<typename Type1, typename Type2, typename... Types>
25Type1 divide(Type1 dividend, Type2 divisor, Types... divisors)
26{
27 if constexpr(sizeof...(divisors)==0)
28 return divide(dividend, divisor);
29 else
30 return divide(divide(dividend, divisor), divisors...);
31}
32
33int main()
34{
35 try
36 {
37 auto rlt = divide(2*3*5, 3, 0);
38 stream << "Result = " << rlt << endl;
39
40 }
41 catch(tpf::debug_exception& e)
42 {
43 stream << e.what() << endl;
44
45 }
46}
tpf::sstream stream
auto endl
Type1 divide(Type1 dividend, Type2 divisor)
int main()
This class implements all debugging requirements for C++ Library Extension.
Definition: tpf_types.hpp:224
virtual const char * what() const noexcept override
Definition: tpf_types.hpp:246
std::string str() const
Definition: tpf_output.hpp:951
constexpr auto endl
Definition: tpf_output.hpp:973
Stream output operators << are implemented.
#define Tpf_ThrowDebugException(debug_message)
Throw a debug_exception with message as argument.
Definition: tpf_types.hpp:1416