fork download
  1. #!/usr/bin/env rdmd
  2. import std.algorithm: equal;
  3. import std.range;
  4.  
  5. template to(T) {
  6. import std.traits;
  7. static import std.conv;
  8.  
  9. T to(S)(S s) if(!isArray!S && isInputRange!S) {
  10. return std.conv.to!T(s.array());
  11. }
  12. T to(A...)(A args) {
  13. return std.conv.to!T(args);
  14. }
  15. }
  16.  
  17. void main() {
  18. auto ar = ["1", "3", "5"].to!(int[])();
  19. assert(equal(ar, [1, 3, 5]));
  20.  
  21. auto ar2 = "1 3 5".splitter().to!(int[])();
  22. assert(equal(ar2, [1, 3, 5]));
  23. }
  24.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.d(5): Error: template prog.to(T) is not a function template
prog.d(18): Error: template prog.to(T) cannot deduce template function from argument types !()(string[])
prog.d(5): Error: template prog.to(T) is not a function template
prog.d(18): Error: template prog.to(T) cannot deduce template function from argument types !()(string[])
prog.d(18): Error: (to(T))(["1","3","5"]) isn't a template
prog.d(18): Error: function expected before (), not __error of type int
stdout
Standard output is empty