Member functions

I have a class for which I implement ranges. I would like to implement functions the way the phobos library does, i.e. Outside the main class.

void popBack(T)(ref T[] a) if (!is(Unqual!T == char) && !is(Unqual!T == wchar))
{
    assert(a.length);
    a = a[0 .. $ - 1];
}

Here is my version:

void popFront(T)(ref PersistentList!(T) a)
{
    a = a.next();   
}

When I try to compile this code with a letter, I get:

Error   1   Error: no property 'popFront' for type 'stmd.PersistentList!(int).PersistentList'   main.d  

I could move the member code to the main class, but since I am changing the "ref" value of the input, I cannot use popFront () I really need popFront (ref a).

What am I doing wrong?

+5
source share
2 answers

, , , D . , , , -. , , . , , , , , 64- .

"" D", D2. . .

+4

/ . , -. , :

int func(int[] arr)
{
    return arr[0];
}

auto arr = [1, 2, 3];
auto val = arr.func();

auto val = func(arr);

, D, , , , .

, , , , . , . , Phobos , , , , , , -, .

+3

All Articles