69 if (c <
'0' or c >
'9')
73 constexpr int max_val = std::numeric_limits<int>::max();
74 if (
value > (max_val - digit) / 10)
86void report(
const std::string &input)
88 auto r = parse_positive(input);
89 std::cout <<
" parse_positive(\"" << input <<
"\") -> ";
91 std::cout <<
"value " << *
r <<
'\n';
93 std::cout <<
"error: " <<
r.error() <<
'\n';
100 std::cout <<
"C++23 library facilities detected on this toolchain:\n"
106 std::cout <<
"Basic value / error reporting:\n";
112 std::cout <<
"\nvalue_or (supply a fallback instead of branching):\n";
113 std::cout <<
" parse_positive(\"100\").value_or(-1) = "
114 << parse_positive(
"100").value_or(-1) <<
'\n';
115 std::cout <<
" parse_positive(\"bad\").value_or(-1) = "
116 << parse_positive(
"bad").value_or(-1) <<
'\n';
118 std::cout <<
"\nMonadic chaining (transform / and_then / or_else):\n";
121 auto squared = parse_positive(
"9").transform([](
int v) {
return v * v; });
122 std::cout <<
" \"9\" |> transform(square) = "
123 << (squared ? std::to_string(*squared) : squared.error()) <<
'\n';
126 auto chained = parse_positive(
"5").and_then(
133 std::cout <<
" \"5\" |> and_then(+100 if <=1000) = "
134 << (chained ? std::to_string(*chained) : chained.error()) <<
'\n';
137 auto recovered = parse_positive(
"oops").or_else(
139 std::cout <<
" \"oops\" |> or_else(0) = "
140 << (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.