www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17835] New: std.algorithm.findSplit: Documentation example


          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 puremagic.com
          Reporter: jrdemail2000-dlang yahoo.com

Documentation for findSplit says:

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.

if (const split = haystack.findSplit(needle))

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.

Sep 17 2017