[Issue 13863] New: More readable template constraints
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Dec 15 04:50:49 PST 2014
https://issues.dlang.org/show_bug.cgi?id=13863
Issue ID: 13863
Summary: More readable template constraints
Product: D
Version: unspecified
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: Phobos
Assignee: nobody at puremagic.com
Reporter: kiithsacmp at gmail.com
Complicated template constraints in function signatures of many Phobos
functions severely affect readability of standard library documentation.
This could be mitigated by refactoring the constraints into separate template
predicates invoked in the (now much shorter) template constraints. These
predicated can then be descriptively documented as well.
E.g. instead of:
--------------------
ptrdiff_t countUntil(alias pred = "a == b", R, Rs...)(R haystack, Rs needles)
if (isForwardRange!R && Rs.length > 0 && isForwardRange!(Rs[0]) ==
isInputRange!(Rs[0]) && is(typeof(startsWith!pred(haystack, needles[0]))) &&
(Rs.length
== 1 || is(typeof(countUntil!pred(haystack, needles[1..$])))));
--------------------
Use something like this:
--------------------
ptrdiff_t countUntil(alias pred = "a == b", R, Rs...)(R haystack,
Rs needles) if (canCountUntil!(pred, R, Rs));
/** A range can be counted if:
- R is a forward range
- pred is a valid string comparison predicate, or a function that can
compare R.front with Rs.front
- ...
*/
template canCountUntil(alias pred, R, Rs...)
{
...
}
--------------------
See also:
http://forum.dlang.org/post/mailman.3193.1418597982.9932.digitalmars-d@puremagic.com
http://forum.dlang.org/post/slssjxbsguvhcbdlfefu@forum.dlang.org
--
More information about the Digitalmars-d-bugs
mailing list