Template value inference: closing the UFCS gap for template value parameters (or, "foo".format(bla) as a template instantiation)
FeepingCreature
feepingcreature at gmail.com
Mon Aug 5 09:41:16 UTC 2019
On Monday, 5 August 2019 at 08:42:29 UTC, Olivier FAURE wrote:
> On Monday, 5 August 2019 at 06:49:32 UTC, FeepingCreature wrote:
>> Since D templates have value parameters, this suggests an
>> analogous process of template value inference. How would this
>> look?
>>
>> void format(string fmt, T...)(fmt, T args);
>
> I'd suggest
>
> void format(enum Fmt: string, T...)(Fmt fmt, T args);
>
Seems extraneous. Enums are not types, fmt is not a variable.
You'd basically be messing with the type system (introducing
static single-value types, similar to the range propagation
magic) for the sake of syntax. Besides, we already have a syntax
for template value parameters.
> That said, does the use case of needing UFCS with a template
> for a formatting string come up *that* often?
I mean, we're using format!"" exclusively, for typechecked
safety. We actually have a regex that translates "foo".format()
into format!"foo"() form. It would be nice to not have to do
that, especially since ufcs form really is more readable. More
than that, though, it is such a logical extension of how
templates already work that I think it should work for that
reason alone.
More information about the Digitalmars-d
mailing list