I am using the CSFML D bindings, and I am creating my own `draw` template function.

I first check that the object passed in is of the appropriate type, and if it is, I call the appropriate function:

```D
template isDrawable(T) {
enum isDrawable = is(T == sfCircleShape*) || is(T == sfRectangleShape*) || is(T == sfText*) || is(T == sfSprite*);
}

void sfRenderWindowExt_draw(T)(sfRenderWindow* renderWindow, T obj) { static assert(isDrawable!T, format("Cannot call any draw method on type %s", T.stringof));

    if (is(T == sfCircleShape*)) {
renderWindow.sfRenderWindow_drawCircleShape(cast(sfCircleShape*)obj, null);
    } else if (is(T == sfRectangleShape*)) {
renderWindow.sfRenderWindow_drawRectangleShape(cast(sfRectangleShape*)obj, null);
    } else if (is(T == sfText*)) {
renderWindow.sfRenderWindow_drawText(cast(sfText*)obj, null);
    } else if (is(T == sfSprite*)) {
renderWindow.sfRenderWindow_drawSprite(cast(sfSprite*)obj, null);
    }
}
```

For some reason, if I replace the `isDrawable` template with the following (using `typeof`), the code does not compile:

```D
template isDrawable(T) {
enum isDrawable = is(typeof(T) == sfCircleShape*) || is(typeof(T) == sfRectangleShape*) || is(typeof(T) == sfText*) || is(typeof(T) == sfSprite*);
}
```

This is really strange, as I assumed that the two pieces of code were essentially the same.

Any help as to why this is the case would be appreciated.

Reply via email to