Boost logo

Boost Users :

From: Meryl Silverburgh (silverburgh.meryl_at_[hidden])
Date: 2007-02-20 15:23:50


On 2/20/07, Pavol Droba <droba_at_[hidden]> wrote:
> Meryl Silverburgh wrote:
> > On 2/20/07, Pavol Droba <droba_at_[hidden]> 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_range<std::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_range<string::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_range<string::iterator>'

Sorry if I mis-understand what you teach me.

From: Pavol Droba <droba_at_[hidden]>
Date: Feb 19, 2007 5:17 PM
Subject: Re: [Boost-users] Using Boost string library
To: boost-users_at_[hidden]

Hi,

Meryl Silverburgh wrote:

<snip>

>>>
>> 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_iterator<string::iterator>. This is
>> not the same (nor convertible) to split_iterator<string::const_iterator>.
>>
>> So the simple fix would be to change the definition of the string_split
>> to split_iterator<string::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_range<string::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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net