We need better documentation for functions with ranges and templates

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Mon Dec 14 18:39:16 PST 2015


On 12/14/15 9:34 PM, Steven Schveighoffer wrote:
>
> InputRange find(alias pred = "a == b", InputRange, Element)(InputRange
> haystack, Element needle) if (isInputRange!InputRange &&
> is(typeof(binaryFun!pred(haystack.front, needle)) : bool));
> InputRange find(alias pred, InputRange)(InputRange haystack) if
> (isInputRange!InputRange);
> R1 find(alias pred = "a == b", R1, R2)(R1 haystack, R2 needle) if
> (isForwardRange!R1 && isForwardRange!R2 &&
> is(typeof(binaryFun!pred(haystack.front, needle.front)) : bool) &&
> !isRandomAccessRange!R1);
> Tuple!(Range, size_t) find(alias pred = "a == b", Range,
> Ranges...)(Range haystack, Ranges needles) if (Ranges.length > 1 &&
> is(typeof(startsWith!pred(haystack, needles))));
> Range1 find(Range1, alias pred, Range2)(Range1 haystack,
> BoyerMooreFinder!(pred, Range2) needle);
>
> If you can decipher this into what find actually will accept, then you
> have more patience than me. I think what I wanted (it's difficult to
> remember) is whether I could pass in a subrange for find to search for
> as the needle. It appears to reject cases where the haystack is a random
> access range and the needle is a range (but it does work).

Heh, looking at the source, I see I was a victim of improper documentation.

There are 2 additional overloads of find that are NOT DOCUMENTED.

It's likely that the 2 overloads vary only by constraints, and that's 
why they are not documented.

But as a user, again, I shouldn't have to care what the constraints are 
specifically.

-Steve


More information about the Digitalmars-d mailing list