Clash When Using Function as Template Value-Parameters?

Vijay Nayar madric at gmail.com
Tue May 29 19:17:37 UTC 2018


On Tuesday, 29 May 2018 at 12:58:20 UTC, Yuxuan Shui wrote:

> I believe that is the case. Normally that will be fine, because 
> you can't modify them. Type-deduced lambda is a very special 
> case, as in their parameter types are deduced on first use, so 
> in a sense, they are "modified" by the first instantiation.
>
> BTW, I can't find the documentation about defining lambda with 
> their parameter types omitted anywhere.

I tried this again, this time completely ignoring lambdas and 
completely specifying the desired type like so:

final class BTree(
     ValueT,
     KeyT = ValueT,
     const(KeyT) function(ValueT) nothrow pure @nogc KeyF =
         function KeyT(ValueT a) { return a; }) {
	
   KeyT getKey(ValueT val) {
     return KeyF(val);
   }
}

But unfortunately, the following code still produces an error:

void main()
{
     auto btree1 = new BTree!(char);
     auto btree2 = new BTree!(int);  // The error is on this line.
}

onlineapp.d(17): Error: template instance `BTree!int` does not 
match template declaration `BTree(ValueT, KeyT = ValueT, 
const(char) function(char) pure nothrow @nogc KeyF = function 
KeyT(ValueT a)
{
return a;
}
)`

I think at this point this may be a bug in the compiler.  What do 
you think?



More information about the Digitalmars-d mailing list