Created
January 19, 2022 17:55
-
-
Save cobbal/20a13dcece4dde1ebe19555c8e2e11c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <functional> | |
#include <random> | |
using namespace std; | |
struct OrElse { | |
function<void()> destruct; | |
~OrElse() { | |
if (destruct) { destruct(); } | |
} | |
}; | |
int main() { | |
int Highest = 0; | |
random_device generator; | |
{ | |
OrElse orElse { [&] { Highest = -1; } }; | |
for (int i = 0; i < 2; i++) { | |
int roll = uniform_int_distribution(1, 6)(generator); | |
cout << roll << endl; | |
if (roll > 4) { | |
Highest = roll; | |
orElse.destruct = nullptr; | |
break; | |
} | |
} | |
} | |
cout << "Highest is " << Highest << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment