In old dmd, we can use typedef to create strong type. Now I found it deprecated: http://dlang.org/deprecate.html#typedef . But it can't completely instead typedef keyword.
The following code run failed, this happened in my project.
--- code
import std.typecons;
import std.stdio;
void testString(S)() {
S a = "a";
S a1 = cast(string)"a".dup;
S b = "b";
assert(a1 == "a");
assert(a == a1);
bool[S] m;
m[a] = true;
bool* v;
v = (a in m);
assert(v);
assert(*v);
v = (b in m);
assert(!v);
v = (a1 in m);
assert(v); // <----- failed line
assert(*v);
}
void main() {
alias Typedef!string MyString;
testString!(string)();
writeln("string test passed");
testString!(MyString)();
writeln("MyString test passed");
}
---
--- output
$ dmd testproxy.d
$ ./testproxy
string test passed
core.exception.AssertError@testproxy(30): Assertion failure
----------------
5 testproxy 0x000000010e9a5ea6 _d_assertm + 38
6 testproxy 0x000000010e99297b void testproxy.__assert(int) + 23
7 testproxy 0x000000010e992e45 void testproxy.testString!(std.typecons.Typedef!(immutable(char)[], null).Typedef).testString() + 441
8 testproxy 0x000000010e992930 _Dmain + 36
9 testproxy 0x000000010e9a6846 extern (C) int rt.dmain2.main(int, char**).void runMain() + 34
10 testproxy 0x000000010e9a61fd extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void delegate()) + 45
11 testproxy 0x000000010e9a6890 extern (C) int rt.dmain2.main(int, char**).void runAll() + 56
12 testproxy 0x000000010e9a61fd extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void delegate()) + 45
13 testproxy 0x000000010e9a6187 main + 235
14 libdyld.dylib 0x00007fff8b17d7e1 start + 0
15 ??? 0x0000000000000001 0x0 + 1
----------------
---
Comment #1 by andrej.mitrovich — 2013-01-26T15:40:03Z
I'm curious which version you made this compile with, I'm getting a compile-time template instance failure instead (see Issue 9407), and this is with 2.062 git-head, 2.061, 2.060 and 2.059. Older versions don't have Typedef.
Comment #2 by b2.temp — 2017-09-13T17:05:31Z
don't know since when but the test case case is okay now.