-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex01_default_arithmetic.cpp
More file actions
48 lines (39 loc) · 1.33 KB
/
ex01_default_arithmetic.cpp
File metadata and controls
48 lines (39 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Example: ex01_default_arithmetic
*
* Purpose:
* Demonstrate the default primitive aliases and operator pipeline for
* arithmetic operations without custom policy overrides.
*
* Expected results:
* - All four operations (+, -, *, /) succeed through dispatcher.
* - The printed values match: sum=42, diff=38, prod=80, quot=20.
* - Program exits with code 0; otherwise prints an error and exits non-zero.
*/
#include <cstdint>
#include <iostream>
import mcpplibs.primitives;
using namespace mcpplibs::primitives;
int main() {
// Point 1: Use built-in primitive type aliases and framework operators.
using namespace mcpplibs::primitives::types;
using namespace mcpplibs::primitives::operators;
using value_t = I32<>;
// Prepare operands.
auto const a = value_t{40};
auto const b = value_t{2};
// Run the four arithmetic operators routed through dispatcher.
auto const sum = a + b;
auto const diff = a - b;
auto const prod = a * b;
auto const quot = a / b;
// Validate all dispatches succeeded.
if (!sum.has_value() || !diff.has_value() || !prod.has_value() ||
!quot.has_value()) {
std::cerr << "default arithmetic failed\n";
return 1;
}
std::cout << "sum=" << sum->value() << ", diff=" << diff->value()
<< ", prod=" << prod->value() << ", quot=" << quot->value() << '\n';
return 0;
}