12345678910111213141516171819202122232425262728293031323334353637 |
- //#define CXXOMFORT_NOTICES 2
- #include <cxxomfort/base.hpp>
- #include <cxxomfort/numeric.hpp>
- #include <cxxomfort/cstdint.hpp>
- #include <limits>
- #include <string>
- #include <iostream>
- #include <cassert>
- void on_pointers (int i, int j) {
- using namespace std;
- char const* text = "0123456789";
- char const* p = text + i;
- char const* q = text + j;
- char const* r = midpoint(p,q);
- cout << "std::midpoint('" << *p << "', '" << *q << "'): '"
- << *r << "'\n";
- };
-
-
- int main() {
- using namespace std;
- uint32_t a = numeric_limits<uint32_t>::max();
- uint32_t b = numeric_limits<uint32_t>::max() - 2;
-
- cout<< "a: " << a << '\n'
- << "b: " << b << '\n'
- << "Incorrect (overflow and wrapping): " << (a + b) / 2 << '\n'
- << "Correct: " << midpoint(a, b) << "\n\n";
-
-
- on_pointers(2, 4);
- on_pointers(2, 5);
- on_pointers(5, 2);
- on_pointers(2, 6);
- }
|