[Issue 17835] std.algorithm.findSplit: Documentation example does not compile
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Sep 21 17:02:01 UTC 2017
https://issues.dlang.org/show_bug.cgi?id=17835
--- Comment #2 from Jon Degenhardt <jrdemail2000-dlang at yahoo.com> ---
(In reply to Duncan Paterson from comment #1)
> Created attachment 1659 [details]
> test case without described behaviour
>
> I tried to reproduce your issue but couldn't using DMD64 v2.076.0 on mac OS.
> I've attached my test code to ensure I'm testing the same thing you are.
Here's the full test case I used:
--------------------------------
import std.stdio;
import std.algorithm : findSplit;
void main(string[] args)
{
if (args.length <= 1)
writeln("Provide an arg with an 'X' in it.");
else if (const split = args[1].findSplit("X"))
writefln("Before: '%s'; After: '%s'", split[0], split[2]);
else
writefln("No X in '%s'", args[1]);
}
----------------------------------
The 'else if' line generates the compile error. It's the combination of
declaring 'split' const and 'if' invoking the 'bool opCast(T : bool)()'
operator, which is not declared const. Declaring 'split' as auto works fine.
Declaring 'split' const, but not invoking the opCast operator is also fine.
--
More information about the Digitalmars-d-bugs
mailing list