lefticus / cpp_weekly

The official C++ Weekly Repository. Code samples and notes of future / past episodes will land here at various times. PR's will be accepted in some cases.
The Unlicense
663 stars 24 forks source link

lambdas as state machines #374

Closed lefticus closed 3 months ago

lefticus commented 3 months ago

Example:

https://compiler-explorer.com/z/vjrhYn9Yx

lefticus commented 3 months ago

Updated link: https://compiler-explorer.com/z/6dM54GMd4

lefticus commented 3 months ago

Coming in Ep426

pozemka commented 2 months ago

Just nitpicking. You can insert minus sign in the middle of the "parsed string".

int main() {
  auto parser = make_int_parser();
  auto result = parser('3');
  result = parser('-');  // <-
  result = parser('2');
  assert(*result == -32);
  std::print("{}", *result);
}
lefticus commented 2 months ago

Yeah, considering I've written 2 scripting languages now, I'm actually really bad at parsing!