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
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 b
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. ("wor
On Tue, Jan 25, 2022 at 10:48:26PM +, forkit via Digitalmars-d-learn wrote:
[...]
> ... but my main focus here, was learning about variadic template
> functions.
D has several flavors of variadics:
1) C-style variadics (not type-safe, not recommended):
int func(int firstArgc, ...)
2
On Tuesday, 25 January 2022 at 22:35:29 UTC, forkit wrote:
I should point out (to anyone looking at that code I posted),
that it's easier, and makes more sense, to just write:
writeln( ["typeA", "typeB", "typeC"].choice );
... but my main focus here, was learning about variadic template
f
On Tuesday, 25 January 2022 at 22:07:43 UTC, Ali Çehreli wrote:
thanks. makes it even shorter and simpler :-)
// --
module test;
@safe:
import std;
auto RandomChoice(R...)(R r)
{
auto rnd = MinstdRand0(unpredictableSeed);
return only(r).choice(rnd);
}
void main()
{
writeln( Ra
On Tue, Jan 25, 2022 at 02:07:43PM -0800, Ali Çehreli via Digitalmars-d-learn
wrote:
[...]
> auto RandomChoice(R)(R[] r...)
>
> > {
> > auto rnd = MinstdRand0(unpredictableSeed);
> > return only(r).randomSample(1, rnd).front;
>
> Which makes that simpler as well because being a slice,
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").
D has a simple variadic parameter syntax as well:
auto R
On Tuesday, 25 January 2022 at 11:50:08 UTC, vit wrote:
thanks. problem solved (providing all parameters are of the same
type).
// ---
module test;
import std;
auto RandomChoice(R...)(R r)
{
auto rnd = MinstdRand0(unpredictableSeed);
return only(r).randomSample(1, rnd).front;
}
v
On Tuesday, 25 January 2022 at 09:48:25 UTC, forkit wrote:
so I'm trying to write (or rather learn how to write) a
'variadic template function', that returns just one of its
variadic parameter, randomly chosen.
But can't get my head around the problem here :-(
.. Error: template `std.random.r
On Tuesday, 25 January 2022 at 09:48:25 UTC, forkit wrote:
so I'm trying to write (or rather learn how to write) a
'variadic template function', that returns just one of its
variadic parameter, randomly chosen.
But can't get my head around the problem here :-(
.. Error: template `std.random.r
On Tuesday, 25 January 2022 at 09:48:25 UTC, forkit wrote:
so I'm trying to write (or rather learn how to write) a
'variadic template function', that returns just one of its
variadic parameter, randomly chosen.
But can't get my head around the problem here :-(
.. Error: template `std.random.r
so I'm trying to write (or rather learn how to write) a 'variadic
template function', that returns just one of its variadic
parameter, randomly chosen.
But can't get my head around the problem here :-(
.. Error: template `std.random.randomSample` cannot deduce
function from argument types `
13 matches
Mail list logo