Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include "std_lib_facilities.h"//from B. Stroustrup's site
  2.  
  3. using Line = vector<char>;
  4.  
  5. class Text_iterator {
  6.  
  7. list<Line>::iterator ln; //points to lines
  8. Line::iterator pos; //points to characters
  9.  
  10. public:
  11. Text_iterator(list<Line>::iterator ll, Line::iterator pp)
  12. :ln{ll}, pos{pp} { }
  13. char& operator*() { return *pos; }
  14. Text_iterator& operator++();
  15. bool operator==(const Text_iterator& other) const
  16. { return ln==other.ln && pos==other.pos; }
  17. bool operator!=(const Text_iterator& other) const
  18. { return !(*this==other); }
  19. };
  20.  
  21. Text_iterator& Text_iterator::operator++()
  22. {
  23. ++pos;
  24. if (pos==(*ln).end()) {
  25. ++ln;
  26. pos = (*ln).begin();
  27. }
  28. return *this;
  29. }
  30.  
  31. Text_iterator find_txt(Text_iterator first, Text_iterator last, const string& s)
  32. {
  33. if (s.size()==0) return last;// can’t find an empty stringchar first_char = s[0];
  34. char first_char = s[0];
  35. while (true) {
  36. auto p = find(first, last, first_char); //<------------the PROBLEM!!!!!!
  37. //if (p==last || match(p,last,s)) return p;
  38. //first = ++p;// look at the next character
  39. }
  40. }
  41.  
  42. void ex6()
  43. {
  44. ;
  45. }
  46.  
  47.  
  48. int main()
  49. {
  50. ex6();
  51. }
  52.  
  53. template<typename _Iterator, typename _Predicate>
  54. inline _Iterator
  55. __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
  56. {
  57. return __find_if(__first, __last, __pred,
  58. std::__iterator_category(__first)); //this is line #162 in stl_algo.h
  59. }
  60.  
  61. template<typename _Iter>
  62. inline typename iterator_traits<_Iter>::iterator_category
  63. __iterator_category(const _Iter&)//this is line #204 in stl_iterator_base_types.h
  64. { return typename iterator_traits<_Iter>::iterator_category(); }
  65.  
  66. namespace std {
  67. template<>
  68. struct iterator_traits<Text_iterator> {
  69. typedef ptrdiff_t difference_type;
  70. typedef char value_type;
  71. typedef char* pointer;
  72. typedef char& reference;
  73. typedef input_iterator_tag iterator_category;
  74. };
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement