c++ - Finding a substring passing only 2 iterators? -
i have curious problem. fix goes high performance library. 1 of tasks change interface use internal string descriptor format pointer , length instead of std string parameters. 1 of functions search , find pattern within string , copy rest of string after pattern buffer.
i added change of assigning entire iterator range buffer{ custom allocator version of std string } , erasing characters upto pattern. fix rejected saying better.
my problem this. input string pair of iterators. may or may not own byte pointed end iterator i.e. cannot dereference safely.
the pattern
std::find(start, end, value);
does not allow value string.
strstr(start, value);
takes null terminated string. code has linkage boost. there boost utilities or stl algorithms take 2 string iterators , return iterator pointing first byte of string pattern. of course. there brain dead solution of creating temporary string , reassigning.
can avoid allocations?
std::search(begin, end, pat_begin, pat_end);
does job me. please give more suggestions if possible.
Comments
Post a Comment