C++ Logo

std-proposals

Advanced search

Re: [std-proposals] !continue

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sun, 5 Nov 2023 23:25:37 +0000
I reply to Julien and Bjorn in series below:


Julien wrote:
> As far as I can tell AddressSanitizer does not care that 'p' becomes
> less than 'buf', as long as it is not dereferenced. So there would be no
> problem here.


If you compile with:
    -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
and then manipulate iterators into a standard library container, your
program will die as soon as you decrement an iterator before begin().


Julien wrote:
> If you don't want the post-iterative step to be executed at each
> iteration, then maybe don't write a post-iterative step? You can leave
> it empty and put the increment where it matters in the body of the loop.


But then you lose the simplicity of having 'continue' in other places
in the loop.


Bjorn wrote:
> The usual solution is to move the increment into the loop
>
> while (Serial.available()) {
> // Do stuff
> if (condition) {
> // Do conditional stuff
> p = buf;
> } else {
> ++p;
> }
> }


Again here you're losing the simplicity of having 'continue' in other
places in the loop (if the loop were bigger and more complex).

Received on 2023-11-05 23:25:49