67 if (c <
'0' or c >
'9')
71 constexpr int max_val = std::numeric_limits<int>::max();
72 if (
value > (max_val - digit) / 10)
84void report(
const std::string &input)
86 auto r = parse_positive(input);
87 std::cout <<
" parse_positive(\"" << input <<
"\") -> ";
89 std::cout <<
"value " << *
r <<
'\n';
91 std::cout <<
"error: " <<
r.error() <<
'\n';
98 std::cout <<
"C++23 library facilities detected on this toolchain:\n"
104 std::cout <<
"Basic value / error reporting:\n";
110 std::cout <<
"\nvalue_or (supply a fallback instead of branching):\n";
111 std::cout <<
" parse_positive(\"100\").value_or(-1) = "
112 << parse_positive(
"100").value_or(-1) <<
'\n';
113 std::cout <<
" parse_positive(\"bad\").value_or(-1) = "
114 << parse_positive(
"bad").value_or(-1) <<
'\n';
116 std::cout <<
"\nMonadic chaining (transform / and_then / or_else):\n";
119 auto squared = parse_positive(
"9").transform([](
int v) {
return v * v; });
120 std::cout <<
" \"9\" |> transform(square) = "
121 << (squared ? std::to_string(*squared) : squared.error()) <<
'\n';
124 auto chained = parse_positive(
"5").and_then(
131 std::cout <<
" \"5\" |> and_then(+100 if <=1000) = "
132 << (chained ? std::to_string(*chained) : chained.error()) <<
'\n';
135 auto recovered = parse_positive(
"oops").or_else(
137 std::cout <<
" \"oops\" |> or_else(0) = "
138 << (recovered ? std::to_string(*recovered) : recovered.error())
C++20/23 compatibility layer: feature detection + Aleph:: polyfills.
#define ALEPH_HAS_STD_FLAT_MAP
#define ALEPH_HAS_STD_EXPECTED
#define ALEPH_HAS_STD_GENERATOR
#define ALEPH_HAS_STD_MDSPAN
size_t size_t int32_t value
Minimal std::expected-style result type for C++20.
Wrapper for the error value used to initialize an expected.