Confused by refusal to expand template

Timon Gehr timon.gehr at gmx.ch
Fri Mar 23 16:01:44 PDT 2012


On 03/23/2012 11:58 PM, David wrote:
> Am 23.03.2012 23:52, schrieb H. S. Teoh:
>> Code:
>> struct S {
>> int f(K)(K x) {
>> return 1;
>> }
>> void func(K)(inout(K) x) {
>> auto h = f(x);
>> }
>> }
>> void main() {
>> S s;
>> s.func("abc"); // This is line 44
>> }
>>
>> This refuses to compile:
>>
>> test2.d(44): Error: template test2.S.func(K) does not match any
>> function template declaration
>> test2.d(44): Error: template test2.S.func(K) cannot deduce template
>> function from argument types !()(string)
>>
>> Removing 'inout' fixes the problem. But I don't understand why.
>>
>>
>> T
>>
> I've never really used inout, but don't you need it also for the
> return-type?

Not any more (DMD 2.059). See 
http://d.puremagic.com/issues/show_bug.cgi?id=7105

> Furthermore you don't the the inout here, since this
> template does match const/immutable/nothing anyways.

His intention probably is to prevent multiple instantiation of a 
template based on different constness.


More information about the Digitalmars-d-learn mailing list