Boost logo

Boost :

Subject: Re: [boost] Result of boost::split against empty string changed in post-1.45 release
From: Olaf van der Spek (ml_at_[hidden])
Date: 2012-06-11 16:05:50


On Mon, Jun 11, 2012 at 8:09 PM, Pavol Droba <droba_at_[hidden]> wrote:
>
> On Mon, 11 Jun 2012 16:58:40 +0200, Mateusz Loskot <mateusz_at_[hidden]>
> wrote:
>
>> Hi,
>>
>> I have a simple program runs boost::split against empty string.
>> I'm testing with Boost 1.45 and later versions like 1.46 or 1.49.
>> As stated in the // comment below, there is difference in behaviour
>> depending on the Boost version:
>>
>> // https://gist.github.com/2910461
>> #include <cassert>
>> #include <string>
>> #include <vector>
>> #include <boost/algorithm/string/split.hpp>
>> #include <boost/algorithm/string/classification.hpp>
>>
>> int main(int argc, wchar_t* argv[])
>> {
>>    std::wstring s;
>>    std::vector<std::wstring> a;
>>
>>    assert(s.empty());
>>    boost::split(a, s, boost::is_any_of(L", "), boost::token_compress_on);
>>    // Boost 1.45:  true
>>    // Boost 1.46+: false
>>    //   Assertion failed: s.empty() == a.empty(), file
>> boost_split_empty_string.cpp, line 16
>>    assert(s.empty() == a.empty());
>>    return 0;
>> }
>>
>> IMHO, the behaviour exposed in newer versions is a bug.
>> Could anyone shed light on what happened in post-1.46?
>>
>
> Hi,
>
> Please search the boos archives. There was an extensive discussion about
> this
> particular issue.
>
> The current behavior is consistent with the assertion that split always
> returns n+1 tokens where n is number of separators in the input string.

It's not what I'd expect.
Would also be handy to include a link to the discussion in the docs
for future reference.

-- 
Olaf

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