fork download
  1. #!/usr/bin/env rdmd
  2. import std.algorithm;
  3. import std.range;
  4. import std.stdio;
  5. import std.traits;
  6. import std.file;
  7.  
  8. static import std.string;
  9.  
  10. alias std.algorithm.splitter splitter;
  11. alias std.string.splitLines byLine;
  12.  
  13. template to(T) {
  14. static import std.conv;
  15.  
  16. T to(S)(S s) if(!isArray!S && isInputRange!S) {
  17. return std.conv.to!T(s.array());
  18. }
  19. T to(A...)(A args) {
  20. return std.conv.to!T(args);
  21. }
  22. }
  23.  
  24. void main() {
  25. auto content = q"EOS
  26. 1 2
  27. 2 3
  28. 3 4
  29. 4 5
  30. EOS";
  31.  
  32. auto tmp = File("tmp.txt", "w");
  33. scope(exit) std.file.remove("tmp.txt");
  34. tmp.write(content);
  35. tmp.close();
  36.  
  37. assert(equal(File("tmp.txt").byLine().map!(splitter)().map!(to!(int[]))(),
  38. [[1, 2], [2, 3], [3, 4], [4, 5]]));
  39.  
  40. assert(equal(File("tmp.txt").byLine().map!(splitter)().map!(to!(int[]))(),
  41. content.byLine().map!(splitter)().map!(to!(int[]))()));
  42. }
  43.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.d(11): Error: identifier 'splitLines' of 'std.string.splitLines' is not defined
stdout
Standard output is empty