Boost logo

Boost :

From: John Maddock (John_Maddock_at_[hidden])
Date: 2001-03-20 07:27:24


>What I don't get is the reason why it does it this way, eating the
>input string. I recognize that this pattern might happen fairly
>frequently, but I have run into a situation where I want to use it with
>a const string. Of course, I can just copy the string to avoid the
>problem, but I'm paying some efficiency costs to do this: I copy the
>string, then erase the copy inside regex_split, then destruct the
>remnants. And, unless I am quite mistaken in my reading of the code,
>I'm not going to gain any efficiency in exchange, since I will need to
>copy the pieces into the output container in either case.

It's done that way, because that's the way that perl does it. You can also
specify an upper limit to the number of items to be split, in which case
some text may be left in the string. BTW the return value is the number of
*items* split out, not the number of characters removed, so there is no way
of knowing how much input has been processed unless you erase processed
text from the input.

BTW it's not that hard to role your own function that does what you want -
really all you need is a custom functor to pass to regex_grep.

- John Maddock
http://ourworld.compuserve.com/homepages/john_maddock/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk