Hi, Meryl Silverburgh wrote:
Thanks for your idea.
I have cases like this:
/1/1 /1/2/3/2
Since the first string /1/1 is smaller than the /1/2 (1 is < 2) of the /1/2/3/2, I should able to stop comparison by looking at the 4th character (/1/2) of '/1/2/3/2'.
So for cases like that, I would like to stop as soon as i can tell one string is shorter than the other, instead of splitting the whole string.
This is exactly what would happen you use the second approach I gave you. Constructing the iterator_range from the split iterator does not perform any actual searching, and lexicographical_compare stops on the first possible index (i.e on the first position where inputs are different).
You can even throw away the vector, and directly create an iterator_range from the split_iterator. This way you may spare some unnecessary tokenization.
typedef split_iteratorstring::const_iterator string_split; iterator_range
r1( make_split_iterator(s1, is_any_of("/")), string_split()) iterator_range
r2( make_split_iterator(s2, is_any_of("/")), string_split()) if(lexicographical_compare(r1, r2, integer_compare)) { // s1 is less }
Regards, Pavol