|
Boost Users : |
From: Meryl Silverburgh (silverburgh.meryl_at_[hidden])
Date: 2007-02-19 18:29:42
On 2/19/07, Pavol Droba <droba_at_[hidden]> wrote:
> Hi,
>
> Meryl Silverburgh wrote:
>
> <snip>
>
> >>>
> >> The problem is with template instantiation. Since you are passing
> >> "string" and not "const string" as an argument to make_split_iterator,
> >> the resulting type is actualy split_iterator<string::iterator>. This is
> >> not the same (nor convertible) to split_iterator<string::const_iterator>.
> >>
> >> So the simple fix would be to change the definition of the string_split
> >> to split_iterator<string::iterator>.
> >>
> > In addition, you will need to implement integer_compare.
> >> In addition, you will need to implement integer_compare. I have not
> >> included it in may mail.
> >
> > Thanks. I notice that. Can you please help me understand how to
> > implement integer_compare (a predicate comparision object)?
> >
> > What are the input type?
> > bool operator() (const ? &a, const ? &b) ?
> >
> > and if the input strings are '/1/1/5' and '1/1/10'
> > what will be passed to the integer_compare?
> >
>
> It is an element comparison predicate therefore its arguments should be
> able to accept elements from the input sequence. So you have guessed the
> signature right. The question marks can be substituted by
> string_split::value_type. And that is an iterator_range pointing to a
> match found in the input string (iterator_range<string::iterator>)
>
> For string '/1/1/5', following ranges will be returned
> <begin, begin) == ""
> <begin+1, begin+2) == "1"
> <begin+3, begin+4) == "1"
> <begin+5, begin+6) == "5"
>
> A naive approach would be to convert the range to a string using
> copy_range<string>(r1) and then simply convert the string to a number.
> I'm sure a more effective way can be designed that does not involve the
> copying.
>
> There is one thing you should be aware of. If your sequence starts with
> a separator, first token returned by the split_iterator is acutaly an
> empty token (i.e everything from the start of the string to the first
> separator == nothing). So make sure that you can handle this in your
> predicate and that your strings are uniform in this regards.
>
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:
../test.cpp:40:2: warning: no newline at end of file
/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:25: 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
#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;
}
}
> 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