Template Instantiation Bug
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Thu Nov 6 04:53:22 PST 2014
On 11/4/14 4:48 PM, 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.
>
The real problem is that D singles out specialized type construction for
inference of types.
For example:
void foo(T)(const(T)*)
This works, because D singles out type construction of an array as one
that it can infer.
However, try to apply this to a custom type:
void foo(T)(Rebindable!(const(T)))
This *doesn't* work. I wish it would, but I can understand the
opposition to it.
The issue is that D has gone down the path of using templates for type
construction instead of adding language features, and this is one of the
main drawbacks.
I continue to think we should be providing mechanisms to hook IFTI.
There are several cases where things that "just work" with builtins
cannot be extended to custom types.
-Steve
More information about the Digitalmars-d
mailing list