input_iterator.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef INPUT_ITERATOR_H
  10. #define INPUT_ITERATOR_H
  11. #include <iterator>
  12. template <class It>
  13. class input_iterator
  14. {
  15. It it_;
  16. public:
  17. typedef typename std::input_iterator_tag iterator_category;
  18. typedef typename std::iterator_traits<It>::value_type value_type;
  19. typedef typename std::iterator_traits<It>::difference_type difference_type;
  20. typedef It pointer;
  21. typedef typename std::iterator_traits<It>::reference reference;
  22. input_iterator() : it_() {}
  23. explicit input_iterator(It it) : it_(it) {}
  24. reference operator*() const {return *it_;}
  25. pointer operator->() const {return it_;}
  26. input_iterator& operator++() {++it_; return *this;}
  27. input_iterator operator++(int) {input_iterator tmp(*this); ++(*this); return tmp;}
  28. friend bool operator==(const input_iterator& x, const input_iterator& y)
  29. {return x.it_ == y.it_;}
  30. friend bool operator!=(const input_iterator& x, const input_iterator& y)
  31. {return !(x == y);}
  32. };
  33. #endif // INPUT_ITERATOR_H