This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,26 @@
// A function:
int multiply1(int a, int b) {
return a * b;
}
// Functions like "multiply1" can be evaluated at compile time if
// they are called where a compile-time constant result is asked for:
enum result = multiply1(2, 3); // Evaluated at compile time.
int[multiply1(2, 4)] array; // Evaluated at compile time.
// A templated function:
T multiply2(T)(T a, T b) {
return a * b;
}
// Compile-time multiplication can also be done using templates:
template multiply3(int a, int b) {
enum multiply3 = a * b;
}
pragma(msg, multiply3!(2, 3)); // Prints "6" during compilation.
void main() {
import std.stdio;
writeln("2 * 3 = ", result);
}