Reputation: 4109
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.
Upvotes: 0
Views: 117
Reputation: 179779
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.
Upvotes: 0
Reputation: 31952
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.
Upvotes: 1