[OT] new thing I learned for today
Steven Schveighoffer
schveiguy at gmail.com
Wed Dec 18 17:41:42 UTC 2019
On 12/18/19 9:18 AM, jmh530 wrote:
> On Wednesday, 18 December 2019 at 01:20:33 UTC, Steven Schveighoffer wrote:
>> [snip]
>>
>> BTW, people have been talking about usage like:
>>
>> auto str = i"I have $apples apples".format;
>>
>> And it got me thinking, does this actually work? I mean, can multiple
>> parameters be used for UFCS?
>>
>> Answer: yes.
>>
>> auto str = AliasSeq!("I have %s apples", apples).format; // OK
>>
>> pretty cool. I had no idea.
>>
>
> I think it works because format takes a variadic template as an input.
> Given the connection between variadic templates and AliasSeq, the input
> is basically an AliasSeq in the first place. Shouldn't be an issue
> having AliasSeq's with length>1.
>
> I don't know if I would describe it as multiple parameters. I would call
> UFCS with multiple parameters as describing when you have foo(x, y, z),
> you can call x.foo(y, z). In this case, something like
> auto str = AliasSeq!("I have %s apples").format(apples);
> also compiles without error and would be more comparable.
Nope. Not just variadic templates:
assert(AliasSeq!(2, 2).pow == 4);
Not even templates in general:
int foo(int x, int y) { return x + y; }
assert(AliasSeq!(1, 2).foo == 3);
-Steve
More information about the Digitalmars-d
mailing list