Unwrap variadic template into vararg of pointers of the same types
wjoe
invalid at example.com
Fri Jul 8 12:40:52 UTC 2022
On Friday, 8 July 2022 at 12:20:13 UTC, ryuukk_ wrote:
> I'm not sure how to phrase it so it'll try with code
>
> I have this piece of code that i would like to improve, right
> now i have to create bunch of duplicates
>
> ```D
> void view_it(A, B)(void function(entity_t, A*, B*) cb)
> {
> foreach(it, e; view!(Includes!(A, B)))
> {
> auto a = it.get!(A)(e);
> auto b = it.get!(B)(e);
> cb(e, a, b);
> }
> }
> ```
>
> The problem when i try to introduce variadic template, is i
> can't seem to understand how to unwrap the parameter as pointer
> type T -> T*
>
>
> ```D
> struct Includes(Args...) { alias args = Args; }
>
> void view_it(Includes)(void function(entity_t, Includes.args* )
> cb)
> {
> // do stuff
> }
>
> ```
>
> I get the following:
>
> ```Error: cannot have pointer to `(EEntityRemoved)```
>
> Anyone got an idea?
>
> Thanks!
I suppose you could do something like this:
```d
template Includes(Args...)
{
template Recurse(Arg...)
{
import std.meta: AliasSeq;
static if (1 == Arg.length)
alias Recurse = AliasSeq!(Arg[0]*);
else
alias Recurse = AliasSeq!(Arg[0]*, Recurse!(Arg[0..$]);
}
alias Includes = Includes!(Args);
}
void view_it(Args...)(void function(entity_t, Includes!(Args) )
```
More information about the Digitalmars-d-learn
mailing list