January 26, 2022
On Tuesday, 25 January 2022 at 22:07:43 UTC, Ali Çehreli wrote:
> On 1/25/22 13:55, forkit wrote:
>
> > auto RandomChoice(R...)(R r)
>
> Watch out though: The compiler will compile a different function per set of values. For example, there will be separate RandomChoice instances for ("hello") vs. ("world").

Huh? Perhaps you meant "for ("hello") vs. ("hello", "world")"? Because it would be the same instantiation for a single string argument :)


January 26, 2022
On 1/26/22 02:20, Stanislav Blinov wrote:
> On Tuesday, 25 January 2022 at 22:07:43 UTC, Ali Çehreli wrote:
>> On 1/25/22 13:55, forkit wrote:
>>
>> > auto RandomChoice(R...)(R r)
>>
>> Watch out though: The compiler will compile a different function per
>> set of values. For example, there will be separate RandomChoice
>> instances for ("hello") vs. ("world").
>
> Huh? Perhaps you meant "for ("hello") vs. ("hello", "world")"? Because
> it would be the same instantiation for a single string argument :)

You're right. I mistakenly assumed it would be the same as RandomChoice(string a, string b)(). But still, as you show, the instantiations could be too many for R...

Ali

January 26, 2022
On 1/26/22 07:44, Ali Çehreli wrote:

> the instantiations could be too many for R...

I am still wrong there. It is inconceivable to instantiate the following template for the same type (e.g. string) from "too many" places in a program:

auto RandomChoice(R...)(R r) {
  // ...
}

There may be a few instantiations that call it with 1, 2, 4... maybe 10 arguments? But that would be it... Oh! Unless there is some code generation. :)

Ali

1 2
Next ›   Last »