Getting the overload set of a template

Simen Kjærås simen.kjaras at gmail.com
Mon Apr 23 15:44:10 UTC 2018


On Monday, 23 April 2018 at 15:00:38 UTC, Alex wrote:
> Ok, thats exactly the point. If you have functions
>
> void foo() {}
> void foo(int n) {}
>
> There is no ambiguity which function will be chosen if it will 
> be called.
>
> If you have templates
>
> // form 1
> template Foo(int N) if (N & 1)    {} // A
> template Foo(int N) if (!(N & 1)) {} // B
>
> OR
>
> // form 2
> template foo(int N)
> {
> 	static if(N & 1){} // A
> 	else{} // B
> }
>
> There is also no ambiguity which will be called.
>
> However, getOverloads will behave differently.

Now I understand what you are getting at. Thanks a bunch for 
being so patient with me. :)

And you are right, of course. But I'm just as interested in the 
templates themselves as the instantiated results.


> This is not bad at all. But you have to admit, that while now, 
> there is no way to distinguish form 1 and form 2, with the new 
> getOverloads there will be.
> This seems strange to me, because there is no reason to 
> distinguish form 1 and form 2. (Because the callable code, 
> which will be generated is the same, I hope... ?)
>
> So, in particular, I'm not against the feature. And if the 
> equivalence between form 1 and form 2 is gone, so what. But I 
> don't understand the reasoning why something which is now equal 
> won't be equal any more later?

Ah, but I'm not looking to instantiate the templates, but to 
learn about them - how many parameters do they take? Are their 
UDAs different, so that I should warn the programmer? Must I wrap 
them in different ways?

I hope we now both understand what the other person means and 
want to achieve. :)

--
   Simen


More information about the Digitalmars-d-learn mailing list