Boost logo

Boost Users :

From: Meryl Silverburgh (silverburgh.meryl_at_[hidden])
Date: 2007-02-19 15:03:47


On 2/18/07, Pavol Droba <droba_at_[hidden]> wrote:
> Hi,
>
> Meryl Silverburgh wrote:
> > Thanks for your idea.
> >
> > I have cases like this:
> >
> > /1/1
> > /1/2/3/2
> >
> > Since the first string /1/1 is smaller than the /1/2 (1 is < 2) of the
> > /1/2/3/2, I should able to stop comparison by looking at the 4th
> > character (/1/2) of '/1/2/3/2'.
> >
> > So for cases like that, I would like to stop as soon as i can tell one
> > string is shorter than the other, instead of splitting the whole
> > string.
> >
> >
> >
>
> This is exactly what would happen you use the second approach I gave you.
> Constructing the iterator_range from the split iterator does not perform
> any actual searching, and lexicographical_compare stops on the first
> possible index (i.e on the first position where inputs are different).
>
>
> >>
> >> You can even throw away the vector, and directly create an
> >> iterator_range from the split_iterator. This way you may spare some
> >> unnecessary tokenization.
> >>
> >> typedef split_iterator<string::const_iterator> string_split;
> >> 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, r2, integer_compare))
> >> {
> >> // s1 is less
> >> }
>
> Regards,
> Pavol

Pavol,

Thanks for your help. I am trying your second approach. But I am
having compilation error in this line:
iterator_range<string_split> r1(
                        make_split_iterator(s1, is_any_of("/")), string_split());
error:
../test.cpp:18: error: no matching function for call to
`boost::algorithm::iterator_range<string_split>::iterator_range(boost::algorithm::split_iterator<__gnu_cxx::__normal_iterator<char*,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
> >, string_split)'
/usr/include/boost/algorithm/string/iterator_range.hpp:89: note:
candidates are:
boost::algorithm::iterator_range<IteratorT>::iterator_range(const
boost::algorithm::iterator_range<IteratorT>&) [with IteratorT =
string_split]
/usr/include/boost/algorithm/string/iterator_range.hpp:85: note:

Complete program:
#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::const_iterator> string_split;

int main(int argc, char **argv) {
        cout << "hello world" << endl;
        
        string s1("/1/1/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, r2, integer_compare))
                {
                        cout << " s1 is less " << endl;
                } else {
                        cout << " s2 is less " << endl;
                }
                }
        
}

complete error:

**** Build of configuration Debug for project str ****

make -k all
Building file: ../test.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"test.d"
-MT"test.d" -o"test.o" "../test.cpp"
../test.cpp: In function `int main(int, char**)':
../test.cpp:18: error: no matching function for call to
`boost::algorithm::iterator_range<string_split>::iterator_range(boost::algorithm::split_iterator<__gnu_cxx::__normal_iterator<char*,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
> >, string_split)'
/usr/include/boost/algorithm/string/iterator_range.hpp:89: note:
candidates are:
boost::algorithm::iterator_range<IteratorT>::iterator_range(const
boost::algorithm::iterator_range<IteratorT>&) [with IteratorT =
string_split]
/usr/include/boost/algorithm/string/iterator_range.hpp:85: note:
          boost::algorithm::iterator_range<IteratorT>::iterator_range(const
std::pair<_ForwardIterator, _ForwardIterator>&) [with IteratorT =
string_split]
/usr/include/boost/algorithm/string/iterator_range.hpp:81: note:
          boost::algorithm::iterator_range<IteratorT>::iterator_range(IteratorT,
IteratorT) [with IteratorT = string_split]
/usr/include/boost/algorithm/string/iterator_range.hpp:77: note:
          boost::algorithm::iterator_range<IteratorT>::iterator_range()
[with IteratorT = string_split]
../test.cpp:21: error: no matching function for call to
`boost::algorithm::iterator_range<string_split>::iterator_range(boost::algorithm::split_iterator<__gnu_cxx::__normal_iterator<char*,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
> >, string_split)'
/usr/include/boost/algorithm/string/iterator_range.hpp:89: note:
candidates are:
boost::algorithm::iterator_range<IteratorT>::iterator_range(const
boost::algorithm::iterator_range<IteratorT>&) [with IteratorT =
string_split]
/usr/include/boost/algorithm/string/iterator_range.hpp:85: note:
          boost::algorithm::iterator_range<IteratorT>::iterator_range(const
std::pair<_ForwardIterator, _ForwardIterator>&) [with IteratorT =
string_split]
/usr/include/boost/algorithm/string/iterator_range.hpp:81: note:
          boost::algorithm::iterator_range<IteratorT>::iterator_range(IteratorT,
IteratorT) [with IteratorT = string_split]
/usr/include/boost/algorithm/string/iterator_range.hpp:77: note:
          boost::algorithm::iterator_range<IteratorT>::iterator_range()
