fork(1) download
  1. auto ref find(T1, T2)(T1 required_element, T2 array) {
  2. import std.variant;
  3.  
  4. foreach (e; array)
  5. if (required_element == e) {
  6. return Variant(e);
  7. }
  8.  
  9. return Variant("-1_fuckLisperam");
  10. }
  11.  
  12. void main() {
  13. import std.stdio;
  14.  
  15. auto a = [1, 5, 9, 43];
  16. auto s = ["cat", "dog", "bar", "foo"];
  17. auto ch = ['a', 'b', 'c', 'd', 'y', 'f'];
  18. auto longDouble = [45.68L, 456.89L, 1.1L, 2.3L, 9.4L, 89.45L];
  19.  
  20. writeln(find(9, a));
  21. writeln(find("foo", s));
  22. writeln(find!(char, char[])('y', ch));
  23. writeln(find(89.45L, longDouble));
  24. writeln(find(15, a));
  25. }
Success #stdin #stdout 0s 3764KB
stdin
Standard input is empty
stdout
9
foo
y
89.45
-1_fuckLisperam