Passing template alias to a function

Andrey Zherikov andrey.zherikov at gmail.com
Thu Aug 7 16:58:34 UTC 2025


On Wednesday, 6 August 2025 at 23:58:03 UTC, monkyyy wrote:
> ```d
> struct A(T) {}
> struct H(T) {}
>
> alias B(T) = A!(H!T);
>
> void f(T)(A!(H!T) b) {}
> void g(T)(A!T b) {}
> void h(B_)(B_ b)if(is(B_==A!(H!T),T)){}
> unittest{
>     f(B!string.init);
>     g(B!int.init);
>     h(B!bool.init);
> }
> ```
>
> I dont think you should actually try to pull patterns out of 
> `h`, and just go with a `void i(T...)(T args)` if you have 
> something complex to match but without a usecase, who knows

I don't want to change function parameter to `A!...` because 
`A!...` is implementation details of `B`:
```d
// module a
public struct A(T) {}

// module b
private struct H(T) {}
public alias B(T) = A!(H!T);

// module main
void f(T)(B!T b) {}
```


More information about the Digitalmars-d-learn mailing list