Boost logo

Boost Users :

From: Meryl Silverburgh (silverburgh.meryl_at_[hidden])
Date: 2007-02-20 16:27:43


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)

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