Re: Checking the available range while iterating through a string
On Feb 17, 4:44 pm, itaj sherman <itajsher...@gmail.com> wrote:
On Feb 17, 6:18 pm, James Kanze <james.ka...@gmail.com> wrote:
Using int instead of std::string::size_type should get rid of
the error. But you're doing a lot of extra work; my version
would be just:
if ( static_cast<size_t>(end - position) >= kToken.size()
&& std::equal(kToken.begin(), kToken.end(), position) )
position += kToken.size();
(Here, you need the static_cast, because of a design flaw in the
standard library; kToken.size() should return int.)
On Feb 17, 6:18 pm, James Kanze <james.ka...@gmail.com> wrote:
On Feb 16, 7:41 pm, =C1ngel Jos=E9 Riesgo <ajrie...@gmail.com> wrote:
(Here, you need the static_cast, because of a design flaw in the
standard library; kToken.size() should return int.)
kToken.size() should return int specifically?
That would have been a better design.
What if int is smaller than std::string::difference_type?
Maybe. Then difference_type might be more appropriate.
Does in mean there shouldn't be a container::size_type, and it should
all be container::difference_type?
The two should probably be identical. Otherwise, you end up
with problems like yours.
Is there any good reason why there is such a distinction in the
standard containers?
I believe that the STL was originally developped on a 16 bit PC,
and the author wanted that extra bit. Although even on a 16 bit
PC, the value is arguable, and the problems are legion.
--
James Kanze