Template-Parameterized Variadic isInstaceOf

"Nordlöw" via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 7 06:25:29 PDT 2015


On Friday, 7 August 2015 at 11:45:22 UTC, Nordlöw wrote:
> Can somebody please explain and help out with variadic version 
> of `isInstanceOf`?

Here's a step forward:

/**
    Returns true if $(D T) is an instance of the template $(D T) 
with template
    parameters $(D Ps).
*/
enum bool isInstanceOf(alias S, T, Ps...) = is(T == S!Ps);

///
unittest
{
     struct SortedRange(Range, alias pred = "a < b")
     {
     }
     alias R = int[];
     alias SR = SortedRange!(R, "a < b");
     static assert(isInstanceOf!(SortedRange, SR, R, "a < b"));
}


1.
This, however, requires *all* the template parameters to be 
given. What I need now is a syntax to check that, in this case, 
*only* the second template argument `pred` matches. How do I do 
that?


2.
Note also that this solution doesn't understand that "a<b" and "a 
< b" are semantically equivalent. Forcing usage of `binaryFun` is 
a temporary solution. Is there a better solution?


More information about the Digitalmars-d-learn mailing list