is pointer

bearophile bearophileHUGS at lycos.com
Fri Mar 19 16:29:24 PDT 2010


(I am looking for rough corners in D, or in my knowledge of D.)

In this page:
http://www.digitalmars.com/d/2.0/templates-revisited.html

In the section "Template Parameters" there is written:

P:P*,         // P must be a pointer type

-----------------

So I have written this D2 program:


template IsPointer1(T) {
    enum bool IsPointer1 = is(T : T*);
}
void main() {
    int* ptr;
    static assert(IsPointer1!(typeof(ptr))); // Err
}


But it asserts, do you know why?

-----------------

Then I have written a different program:


template IsPointer2(T) {
    enum bool IsPointer2 = is(typeof(*T)) || is(T == void*);
}
void main() {
    int* ptr;
    static assert(IsPointer2!(typeof(ptr))); // OK
    int[] arr;
    static assert(!IsPointer2!(typeof(arr))); // Err
}


Do you know why IsPointer2 is true for the dynamic array type too?

(I know in std.traits of Phobos 2 there is an isPointer).

Thank you,
bye,
bearophile


More information about the Digitalmars-d-learn mailing list