Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Function-definition/D/function-definition.d
Normal file
24
Task/Function-definition/D/function-definition.d
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// 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:
|
||||
enum multiply3(int a, int b) = a * b;
|
||||
|
||||
pragma(msg, multiply3!(2, 3)); // Prints "6" during compilation.
|
||||
|
||||
void main() {
|
||||
import std.stdio;
|
||||
writeln("2 * 3 = ", result);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue