digitalmars.D - Constness thrown away in D2.008
- Janice Caron (22/22) Nov 29 2007 Sadly, in D2.008, the constness of basic types seems to be "thrown
- Walter Bright (6/33) Nov 29 2007 This was done so that 'ordinary' templates don't get instantiated
- Jason House (3/42) Nov 29 2007 This is not obvious from the docs that this functionality would be
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?
Nov 29 2007
Janice Caron wrote: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.This was done so that 'ordinary' templates don't get instantiated multiple times for int, const int, and invariant int when that is quite unnecessary for the vast bulk of templates.Just in case this is a bug, I've posted about this in digitalmars-d-bugs.It's not a bug.But in case it's not, what code changes do I need to make, to make this work?template isConst(T:T)
Nov 29 2007
Walter Bright wrote:Janice Caron wrote:This is not obvious from the docs that this functionality would be different. Is it possible to clarify them?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.This was done so that 'ordinary' templates don't get instantiated multiple times for int, const int, and invariant int when that is quite unnecessary for the vast bulk of templates.Just in case this is a bug, I've posted about this in digitalmars-d-bugs.It's not a bug.But in case it's not, what code changes do I need to make, to make this work?template isConst(T:T)
Nov 29 2007