[Issue 5507] countUntil should take Ranges... instead of R2
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Nov 15 05:31:29 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5507
monarchdodra at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |monarchdodra at gmail.com
--- Comment #1 from monarchdodra at gmail.com 2012-11-15 05:31:27 PST ---
(In reply to comment #0)
> The recent addition of countUntil makes use of the startsWith template function
> which has an overload for accepting many ranges. By modifying the signature you
> can take advantage of this overload at no additional code:
>
> - sizediff_t countUntil(alias pred = "a == b", R1, R2)(R1 haystack, R2 needle)
> + sizediff_t countUntil(alias pred = "a == b", R1, Ranges...)(R1 haystack,
> Ranges needle)
>
> https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d#L3239
While the new signature *would* be nice to have, this actually *would* make
count until much more complex:
startsWith only cares about the beginning of the ranges, and as such, is
perfectly capable of operating on input+input ranges. By contrast, countUntil
*Needs* to have Forward+Forward
1. This makes the "if(is(typeof(startsWith(haystack, needles))))" a bad
condition
Also, since startsWith "consumes" its inputs, the ranges passed to it need to
be saved.
2. This would require a lot of code, to analyze just what in needle is a range
(that needs saving) or is an element (that doesn't).
Not saying it's a bad idea, or that it can't happen, but it requires *much*
more than a simple signature change.
For now (IMHO), we should concentrate on consolidating the current implementati
--
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