March 05, 2006
Hi,

i have the following problem in a template:

class SomeClass(T) {
 T[] elements;

 ...
 /*code for adding and removing elements*/
 ...

 public int contains(T x) {

  /*x could be null if T is a pointer-type*/
  static if("T is a Pointer-Type") { /*<- How can i do this ???*/
    if(x is null){
     foreach(T y;elements){
      if(y is null) return true;
     }
     return false;
    }
   }

   ...
   /*rest of the method*/
   ...
 }

 ...

}


thnx Philipp
March 05, 2006
Philipp Heise schrieb am 2006-03-05:
> Hi,
>
> i have the following problem in a template:
>
> class SomeClass(T) {
>  T[] elements;
>
>  ...
>  /*code for adding and removing elements*/
>  ...
>
>  public int contains(T x) {
>
>   /*x could be null if T is a pointer-type*/
>   static if("T is a Pointer-Type") { /*<- How can i do this ???*/
>     if(x is null){
>      foreach(T y;elements){
>       if(y is null) return true;
>      }
>      return false;
>     }
>    }
>
>    ...
>    /*rest of the method*/
>    ...
>  }
>
>  ...
>
> }

# class C(T){
#     private T[] elements;
#
#     public int contains(T t){
#         static if(is(T == class)){
#             pragma(msg, "it's a class");
#         }else static if(is(T == delegate) || is(T == function)){
#             pragma(msg, "it's a function pointer");
#         }else static if(is(T : void*)){
#             pragma(msg, "it's a 'plain' pointer");
#         }else{
#             pragma(msg, "this isn't a pointer type");
#         }
#     }
# }

Thomas