[Issue 17835] New: std.algorithm.findSplit: Documentation example does not compile
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Sep 17 20:34:41 UTC 2017
https://issues.dlang.org/show_bug.cgi?id=17835
Issue ID: 17835
Summary: std.algorithm.findSplit: Documentation example does
not compile
Product: D
Version: D2
Hardware: x86
OS: Mac OS X
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: jrdemail2000-dlang at yahoo.com
Documentation for findSplit says:
---------------------------------
Returns:
A sub-type of Tuple!() of the split portions of haystack (see above for
details). This sub-type of Tuple!() has opCast defined for bool. This opCast
returns true when the separating needle was found (!result[1].empty) and false
otherwise. This enables the convenient idiom shown in the following example.
Example
if (const split = haystack.findSplit(needle))
{
doSomethingWithSplit(split);
}
---------------------------------
However, the example fails to compile with the error message:
Error: mutable method std.algorithm.searching.findSplit!("a == b", string,
string).findSplit.Result!(string, string).Result.opCast!bool.opCast is not
callable using a const object
Changing the example to use 'auto' rather than 'const' works. There is no unit
test of this capability. It does not appear to be a regression, the same error
occurs with DMD 2.072.2 through 2.076.0-dirty.
I didn't try it, but declaring the opCast const (and perhaps pure, nothrow,
@nogc) would make the example work. Otherwise, the documentation should be
change. A unit test would also be appropriate.
This also applies to the sibling functions findSplitBefore and findSplitAfter.
--
More information about the Digitalmars-d-bugs
mailing list