[with IteratorT = string_split]
../test.cpp:23: error: `integer_compare' was not declared in this scope
../test.cpp:23: warning: unused variable 'integer_compare'
../test.cpp: At global scope:
../test.cpp:31: error: expected declaration before '}' token
/usr/include/boost/function/function_template.hpp: In static member
function `static R
boost::detail::function::function_obj_invoker2<FunctionObj, R, T0,
T1>::invoke(boost::detail::function::any_pointer, T0, T1) [with
FunctionObj = boost::algorithm::detail::is_any_ofF<char>, R =
boost::algorithm::iterator_range<__gnu_cxx::__normal_iterator<char*,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
> >, T0 = __gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, T1 =
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >]':
/usr/include/boost/function/function_template.hpp:482: instantiated
from `void boost::function2<R, T0, T1,
Allocator>::assign_to(FunctionObj,
boost::detail::function::function_obj_tag) [with FunctionObj =
boost::algorithm::detail::is_any_ofF<char>, R =
boost::algorithm::iterator_range<__gnu_cxx::__normal_iterator<char*,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
> >, T0 = __gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, T1 =
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, Allocator =
std::allocator<boost::function_base>]'
/usr/include/boost/function/function_template.hpp:433: instantiated
from `void boost::function2<R, T0, T1, Allocator>::assign_to(Functor)
[with Functor = boost::algorithm::detail::is_any_ofF<char>, R =
boost::algorithm::iterator_range<__gnu_cxx::__normal_iterator<char*,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
> >, T0 = __gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, T1 =
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, Allocator =
std::allocator<boost::function_base>]'
/usr/include/boost/function/function_template.hpp:289: instantiated
from `boost::function2<R, T0, T1, Allocator>::function2(Functor,
typename boost::enable_if_c< boost::type_traits::ice_not<
boost::is_integral<Functor>::value>::value, int>::type) [with Functor
= boost::algorithm::detail::is_any_ofF<char>, R =
boost::algorithm::iterator_range<__gnu_cxx::__normal_iterator<char*,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
> >, T0 = __gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, T1 =
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, Allocator =
std::allocator<boost::function_base>]'
/usr/include/boost/algorithm/string/detail/find_iterator.hpp:50:
instantiated from
`boost::algorithm::detail::find_iterator_base<IteratorT>::find_iterator_base(FinderT,
int) [with FinderT = boost::algorithm::detail::is_any_ofF<char>,
IteratorT = __gnu_cxx::__normal_iterator<char*,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>]'
/usr/include/boost/algorithm/string/find_iterator.hpp:262:
instantiated from
`boost::algorithm::split_iterator<IteratorT>::split_iterator(IteratorT,
IteratorT, FinderT) [with FinderT =
boost::algorithm::detail::is_any_ofF<char>, IteratorT =
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >]'
/usr/include/boost/algorithm/string/find_iterator.hpp:351:
instantiated from `boost::algorithm::split_iterator<typename
boost::algorithm::result_iterator_of<C>::type>
boost::algorithm::make_split_iterator(CollectionT&, FinderT) [with
CollectionT = std::string, FinderT =
boost::algorithm::detail::is_any_ofF<char>]'
../test.cpp:18: instantiated from here
/usr/include/boost/function/function_template.hpp:111: error: no match
for call to `(boost::algorithm::detail::is_any_ofF<char>)
(__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >&,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >&)'
make: *** [test.o] Error 1
make: Target `all' not remade because of errors.
Build complete for project str

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