Boost logo

Boost Users :

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


On 2/20/07, Pavol Droba <droba_at_[hidden]> wrote:
> Hi,
>
> Meryl Silverburgh wrote:
> > On 2/20/07, Pavol Droba <droba_at_[hidden]> wrote:
> >>> 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.
> >>>
> >> No worries.
> >>
> >> There is no problem with using string_split::value_type. It is just
> >> a typedef to iterator_range<string::iterator>. In your code, you
> >> misplaced it with string_split itself.
> >>
> >
> > I change the integer_compare class to use iterator_range<string::iterator>&.
> >
> > And I am trying to loop thru the iterator_range inside the function()
> > of integer_compare:
> >
> > bool operator() (const iterator_range<string::iterator>& a,
> >
> > const iterator_range<string::iterator>& b) {
> > cout << "calling integer_compare " << endl;
> >
> > // expect to print out "", "1", "1", "2" for a string of "/1/1/2"
> > for (string::iterator sitr = a.begin(); sitr != a.end(); sitr++) {
> >
> > cout << copy_range<std::string>(*sitr) << endl;
> >
> > }
> > return true;
> > }
> >
>
> Please, see the iterator_range documentation:
> http://www.boost.org/libs/range/doc/utility_class.html#iter_range
>
> Although you changed the names of parameters, you are still using
> iterator_range as if it was a split_iterator.
>
> copy_range copies a *range* to a given container. when you dereference
> a string::iterator, you will not get a *range*, rather a single character.
>
> Instead of "for" loop you should use just
> cout << copy_range<std::string>(a) << endl;
>

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.

class integer_compare {
public:
    // bool operator() (const string_split::value_type &a, const
//string_split::value_type &b) {
        
        bool operator() (const iterator_range<string::iterator>& a,
        
        const iterator_range<string::iterator>& b) {
                cout << "calling integer_compare " << endl;
                
                cout << copy_range<std::string>(a) << endl;
                cout << copy_range<std::string>(b) << endl;
                /*
                for (string::iterator sitr = a.begin(); sitr != a.end(); sitr++) {
                        
                        cout << copy_range<std::string>(*sitr) << endl;
                        
                }*/
               return true;
       }

};

int main(int argc, char **argv) {
       cout << "hello world" << endl;

       string s1("/1/11/2");
       string s2("/1/9/3");

       iterator_range<string_split> r1(
                       make_split_iterator(s1,
token_finder(is_any_of("/"))), string_split());

               iterator_range<string_split> r2(
                       make_split_iterator(s2,
token_finder(is_any_of("/"))), string_split());

               if(lexicographical_compare(r1.begin(), r1.end(),

                               r2.begin(), r2.end(), integer_compare()))
               {
                       cout << " s1 is less " << endl;
               } else {
                       cout << " s2 is less " << endl;
               }

}

> 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