<div dir="ltr">I would rewrite it to something like this:<div><br></div><div><div>import std.stdio;</div><div>import std.functional;</div><div><br></div><div>template BTree(ValueT, KeyT = ValueT,alias KeyF = unaryFun!"cast(const)a")</div><div>{</div><div>    class BTree</div><div>    {</div><div>        auto getKey(ValueT val) {</div><div>            return KeyF(val);</div><div>        }</div><div>    }</div><div>}</div><div><br></div><div>void main()</div><div>{</div><div>    auto btree1 = new BTree!(char)();  // Removing this line eliminates the error.</div><div>    auto btree2 = new BTree!(int)();</div><div>}</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, May 27, 2018 at 9:03 AM, Vijay Nayar via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Saturday, 26 May 2018 at 11:56:30 UTC, Vijay Nayar wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The error is:<br>
```<br>
onlineapp.d(8): Error: function literal `__lambda6(char a)` is not callable using argument types `(int)`<br>
onlineapp.d(8):        cannot pass argument `val` of type `int` to parameter `char a`<br>
onlineapp.d(15): Error: template instance `onlineapp.BTree!(int, int, function (char a) => a)` error instantiating<br>
```<br>
</blockquote>
<br></span>
Just to clarify.  In the example above, if I create a 'BTree!int' by itself, it's fine.  If I create a 'BTree!char' by itself, it's fine also.  But if I create both, even if they are created in different modules, the compiler seems to mix up the types of the function template-parameter, and tries to fit a 'char' to the 'int' function or an 'int' to the 'char' function, depending on which was declared first.<br>
</blockquote></div><br></div>