Adrian wrote:
Quote:
On Jul 11, 11:32 am, ricec...@gehennom.invalid (Marcus Kwok) wrote:
Quote:
>Adrian <n...@bluedreamer.comwrote:
Quote:
Why does std::strings find search from the begining of the string when
pos >= (std::string::npos-3)
>>
>It does not on my implementation (see below).
>Running the above code on Windows, compiled with VS 2005:
>>
>x=4294967295 Not found
>x=4294967294 Not found
>x=4294967293 Not found
>x=4294967292 Not found
>x=4294967291 Not found
>x=4294967290 Not found
>x=4294967289 Not found
>x=4294967288 Not found
>x=4294967287 Not found
>x=4294967286 Not found
>>
>so maybe it is a quirk in the GCC Standard Library implementation.
>
Your result is what I would expect.
>
To me common sense says this is a bug in gcc
It appears to be fixed in 4.2.0.
Quote:
- but is there anything in the standard to support that.
Sure [21.3.6.1/1-3]
basic_string::find [lib.string::find]
size_type
find( const basic_string<charT,traits,Allocator>& str,
size_type pos = 0) const;
Effects: Determines the lowest position xpos, if possible, such that both
of the following conditions obtain:
? pos <= xpos and xpos + str.size() <= size();
? at(xpos+I) == str.at(I) for all elements I of the
string controlled by str.
Returns: xpos if the function can determine such a value for xpos.
Otherwise, returns npos.
Notes: Uses traits::eq().
That determines the return-value uniquely for all possible inputs since
size_type is an unsigned type.
Best
Kai-Uwe Bux