Skip to content

Instantly share code, notes, and snippets.

@superwills
Created February 19, 2024 19:27
Show Gist options
  • Save superwills/0683895314c7d7831b077e39aff21d45 to your computer and use it in GitHub Desktop.
Save superwills/0683895314c7d7831b077e39aff21d45 to your computer and use it in GitHub Desktop.

Revisions

  1. superwills created this gist Feb 19, 2024.
    22 changes: 22 additions & 0 deletions firstRun.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #include <stdio.h>

    int main(int argc, const char * argv[]) {

    struct FirstRun {
    bool hasRun = 0;

    operator bool() {
    bool firstRun = !hasRun;
    hasRun = 1;
    return firstRun;
    }
    };

    for (int i = 0; i < 3; i++) {
    static FirstRun isFirstRun;
    if (isFirstRun) puts("1st run");
    else puts("subsequent");
    }

    return 0;
    }