Metaprogramming, generate argument list.
Nicholas Wilson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Aug 22 23:37:09 PDT 2016
On Monday, 22 August 2016 at 22:01:51 UTC, ciechowoj wrote:
> Is it possible to generate an argument list that contains
> pointers to local variables at compile time?
>
> For example, consider following code:
>
> template Repeat(alias int N, alias variable)
> {
> // Magic
>
> alias Repeat = /* Even more magic */;
> }
>
> void foo(int* x, int* y, int* z)
> {
> // [...]
> }
>
> void fun()
> {
> int bar = 42;
>
> foo(Repeat!(3, bar)); // want to replace it with &bar,
> &bar, &bar
> }
template Repeat( int N, alias variable)
{
static if (N == 1)
alias Repeat = variable;
else
alias Repeat = AliasSeq!(variable,Repeat!(N-1,variable));
}
Not sure if it will work with addresses of variables.
More information about the Digitalmars-d-learn
mailing list