Constness thrown away in D2.008

Janice Caron caron800 at googlemail.com
Thu Nov 29 03:08:54 PST 2007


Sadly, in D2.008, the constness of basic types seems to be "thrown
away" when passed to templates. This means that code which used to
work in D2.007 now doesn't work in D2.008, and for the life of me, I
can't think of a workaround. Walter said that very few code changes
were needed to get D2.007 const to work in D2.008. Well, I can't get
this to work /at all/.

Here's the basic issue

    import std.stdio;

    template isConst(T)
    {
        static if (is(T == const)) static const bool isConst = true;
        else static const bool isConst = false;
    }

    void main()
    {
        writefln(isConst!(const(int)));
    }

prints false. This used to work in D2.007 (with the minor modification
that you'd write (T == const(T)) instead of (T == const). But the old
way doesn't work either in D2.008.

Just in case this is a bug, I've posted about this in digitalmars-d-bugs.

But in case it's not, what code changes do I need to make, to make this work?



More information about the Digitalmars-d mailing list