static with?
JR
zorael at gmail.com
Sun Dec 15 04:34:38 PST 2013
On Sunday, 15 December 2013 at 02:03:09 UTC, bearophile wrote:
> I think I'd like with() to not create a scope, just like the
> "static if". So you could write this code:
> [...]
And/or with the same syntax as <attribute>: (saving some
indentation, but perhaps less idiomatic?). Granted it doesn't
allow for top-level definitions, and it *really* would highlight
the need for a way to end the attribue scope.
enum Foo { A, B }
void main() {
import std.stdio;
with (Foo):
immutable data = [A, B];
// ~with (Foo) ? pretty pretty please, would help so very
much elsewhere
data.writeln();
}
In my code I usually locally alias the enum to a single letter
and use it as a shorthand identifier. But it's ugly.
enum DescriptiveEnumNameBecauseReasons { A, B }
void main() {
import std.stdio;
alias d = DescriptiveEnumNameBecauseReasons;
immutable data = [d.A, d.B];
data.writeln();
}
More information about the Digitalmars-d
mailing list