if ((auto wText = cast<TextWidget>(w)) !is null)
wText.SetColor(col);
else if ((auto wButton = cast<ButtonWidget>(w)) !is null)
wButton.SetColor(col);
🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Syntax suggestion for if statements
I don't actually know a language where the above is valid but I can imagine that some exist. However, it may be worth considering that C++17 introduces a similar but more consistent and, to me, far better looking syntax, for if and switch statements, similar to that of for loops:
if (auto it = m.find(10); it != m.end()) {
return it->size();
}
funny. I had considered exactly the analogy of declaring variables in for() loops to accomplish the suggestion that Ansjh brought up. It makes me pleased to know that this same idea has already been introduced in C++17.
I agree that the syntax introduced in C++17 is better and also consistent with the already existing syntax in for-loops.