stdin as a File.
Note: The returned File wraps core.stdc.stdio.stdin, and is therefore thread global. Reassigning stdin to a different File must be done in a single-threaded or locked context in order to avoid race conditions.
All reading from stdin automatically locks the file globally, and will cause all other threads calling read to wait until the lock is released.
1 // Read stdin, sort lines, write to stdout 2 import std.algorithm.mutation : copy; 3 import std.algorithm.sorting : sort; 4 import std.array : array; 5 import std.typecons : Yes; 6 7 void main() 8 { 9 stdin // read from stdin 10 .byLineCopy(Yes.keepTerminator) // copying each line 11 .array() // convert to array of lines 12 .sort() // sort the lines 13 .copy( // copy output of .sort to an OutputRange 14 stdout.lockingTextWriter()); // the OutputRange 15 }
The standard input stream.