simple (I think) eponymous template question ... what is proper idimatic way ?

james.p.leblanc james.p.leblanc at gmail.com
Tue Aug 17 18:11:56 UTC 2021


Evening All,

Eponymous templates allow a nice calling syntax.  For example, 
"foo" here can
be called without needing the exclamation mark (!) at calling 
sites.  We see that
foo is restricting a, and b to be of the same type ... so far, so 
good.

auto foo(T)(T a, T b) { ... }

Now, suppose I need to restrict "T" only certain subsets of 
variable types.

I can imagine putting in some "static if" statements in my 
function body,
is one solution.  (Also a bit ugly as the allowed types might 
grow).

Is there a more elegant way, to do this?

Regards,
James

PS Any violations should be caught at compile time.






More information about the Digitalmars-d-learn mailing list