dlang-book/05-данные-и-функции-функцио.../src/chapter-5-4/app.d

16 lines
310 B
D

T[] find(T, E)(T[] haystack, E needle)
if (is(typeof(haystack[0] != needle) == bool))
{
while (haystack.length > 0 && haystack[0] != needle)
{
haystack = haystack[1 .. $];
}
return haystack;
}
unittest
{
// assert(find([1, 2, 3], "Hello"));
assert(find([1, 2, 3], 1.0));
}