This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Re: basic_string<>::operator[] const
- To: libstdc++@sourceware.cygnus.com
- Subject: Re: basic_string<>::operator[] const
- From: Nathan Myers <ncm@best.com>
- Date: Wed, 9 Jun 1999 14:59:23 -0700 (PDT)
> Is it neccesary to check for __pos != size() ?
> Why only for the const version?
> Is this requierd by the standard?
>
> BTW. If we check for !=, so we can check for < instead.
>
> // Element access:
> const_reference
> operator[] (size_type __pos) const
> {
> if (__pos != this->size()) // Why not: if (__pos < this->size())
> return _M_data()[__pos];
> else
> return _Rep::_S_terminal;
> }
Indeed, why check at all? We are careful to plug in the
right value at that place when constructing the string,
and don't (or at least didn't) allow it to be overwritten.
Irritatingly, the original spec left the value at that location
undefined, allowing an implementation to report an error if it was
looked at, and then when I wasn't looking the library subgroup
changed it. Grrrr.
Nathan Myers
ncm@cantrip.org