How to get the base type of a typedef

Jarrett Billingsley jarrett.billingsley at gmail.com
Fri May 1 07:05:06 PDT 2009


On Fri, May 1, 2009 at 9:54 AM, MLT <none at anone.com> wrote:

> and it works! Great!!
> Hmmm... but how?
> in "is( T BaseType1 == typedef )" Basetype1 seems to be a variable of type T.
> Then calling 'alias BaseTypedef!(BaseType1) BaseTypedef;' does not seem to strip away a layer... isn't it still called on a variable of type T? Or does 'is()' do some magic?

is() does a lot of magic.  It has the worst, most confusing thing in
the language.

When you do is(T U == typedef), it will evaluate to true if T is a
typedef, and if so, will declare an alias U which is aliased to the
base type of the typedef.  It's not a variable, just a type.

The recursive call to BaseTypedef!(BaseType1) is there because
BaseType1 _itself_ may be a typedef.  For instance:

typedef int a;
typedef a b;

If you call BaseTypedef!(b), the is() will figure out that its base
type is a; then it recursively calls BaseTypedef!(a), which determines
the base type is int; then it recursively calls BaseTypedef!(int),
where the is() evaluates to false, it hits the base case of recursion,
and evaluates to int.  That propagates up, and so BaseTypedef!(b)
evaluates to int.


More information about the Digitalmars-d-learn mailing list