This is the mail archive of the mailing list for the libstdc++ project. See the libstdc++ home page for more information.

[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]

Re: iterator class for vector and basic_string

Chip Salzenberg        - a.k.a. -        <>
>According to Ryszard Kabatek:
>> I wrote an iterator class for std::vector<> and std::basic_string<>.
>Could someone please fill me in on why that's necessary?  I thought
>that plain old pointers were adequate iterators in these cases.

It's not necessary for conformance, but it _is_ necessary for
type-safety.  Otherwise any old char* works as an iterator,
no matter where it came from.  This is evil.  

At the least, it leads your code to be non-portable, because 
other string implementations don't use pointers for iterators, 
so if you  misuse pointers got from c_str() or data(), it may 
work with one implementation but not another. 

Nathan Myers