Why does std.string.munch take a string ref?
Sean Kelly via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jun 11 14:24:08 PDT 2014
On Wednesday, 11 June 2014 at 21:18:29 UTC, monarch_dodra wrote:
>
> I think it's because it "returns" both the munched data, and
> the modified string:
>
> string s = "123abc";
> string t = munch(s, "0123456789");
> assert(t == "123" && s == "abc");
>
> But it would indeed be more natural to simply return the
> updated "s". It's what things like "find" or "stripLeft" do
> anyways, and that works fine.
Right. The problem I ran into was that because munch takes a
reference, I can't chain it with other functions in std.string
because they all return rvalues. So it makes for some
unnecessarily awkward code.
More information about the Digitalmars-d
mailing list