I want to learn how to make compact switches, tell me if I'm doing it right or can I simplify it?
auto _time = 5s;
bool save_time;
auto fs_time = steady_clock::now();
for(;;) {
auto now_time = steady_clock::now();
if (duration_cast<seconds>(now_time - fs_time) >= _time) {
save_time = true;
}
else {
save_time = false;
}
// CODE ....
if(save_time) {
// CODE ....
}
if(save_time) {
// CODE 2 ....
}
}
I do this to not write the same thing repeatedly.
if (duration_cast<seconds>(now_time - fs_time) >= _time) {}
Perhaps this slows down the code when it checks it constantly.