www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11219] New: isExpression should work on non-type template instantiations

http://d.puremagic.com/issues/show_bug.cgi?id=11219

           Summary: isExpression should work on non-type template
                    instantiations
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: simen.kjaras gmail.com


--- Comment #0 from Simen Kjaeraas <simen.kjaras gmail.com> 2013-10-10 10:55:34
PDT ---
Given a templated type:

struct Foo(int x) {
    enum myValue = x;
}

I can check if something is an instantiation of this type:

template isFoo(T) {
    enum isFoo = is(T == Foo!U, U...);
}

But when the template acts only as a namespace:

template Bar(T) {
    enum myValue = x;
}

the isExpression recognizes Bar!T as not a type, and the comparisons return
false.

A useful idiom is to store compile-time values in such a template (typetuples
that don't auto-flatten, for instance), and later being able to tell if the
value being passed is an instantiation of template A or template B:

template Rectangle(float w, float h) {
    enum values = TypeTuple!(w,h);
}

template Circle(float radius) {
    enum values = TypeTuple!(radius);
}

template doStuff(alias A) {
    // Behave differently for a rectangle than for a circle.
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 10 2013