|
|
|
|
|
by dataflow
530 days ago
|
|
> I do, but I'm still expecting things to be more complicated than that example. They're not. I've done this all the time, in the vast majority of cases it's perfectly fine. It sounds like you might not have tried this in practice -- I would recommend giving it a shot before judging it, it's quite an improvement in quality of life once you're used to it. But in any large codebase you're going to find occasional situations complicated enough to obviate whatever generic solution anyone made for you. In the worst case you'll legitimately need gotos or inline assembly. That's life, nobody says everything has a canned solution. You can't make sweeping arguments about entire coding patterns just because you can come up with the edge cases. > Without infallibility, you need a separate cleanup scope for each call you make. So your goal here is to restore the length, and you're assuming everything is infallible (as inadvisable as that often is)? The solution is still pretty darn simple: absl::Cleanup _ = [&, old_len = len] { len = old_len; };
foo();
this.len += 1;
bar();
this.len += 1;
baz();
this.len += 1;
return ...;
No need for a separate cleanup for every increment. |
|