static with?
bearophile
bearophileHUGS at lycos.com
Sat Dec 14 18:03:08 PST 2013
I think I'd like with() to not create a scope, just like the
"static if". So you could write this code:
enum Foo { A, B }
auto x1 = Foo.A;
auto x2 = Foo.B;
void main() {
import std.stdio;
immutable data = [Foo.A, Foo.B];
data.writeln;
}
Like this, where "with(Foo)" is usable at module scope, and it
can be used to define an immutable and keep it visible later for
the writeln:
enum Foo { A, B }
with (Foo) {
auto x1 = A;
auto x2 = B;
}
void main() {
import std.stdio;
with (Foo) {
immutable data = [A, B];
}
data.writeln;
}
Assuming the current design of with() can't change, I think a
"static with" could be used...
enum Foo { A, B }
static with (Foo) {
auto x1 = A;
auto x2 = B;
}
void main() {
import std.stdio;
static with (Foo) {
immutable data = [A, B];
}
data.writeln;
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list