Boost logo

Boost Users :

From: Pavol Droba (droba_at_[hidden])
Date: 2007-02-19 18:17:19


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>)

For string '/1/1/5', following ranges will be returned
<begin, begin) == ""
<begin+1, begin+2) == "1"
<begin+3, begin+4) == "1"
<begin+5, begin+6) == "5"

A naive approach would be to convert the range to a string using
copy_range<string>(r1) and then simply convert the string to a number.
I'm sure a more effective way can be designed that does not involve the
copying.

There is one thing you should be aware of. If your sequence starts with
a separator, first token returned by the split_iterator is acutaly an
empty token (i.e everything from the start of the string to the first
separator == nothing). So make sure that you can handle this in your
predicate and that your strings are uniform in this regards.

Regards,
Pavol.


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