is pointer

Ellery Newcomer ellery-newcomer at utulsa.edu
Fri Mar 19 18:52:41 PDT 2010


On 03/19/2010 07:53 PM, Moritz Warning wrote:
> On Fri, 19 Mar 2010 19:29:24 -0400, bearophile wrote:
>
>> (I am looking for rough corners in D, or in my knowledge of D.)
> [..]
>>
>> 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?
>
> I think the problem is that is(T : T*) becomes is(int* : int**)
> and that's false.
>
>
>
>> Then I have written a different program:
> [..]
>>      enum bool IsPointer2 = is(typeof(*T)) || is(T == void*);
> [..]
>>
>>
>> Do you know why IsPointer2 is true for the dynamic array type too?
> .. no idea.

Curious behavior DArrays exhibit:

void main(){
   int[] i = [5,4,3,2,1];
   writeln(*i); // prints 5
}

Ick.


More information about the Digitalmars-d-learn mailing list