Thread overview | |||||
---|---|---|---|---|---|
|
June 13, 2018 is(T t == U!n, U, int n) | ||||
---|---|---|---|---|
| ||||
If this works: template X(T) { static if(is(T t == S!n, int n)) { static if(n == 0) alias X = AliasSeq!(); else alias X = S!0; } else { static assert(0); } } class S(int n) { } pragma(msg, X!(S!3)); // S!0 pragma(msg, X!(S!0)); // () ...why can't I generalize it to match U!n, for some U, int n? template X(T) { static if(is(T t == U!n, U, int n)) { static if(n == 0) alias X = AliasSeq!(); else alias X = U!0; } else { static assert(0); } } class S(int n) { } pragma(msg, X!(S!3)); // static assert: 0 |
June 13, 2018 Re: is(T t == U!n, U, int n) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luís Marques | On Wednesday, 13 June 2018 at 09:41:45 UTC, Luís Marques wrote:
> ...why can't I generalize it to match U!n, for some U, int n?
>
> template X(T)
> {
> static if(is(T t == U!n, U, int n))
U needs to be alias U, since S is not a type, but a template. This works:
template X(T)
{
static if(is(T t == U!n, alias U, int n))
{
static if(n == 0)
alias X = AliasSeq!();
else
alias X = U!0;
}
else
{
static assert(0);
}
}
class S(int n) { }
pragma(msg, X!(S!3));
Also, you might want to consider the Learn forum for these kinds of questions in the future. :)
--
Simen
|
June 13, 2018 Re: is(T t == U!n, U, int n) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjærås | On Wednesday, 13 June 2018 at 10:34:48 UTC, Simen Kjærås wrote:
> Also, you might want to consider the Learn forum for these kinds of questions in the future. :)
You're right. What happened is that I went to check the syntax in the "D Templates: A Tutorial" PDF, and it has some material on how some possible uses of is expressions used to not be accepted by the frontend, so I though this might be a similar case: perhaps a bug or an unsupported scenario. A bit arrogant on my part, but I do stumble into bugs from time to time, so it was plausible :-). And if it was a bug/limitation then arguably this was the better forum.
|
Copyright © 1999-2021 by the D Language Foundation