Experience upgrading template code from 2.065 to 2.067
simendsjo via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jul 22 08:50:12 PDT 2015
I updated a small template-heavy experimental library mostly for
compile-time introspection I write some time ago. The last time I
updated the code was probably using 2.065, but might also have
been as old as 2.063.
The code doesn't use much of the standard library, mostly parts
of std.traits and std.typetuple.TypeTuple. While upgrading, I
only encountered a single bug
(https://issues.dlang.org/show_bug.cgi?id=14820), which might
have been there for a long time as I didn't check when it was
introduced - I hit it when adding additional unittests when I got
weird compile-time errors.
There was however a breaking change that caused most of my
templates to fail. My templates supports both built-in types,
user-defined types and values. In order to do this, both
templates of `T` and `alias T` has to be created. In previous
versions of the compiler, user-defined types always picked the
`alias T` version first, while the newest compiler picks `T` for
all types. I found the old behavior pretty weird, so I'm all in
favor of the change though.
// 1
template Tmlp(T) {}
// 2
template Tmpl(alias T) {}
struct S {}
Tmpl!S; // 2 on 2.065 (/2.063?), 1 on 2.067
There's still an odd difference between built-in and user-defined
types:
template OnlyAlias(alias T) {}
struct S {}
OnlyAlias!S; // works
OnlyAlias!int; // doesn't work
I also had to make some dub related changes and a simple import
because `chain` moved from `std.algorithm` to `std.range`.
Just a little experience-report for upgrading between compiler
versions. I'm one of the people that is pro breaking-changes.
Keep in mind that this is a small project of just 4351 LOC where
a lot is tests and documentation and nearly no use of phobos or
druntime.
Anyway - happy to see breaking changes that improves the language.
More information about the Digitalmars-d
mailing list