simple syntax issue with template
Lloyd Dupont
ld-REMOVE at galador.net
Mon Jun 13 05:21:29 PDT 2011
removed some obvious error, still stumped on the templated syntax ...
so.. why is it not compiling?
(error:
Error: template std.algorithm.countUntil(alias pred = "a == b",R1,R2) if
(is(typeof(startsWith!(pred)(haystack,needle)))) does not match any function
template declaration
)
=====
import std.algorithm;
public:
void remove(T)(ref T[] array, T element)
{
sizediff_t index = array.countUntil!("a == b", T[], T)(array, element);
removeAt(array, index);
}
void removeAt(T)(ref T[] array, sizediff_t index)
{
if(index < 0 || index >= array.length)
return;
array.replaceInPlace(index, index + 1, []);
}
unittest
{
auto a = [1, 3, 4];
a.remove(3);
assert(a == [1, 4]);
}
=====
More information about the Digitalmars-d-learn
mailing list