digitalmars.D.bugs - [Issue 5055] New: hasAssignableElements etc only check forward range primitives
- d-bugmail puremagic.com (80/80) Oct 15 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5055
- d-bugmail puremagic.com (10/10) Jan 09 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5055
http://d.puremagic.com/issues/show_bug.cgi?id=5055 Summary: hasAssignableElements etc only check forward range primitives Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: accepts-invalid Severity: normal Priority: P2 Component: Phobos AssignedTo: nobody puremagic.com ReportedBy: yebblies gmail.com Most of the hasSomething templates in std.range should check that range.back and/or range[i] fill the requirements. hasMobileElements already does this. Also, should back/opIndex always return the same type as front? If so, this should be added to the definitions of isBidirectionalRange and isRandomAccesRange. List: hasSwappableElements hasAssignableElements hasLvalueElements Possible Implementations: template hasSwappableElements(R) { enum bool hasSwappableElements = isForwardRange!(R) && is(typeof( { R r; swap(r.front, r.front); // can swap elements of the range })) && (!isBidirectionalRange!R || is(typeof( { R r; swap(r.back, r.back); }))) && (!isRandomAccessRange!R || is(typeof( { R r; swap(r[0], r[0]); }))); } template hasAssignableElements(R) { enum bool hasAssignableElements = isInputRange!(R) && is(typeof( { R r; auto e = r.front; r.front = e; // can assign elements of the range })) && (!isBidirectionalRange!R || is(typeof( { R r; auto e = r.back; r.back = e; }))) && (!isRandomAccessRange!R || is(typeof( { R r; auto e = r[0]; r[0] = e; }))); } template hasLvalueElements(R) { enum bool hasLvalueElements = isInputRange && is(typeof(&R.init.front()) == ElementType!(R)*) && (!isBidirectionalRange!R || is(typeof(&R.init.back()) == ElementType!(R)*)) && (!isRandomAccessRange!R || is(typeof(&R.init[0]) == ElementType!(R)*)); } Adding the appropriate asserts to ElementType, isBidirectionalRange and isRandomAccessRange should prevent ranges with mismatched element types from being used. static assert(!isBidirectionalRange!R || is(typeof({return R.init.front();}()) == typeof({return R.init.back();}()), "Members front and back must have the same type"); static assert(!isRandomAccessRange!R || is(typeof({return R.init.front();}()) == typeof({return R.init[0];}()), "Members front and opIndex must have the same type"); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 15 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5055 Andrei Alexandrescu <andrei metalanguage.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED CC| |andrei metalanguage.com AssignedTo|nobody puremagic.com |andrei metalanguage.com -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 09 2011