Manipulating alias sequences

Ben Ogles benjaminogles at gmail.com
Mon Jul 15 13:40:29 UTC 2019


I have written a simple function that can call another function 
over integral types with random arguments:

auto rnd = Random(42);

auto rand_integral(T)() {
   return uniform(T.min, T.max, rnd);
}

auto call_with_rand(alias fun)() {
   fun(staticMap!(get_rand_integral, Parameters!fun));
}

Now I want to extend it so that a caller can specify the values 
of only some of the parameters. I tried using a static foreach 
instead of the staticMap function. But I can't modify AliasSeq 
values.

alias args = AliasSeq!(0, 0);
static foreach (idx, val; args) {
   static if (user_defined_function_exists_for_arg!(idx)) {
     args[idx] = user_defined_function(); // cannot modify tuple
   } else {
     args[idx] = gen_rand_integral!(typeof(val)); // cannot modify 
tuple
   }
}

How do I build up an argument tuple at compile time where some 
values are randomly generated and others are given through some 
user defined function (most likely automatically discovered by a 
naming convention)?



More information about the Digitalmars-d-learn mailing list