simple syntax issue with template

Dmitry Olshansky dmitry.olsh at gmail.com
Mon Jun 13 08:04:39 PDT 2011


On 13.06.2011 16:49, Lloyd Dupont wrote:
> ho.. plenty of silly mistake indeed.. thanks for spotting them!
> (maybe I should take a break and play the witcher 2 hey!?!? :)

Why not ? ;-)
>
> however I still have a problem with removeAt now! :(
> ===
> void removeAt(T)(ref T[] array, int index)
> {
>    if(index < 0 || index >= array.length)
>        return;
>    array.replaceInPlace(index, index + 1, []);
> }
Yeah, I think I've hit this issue before, and used plain cast(T[])[]. 
The problem is that [] is null of type void[], and template fails to 
resolve type. Seems like insertInPlace probably should take this special 
case into account.

> ===
> will produce the following errors:
> ===
> Error: template std.array.replaceInPlace(T,Range) if 
> (isDynamicArray!(Range) && is(ElementEncodingType!(Range) : T) && 
> !is(T == const(T)) && !is(T == immutable(T))) does not match any 
> function template declaration
> Error: template std.array.replaceInPlace(T,Range) if 
> (isDynamicArray!(Range) && is(ElementEncodingType!(Range) : T) && 
> !is(T == const(T)) && !is(T == immutable(T))) cannot deduce template 
> function from argument types !()(int[],int,int,void[])
> ===
>
> mmm.. strangely enough the code below succeed!
> ====
> void removeAt(T)(ref T[] array, int index)
> {
>    if(index < 0 || index >= array.length)
>        return;
>    T[] empty;
>    array.replaceInPlace(index, index + 1, empty);
> }
> ====
> but T[].init didn't work either....?! ho well, thanks! :)


-- 
Dmitry Olshansky



More information about the Digitalmars-d-learn mailing list