Bug 3508 – hasLength is broken for length defined as function

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2009-11-14T12:00:00Z
Last change time
2015-06-09T01:27:02Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
k-foley

Comments

Comment #0 by k-foley — 2009-11-14T12:00:35Z
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.
Comment #1 by k-foley — 2009-11-14T12:04:01Z
(In reply to comment #0) > import std.stdio; > > struct Test1 { ulong length(); } > struct Test2 { ulong length; } > struct Test3 { string length; } > > ... I accidentally left out a few lines at the top (can't edit my original post): --- module test; import std.range;
Comment #2 by repeatedly — 2010-05-02T10:04:17Z
*** This issue has been marked as a duplicate of issue 2873 ***