Clash When Using Function as Template Value-Parameters?

Yuxuan Shui yshuiv7 at gmail.com
Tue May 29 12:58:20 UTC 2018


On Tuesday, 29 May 2018 at 12:37:04 UTC, Vijay Nayar wrote:
> On Tuesday, 29 May 2018 at 11:36:11 UTC, Yuxuan Shui wrote:
>>
>> No, wait a second. (a)=>a is in default argument list, so it 
>> is in the global scope. And it was instantiated when you 
>> instantiate BTree with char.
>
> Could you explain that part a bit for me?  Yes, (a) => a is a 
> default value, but when you say it is in the global scope, are 
> you saying that a single object "(a) => a" is created in the 
> global scope and not created for each template argument list, 
> e.g. "BTree!int" and "BTree!char"?
>
> I actually do not know in what scope such objects would be 
> created, I had assumed it was per template-parameter list, but 
> are you saying this is not the case?

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.


More information about the Digitalmars-d mailing list