Template Instantiation Bug

Jonathan Marler via Digitalmars-d digitalmars-d at puremagic.com
Wed Nov 5 12:01:01 PST 2014


On Tuesday, 4 November 2014 at 21:48:29 UTC, Walter Bright wrote:
> On 11/4/2014 9:51 AM, Jonathan Marler wrote:
>> given the
>> output of Transform, the compiler cannot deduce what the input 
>> of Transform was
>> EVEN IF THE TEMPLATE IS AS SIMPLE AS THIS ONE.
>
> To answer a question not asked, why doesn't the compiler see 
> the simple case and handle it?
>
> The problem is that this becomes a special case in the language 
> specification, making the language harder to understand. Cue 
> bug reports of people confused about why the simpler cases work 
> and the more complex ones do not, and they overall get a 
> negative impression of the language. And I don't blame them.

Actually I just realized that this would be IMPOSSIBLE in the 
general case since a template transormation isn't necessarily a 
1-1 mapping. Consider,

template Normalize(T)
{
     static if(isIntegral!T) {
         alias Normalize = int;
     } else {
         alias Normalize = string;
     }
}

Given the output of Normalize, say int, there's no way of knowing 
if T was ubyte, long, int or whatever.


More information about the Digitalmars-d mailing list