Fun with templates

Artur Skawina art.08.09 at gmail.com
Sun Jul 7 01:34:32 PDT 2013


On 07/07/13 08:22, Manu wrote:
> On 7 July 2013 16:02, TommiT <tommitissari at hotmail.com <mailto:tommitissari at hotmail.com>> wrote:
> 
>     On Saturday, 6 July 2013 at 23:11:26 UTC, Manu wrote:
> 
>         [..] I feel like it would be a much cleaner solution than any of
> 
>         the others presented in this thread...
> 
> 
>     I think Artur's solution is the cleanest one because it changes the default behaviour to a more sensible one: it is useful to keep the full type information only if the type isn't implicitly convertible from immutable to mutable and back again... otherwise keeping the full type information along only causes inconvenience.
> 
> 
> Maybe so, but I just have my suspicions that it will never fly, and I think a solution here is actually pretty important.
> This is demonstrably one of the biggest issues with C++, and since templates are so much more convenient in D, I expect time will show it to be far worse in D than it already is in C++.

It's like the virtual-by-default situation - if the default isn't fixed
everybody will ignoring this issue, until it actually becomes a problem.
Then they (or more likely somebody else) will have tp do a clean up pass,
and then the cycle will repeat. Almost nobody will start with

   auto f(T=Unqual!_T)(_T val) { /*...*/ } // example new syntax

Fixing "just" IFTI should be relatively safe, affecting only a tiny
amount of code, if any.  These kind of const changes happen more
or less randomly anyway, from the POV of the called function. 
"const a=1; f(a+a); f(a+1);" -- this already creates two different
instances of 'f(T)(T)".

Yeah, fixing the expression types would be an even better idea (so
that "const int + const int" == "int" etc) but that could have a
larger impact, as it would affect a lot of 'auto' declarations.

artur


More information about the Digitalmars-d mailing list