On 2/20/07, Pavol Droba
Meryl Silverburgh wrote:
On 2/20/07, Pavol Droba
wrote: Hi,
There is realy no magic there. You just need to realize, that you are not getting a string, rather a range. Range is a generalization of a pair of iterators.
In case of split_iterator, these iterators point to first and one past the last character of the current token.
Example can be found in /boost/libs/algorithm/string/example/split_example.cpp
Regards, Pavol.
Thanks for your help. I have another question, how can I can i terminate the for loop when loop using string_split?
class integer_compare { public: bool operator() (const string_split::value_type &a, const string_split::value_type &b) { // how can I iterate thru the string? how can i terminate the for loop?
for (const string_split sitr = a; sitr != ???; sitr++) {
// print out each substring (after '/' is stripped out) cout << copy_rangestd::string(*sitr) << endl;
} return true; } };
First of all, I don't understand your example. string_split::value_type is definitely not another split_iterator. it's type is (as I have mentioned in some previous mail) iterator_rangestring::iterator.
Pavol,
Thank for your help. I thought you said 'The question marks can be
substituted by
string_split::value_type'. In one of our previous exchange.
That is why I am using 'string_split::value_type' not
'iterator_rangestring::iterator'
Sorry if I mis-understand what you teach me.
From: Pavol Droba
The problem is with template instantiation. Since you are passing "string" and not "const string" as an argument to make_split_iterator, the resulting type is actualy split_iteratorstring::iterator. This is not the same (nor convertible) to split_iteratorstring::const_iterator.
So the simple fix would be to change the definition of the string_split to split_iteratorstring::iterator.
In addition, you will need to implement integer_compare.
In addition, you will need to implement integer_compare. I have not included it in may mail.
Thanks. I notice that. Can you please help me understand how to implement integer_compare (a predicate comparision object)?
What are the input type? bool operator() (const ? &a, const ? &b) ?
and if the input strings are '/1/1/5' and '1/1/10' what will be passed to the integer_compare?
It is an element comparison predicate therefore its arguments should be able to accept elements from the input sequence. So you have guessed the signature right. The question marks can be substituted by string_split::value_type. And that is an iterator_range pointing to a match found in the input string (iterator_rangestring::iterator)
As for the loop termination, default-initialized split_iterator (i.e. string_split) functions as a terminator. Alternatively you can check the eof() method.
Regards, Pavol. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users