Skip to content

Commit 3c3279c

Browse files
authored
Merge pull request #1758 from wilzbach/example-ct-sort
Add example; Compile-Time Sort in D merged-on-behalf-of: Vladimir Panteleev <github@thecybershadow.net>
2 parents efa2422 + 0b80037 commit 3c3279c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

index.dd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ void main()
9494
}
9595
----
9696
)
97+
$(EXTRA_EXAMPLE Sort an Array at Compile-Time,
98+
----
99+
void main()
100+
{
101+
import std.algorithm, std.conv, std.stdio;
102+
103+
"Starting program".writeln;
104+
105+
// Sort a constant declaration at Compile-Time
106+
enum a = [ 3, 1, 2, 4, 0 ];
107+
static immutable b = sort(a);
108+
109+
// Print the result _during_ compilation
110+
pragma(msg, text("Finished compilation: ", b));
111+
}
112+
----
113+
)
97114

98115
) $(COMMENT your-code-here)
99116
))) $(COMMENT intro, div, div)

0 commit comments

Comments
 (0)