New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use of ?: in static const #5558
Comments
This comment was originally written by ladicek@gmail.com I think that the ?: ternary operator could easily be made compile-time constant, provided that its operands are also constants (and the condition is bool). This would increate expressivity of compile-time constants a lot. In other words, I want this added to section 11.1 of the spec: A constant expression is one of the following: - ... |
cc @floitschG. |
It's perfectly doable. Of course, the effect is just a rather minor convenience. Set owner to @gbracha. |
Issue #12981 has been merged into this issue. |
I have on several occasions needed something like this. |
Added Done label. |
This issue was originally filed by Rupert....@gmail.com
Would it be possible to allow use of ?: operator in static consts?
This allows them to be used a little like cpp's #ifdef.
const bool GRAVITY_ENABLED = true;
const num GRAVITY_Y = GRAVITY_ENABLED ? -9.81 : 0;
Per forum discussion https://groups.google.com/a/dartlang.org/d/topic/misc/RaFkab2-oU8/discussion
(FAO Gilad.)
The text was updated successfully, but these errors were encountered: