Boost logo

Boost Users :

From: Meryl Silverburgh (silverburgh.meryl_at_[hidden])
Date: 2007-02-20 11:17:35


On 2/20/07, Pavol Droba <droba_at_[hidden]> wrote:
> Hi,
>
> Meryl Silverburgh wrote:
> > On 2/19/07, Pavol Droba <droba_at_[hidden]> wrote:
> <snip>
>
> >
> > Thanks for your help. I am getting the following error.
> > I haven't implemented integer_compare(), but I still can't get what I
> > have to compile:
> >
> > Build complete for project str
> >
> > #include <iostream>
> > #include <string>
> >
> > #include "boost/algorithm/string/find_iterator.hpp"
> > #include "boost/algorithm/string/classification.hpp"
> > using namespace std;
> > using namespace boost::algorithm;
> >
> > typedef split_iterator<string::iterator> string_split;
> >
> > class integer_compare {
> > public:
> > bool operator() (const string_split::value_type &a, const
> > string_split::value_type &b) {
> > return true;
> > }
> > };
> >
> > int main(int argc, char **argv) {
> > cout << "hello world" << endl;
> >
> > string s1("/1/11/2");
> > string s2("/1/1/3");
> >
> > iterator_range<string_split> r1(
> > make_split_iterator(s1, is_any_of("/")), string_split());
> >
> > iterator_range<string_split> r2(
> > make_split_iterator(s2, 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;
> > }
> >
> >
> > }
>
> So I forgot something else again. Shame on me. In the
> make_split_iterator call you have to specify a finder. I somehow forgot
> this. So the correct syntax is:
> make_split_iterator(s1, token_finder(is_any_of("/"))
>
> In addition there is a problem in using directives. I suggest you don't
> use using namespace boost::algorithms, but rather using namespace boost;
> In the current state, iterator_range is not available since it is in the
> namespace boost. It is actualy defined in boost.range library in in the
> string algorithms itself.
> All relevant string algorithms are pulled to namespace boost as well.
>
> Also, add another include
> #include <boost/algorithm/string/predicate.hpp> for lexicographical_compare.
>
> With these modification, I have tried and compiled the code successfully.
>

Thanks for your help again. However, I still have compilation error.
It still does not like make_split_iterator:

g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"stringCompare.d"
-MT"stringCompare.d" -o"stringCompare.o" "../stringCompare.cpp"
../stringCompare.cpp:44:2: warning: no newline at end of file
../stringCompare.cpp: In function 'int main(int, char**)':
../stringCompare.cpp:29: error: no matching function for call to
'make_split_iterator(std::string&,
boost::algorithm::detail::token_finderF<boost::algorithm::detail::is_any_ofF<char>
>, string_split)'
../stringCompare.cpp:32: error: no matching function for call to
'make_split_iterator(std::string&,
boost::algorithm::detail::token_finderF<boost::algorithm::detail::is_any_ofF<char>
>, string_split)'
make: *** [stringCompare.o] Error 1
make: Target `all' not remade because of errors.
Build complete for project sandbox

#include <iostream>
#include <string>

#include "boost/algorithm/string/find_iterator.hpp"
#include "boost/algorithm/string/classification.hpp"
#include "boost/algorithm/string/predicate.hpp"

using namespace std;
using namespace boost;

typedef split_iterator<string::iterator> string_split;

class integer_compare {
public:
       bool operator() (const string_split::value_type &a, const
string_split::value_type &b) {
               return true;
       }
};

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

       string s1("/1/11/2");
       string s2("/1/1/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;
               }

}

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