IsExpression question

Sean Kelly sean at f4.ca
Sun Jul 9 20:13:12 PDT 2006


Kirk McDonald wrote:
> Even after writing most of a library founded on the thing, I still don't 
> get something. What exactly is the expression
> 
>     is(T == function)
> 
> testing? I would expect it to test whether T is a function pointer type 
> (like how "is(T == delegate)" tests whether T is a delegate type), but 
> it doesn't.

It's testing whether T is a function type, not a function pointer type. 
  For template code, it's mostly useful in this sort of situation:

template isFunctionType( alias ref ) {
     const bool isFunctionType = is( ref == function );
}

Though it can be used to detect a function pointer type like so:

template isFunctionPointerType( T ) {
     const bool isFunctionPointerType = is( typeof(*T) == function );
}

> 1 just baffles be. What is that? I'm dereferencing a type? Then I'm 
> taking the type of THAT? Why does that even work?

Weird, eh? :-)



Sean



More information about the Digitalmars-d mailing list