Boost logo

Boost Users :

From: Pavol Droba (droba_at_[hidden])
Date: 2007-02-20 17:53:01


Meryl Silverburgh wrote:
> On 2/20/07, Pavol Droba <droba_at_[hidden]> wrote:
>>> Thanks, I did try just doing this
>>> cout << copy_range<std::string>(a) << endl;
>>> cout << copy_range<std::string>(b) << endl;
>>>
>>> But I find out that 'integer_compare' just call once, and it is an empty string.
>>>
>>> My input strings were "/1/11/2", "1/9/2". From your previous message,
>>> I understand the first time return an empty string, but I do expect
>>> integer_compare will call again and again like "1", "11", "2", "1",
>>> "9" ,"2"....
>>> But it did not happens.
>>>
>>>
>> Great, we are getting to the finish ;) There is just one slight problem,
>> that I have overlooked in your code.
>>
>> lexicographical_compare simply forwards the call to
>> std::lexicographical_compare
>> http://www.sgi.com/tech/stl/lexicographical_compare.html
>>
>> So the given predicate (integer_compare) functions as *isless*. It
>> means, that it should return true if the first argument is *less* then
>> the second one. In case of equality it should return false.
>>
>> In your case, lexicographical_compare stopped on the first tokens, since
>> the predicate reported that one is less then other. No other comparison
>> was necessary to get the result.
>>
>> Try to change the result to false. You should be seeing the output from
>> whole inputs.
>>
>> Best regards,
>> Pavol.
>
> Pavol,
>
> Thank you very much for your effort/time/help.
> Yes, I do see the output. But still one question, why my function
> integer_compare is being call 2 times for every sub-string?
>
> my input strings are string s1("/1/11/2"), string s2("/1/9/3");
>
> Here is my output:
>
> calling integer_compare
> ()
> ()
> calling integer_compare
> ()
> ()
> calling integer_compare
> (1)
> (1)
> calling integer_compare
> (1)
> (1)
> calling integer_compare
> (11)
> (9)
> calling integer_compare
> (9)
> (11)
> calling integer_compare
> (2)
> (3)
> calling integer_compare
> (3)
> (2)
>

If you look better, you see that the arguments are reversed in the
second call. because the interger_compare implements only '<' operation,
we need actualy to call it twise to get ==.

Anyway, if you find lexicographical_compare insufficient in some
regards, I'm sure you can now implement version that suits your needs.

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