Template value inference: closing the UFCS gap for template value parameters (or, "foo".format(bla) as a template instantiation)

Nick Treleaven nick at geany.org
Sat Aug 10 17:55:14 UTC 2019


On Monday, 5 August 2019 at 06:49:32 UTC, FeepingCreature wrote:
> void format(string fmt, T...)(fmt, T args);
>
> In other words, we specialize format for the *value* of the 
> template parameter fmt, and then let IFTI/template inference do 
> the work of figuring out the appropriate template 
> instantiation, exactly as before.
>
> With this change, format!"..." would no longer be necessary at 
> all; all format calls of the form format("format string", args) 
> would be templated on the string's value, as they already are 
> on the argument types.
>
> Thoughts?

Sounds great. I think the main advantages are optimization and 
compile-time checking rather than UFCS.

IFTI should prefer template value parameter inference over an 
overload that takes the parameter at runtime. (The overload is 
still necessary for non-literal arguments).

Then we could call a function with compile time optimization 
without even having to be aware of a template overload that takes 
a literal value argument at compile-time instead of runtime.


More information about the Digitalmars-d mailing list