[Issue 3508] New: hasLength is broken for length defined as function
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sat Nov 14 12:00:36 PST 2009
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=3508
           Summary: hasLength is broken for length defined as function
           Product: D
           Version: 2.036
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: k-foley at onu.edu
--- Comment #0 from Kyle Foley <k-foley at onu.edu> 2009-11-14 12:00:35 PST ---
import std.stdio;
struct Test1 { ulong length(); }
struct Test2 { ulong length; }
struct Test3 { string length; }
/* Definition from std.range
template hasLength(R)
{
    enum bool hasLength = is(typeof(R.init.length) : ulong);
}
*/
template hasLength(R)
{
    enum bool hasLength = is(typeof({
        auto r = R.init;
        auto l = r.length;
        static assert( is(typeof(l) : ulong) );
    }()));
}
int main(string[] args)
{
    writeln( std.range.hasLength!(Test1) ); // false
    writeln( std.range.hasLength!(Test2) ); // true
    writeln( std.range.hasLength!(Test3) ); // false
    writeln( test.hasLength!(Test1) ); // true
    writeln( test.hasLength!(Test2) ); // true
    writeln( test.hasLength!(Test3) ); // false
    return 0;
}
---
I included my proposed fix as test.hasLength.
-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
    
    
More information about the Digitalmars-d-bugs
mailing list