On 2/19/07, Pavol Droba
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_iteratorstring::iterator. This is not the same (nor convertible) to split_iteratorstring::const_iterator.
So the simple fix would be to change the definition of the string_split to split_iteratorstring::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_rangestring::iterator)
For string '/1/1/5', following ranges will be returned
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
, T0 = __gnu_cxx::__normal_iterator
>, T1 = __gnu_cxx::__normal_iterator >]': /usr/include/boost/function/function_template.hpp:482: instantiated from `void boost::function2 ::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 , T0 = __gnu_cxx::__normal_iterator >, T1 = __gnu_cxx::__normal_iterator >, Allocator = std::allocatorboost::function_base]' /usr/include/boost/function/function_template.hpp:433: instantiated from `void boost::function2 ::assign_to(Functor) [with Functor = boost::algorithm::detail::is_any_ofF<char>, R = boost::algorithm::iterator_range<__gnu_cxx::__normal_iterator , T0 = __gnu_cxx::__normal_iterator >, T1 = __gnu_cxx::__normal_iterator >, Allocator = std::allocatorboost::function_base]' /usr/include/boost/function/function_template.hpp:289: instantiated from `boost::function2 ::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 , T0 = __gnu_cxx::__normal_iterator >, T1 = __gnu_cxx::__normal_iterator >, Allocator = std::allocatorboost::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 ]' /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 >]' /usr/include/boost/algorithm/string/find_iterator.hpp:351: instantiated from `boost::algorithm::split_iterator 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 >&, __gnu_cxx::__normal_iterator >&)' 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_iteratorstring::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
Regards, Pavol. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users