www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9705] New: property parameter-less template function not resolved in typeof


           Summary: property parameter-less template function not resolved
                    in typeof
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: monarchdodra gmail.com

--- Comment #0 from monarchdodra gmail.com 2013-03-12 11:44:14 PDT ---
There is a construct, where one defines a parameter template function, so that
the compiler can infer its attributes.

The problem is that when said function is a property, it doesn't mix with
traits, because it fails the typeof blocks. Explanation:

import std.range;

struct Infered
    size_t length()(){return 0;}

void main()
    Infered r;
    auto len = r.length; //OK

    static assert(hasLength!Infered);
        //Error: static assert  (hasLength!(Infered)) is false

    static assert(is(typeof(r.length) : ulong));
        //Error: static assert  (is(typeof(r.length()()) : ulong)) is false

    pragma(msg, typeof(r.length).stringof);
        //Error: expression (r.length()()) has no type
        //   while evaluating pragma(msg, (_error_).stringof)

Such usage is very interesting for wrapper ranges, but they are the most
vulnerable: Are concerned:

One workaround is to make the call outside of the typeof, and store the result,
and then test result itself eg is(typeof(len) : ulong)). Doing this would
shuffle around a lot of code though, so I don't think it's worth doing it.

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