I have defined my own character iterator class. Can I somehow plug it in to std::string so that I dont have to implement the std::string kind of interface again? I checked the template arguments of std::basic_string, but it does not take anything of this sort.
2 Answers
One idea is to provide begin(std::string) and end(std::string) functions which return your iterators. These can then be used in all the places which expect iterators.
begin() free function style is from c++11 onwards.
4 Comments
begin(std::string), because that class does expose a suitable .begin() member.There's an overloaded constructor for std::string which will take an iterator pair. That would work, but create a copy. That is of course the best you can do. Consider an implementation which has the "Small String Optimization", i.e. a small char[N] inside the std::string object itself. That is very, very likely incompatible with your memory layout.
std::string's iterators (char*) don't?