<div class="gmail_quote">On Thu, Dec 30, 2010 at 9:24 AM, bearophile <span dir="ltr"><<a href="mailto:bearophileHUGS@lycos.com">bearophileHUGS@lycos.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Jonathan M Davis:<br>
<div class="im"><br>
> typedef is definitely on the way out, so that's not a solution,<br>
<br>
</div>typedef is deprecated (because its semantics is not flexible enough and because it doesn't play well with object oriented language features), but I have a real need for something like it. Andrei has discussed about a Phobos-based typedef replacement (based on structs + alias this), but nothing concrete has come out yet. I hope to see something to solve problems like spir ones.<br>

<div class="im"><br>
<br>
> and it would be a pretty fragile one IMHO anyway.<br>
<br>
</div>Please, explain better.<br>
<br>
Bye,<br>
<font color="#888888">bearophile<br>
</font></blockquote></div><div><br></div>As far as I know, typedef was a form of "discriminated alias". I don't know the reasons for its deprecation. It just occurred to me that D's typedefs + templates could be quite handy in this case.<div>
<br></div><div>Consider:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><font class="Apple-style-span" face="'courier new', monospace">struct semantic_wrapper(T)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">{</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    this(T value) { this.value = value; }</font></div><div>
<font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">    T value;</font></div><div><font class="Apple-style-span" face="'courier new', monospace">}</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">typedef semantic_wrapper!(int) Position;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">typedef semantic_wrapper!(size_t) Count;</font></div><div><font class="Apple-style-span" face="'courier new', monospace">typedef semantic_wrapper!(string) Filename;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">typedef semantic_wrapper!(string) DirPath;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">void func(Position pos) { ... }</font></div><div><font class="Apple-style-span" face="'courier new', monospace">void func(Count c) { ... }</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">void func(Filename fname) { ... }</font></div><div><font class="Apple-style-span" face="'courier new', monospace">void func(DirPath dir) { ... }</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">void main()</font></div><div><font class="Apple-style-span" face="'courier new', monospace">{</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">    func(Position(1)); // calls first overload</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    func(Count(5)); // calls second</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">    func(Filename("file.txt")); // third</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    func(DirPath("/dev/null")); // fourth</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">    func(1); // fails</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    func("blah"); // fails</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">}</font></div></blockquote><div><br></div><div>Requires a little more typing, but sometimes it can be better than creating a new function name (which can get extra-big, non-telling or both) or than creating factory methods (which I personally dislike, although it's just a matter of taste most of the time; sometimes you may want to instantiate from inside a template and classes needing factories would not work, for example, but one could argue on the validity of this anytime).</div>
<div><br></div><div>Just giving my 2 cents. Dunno if I missed some detail.<br clear="all"><br>-- <br>Atenciosamente / Sincerely,<br>Guilherme ("n2liquid") Vieira<br>
</div>