When I pass custom iterator arguments to std :: find (), GCC 5.2.1. the compiler (on Ubuntu 15.10) gives two error messages:
(1)
/usr/include/++/5/bits/stl_algo.h: 162: 34: error: no match function to call '__iterator_category (Text_iterator &)
standard :: __ iterator_category (__ first));
(2)
/usr/include/++/5/bits/stl_iterator_base_types.h: 204: 5: error: none type named 'iterator_category in' struct std :: iterator_traits
The error is caused by the line auto p = find(first, last, first_char);that is inside the find_txt () function. When a line is commented out, the code compiles easily. Here is a piece of code that causes errors:
#include "std_lib_facilities.h"
using Line = vector<char>;
class Text_iterator {
list<Line>::iterator ln;
Line::iterator pos;
public:
Text_iterator(list<Line>::iterator ll, Line::iterator pp)
:ln{ll}, pos{pp} { }
char& operator*() { return *pos; }
Text_iterator& operator++();
bool operator==(const Text_iterator& other) const
{ return ln==other.ln && pos==other.pos; }
bool operator!=(const Text_iterator& other) const
{ return !(*this==other); }
};
Text_iterator& Text_iterator::operator++()
{
++pos;
if (pos==(*ln).end()) {
++ln;
pos = (*ln).begin();
}
return *this;
}
Text_iterator find_txt(Text_iterator first, Text_iterator last, const string& s)
{
if (s.size()==0) return last;
char first_char = s[0];
while (true) {
auto p = find(first, last, first_char);
}
}
void ex6()
{
;
}
int main()
{
ex6();
}
I mentioned the files mentioned in the error messages:
template<typename _Iterator, typename _Predicate>
inline _Iterator
__find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
{
return __find_if(__first, __last, __pred,
std::__iterator_category(__first));
}
and
template<typename _Iter>
inline typename iterator_traits<_Iter>::iterator_category
__iterator_category(const _Iter&)
{ return typename iterator_traits<_Iter>::iterator_category(); }
auto p = find(first, last, first_char); GCC, stl_algo.h stl_iterator_base_types.h? ?
6, 20 " ": ++, 2- . . std:: find() . funtion.