Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
32
Task/Introspection/D/introspection.d
Normal file
32
Task/Introspection/D/introspection.d
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// Some module-level variables (D doesn't have a global scope).
|
||||
immutable x = 3, y = 100, z = 3_000;
|
||||
short w = 1; // Not an int, must be ignored.
|
||||
immutable s = "some string"; // Not an int, must be ignored.
|
||||
|
||||
void main() {
|
||||
import std.compiler, std.math, std.traits;
|
||||
|
||||
// Compile-time constants of the compiler version:
|
||||
static assert(version_major > 1 && version_minor > 50,
|
||||
"I can't cope with this compiler version.");
|
||||
|
||||
immutable bloop = 10;
|
||||
|
||||
// To check if something compiles:
|
||||
static if (__traits(compiles, bloop.abs)) {
|
||||
pragma(msg, "The expression is compilable.");
|
||||
auto x = bloop.abs;
|
||||
} else {
|
||||
pragma(msg, "The expression can't be compiled.");
|
||||
}
|
||||
|
||||
import std.stdio;
|
||||
immutable s = 10_000; // Not at module scope, must be ignored.
|
||||
|
||||
int tot = 0;
|
||||
/*static*/ foreach (name; __traits(allMembers, mixin(__MODULE__)))
|
||||
static if (name != "object" &&
|
||||
is(int == Unqual!(typeof(mixin("." ~ name)))))
|
||||
tot += mixin("." ~ name);
|
||||
writeln("Total of the module-level ints (could overflow): ", tot);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue