input_iterator.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef INPUT_ITERATOR_H
  9. #define INPUT_ITERATOR_H
  10. #include <iterator>
  11. template <class It>
  12. class input_iterator
  13. {
  14. It it_;
  15. public:
  16. typedef typename std::input_iterator_tag iterator_category;
  17. typedef typename std::iterator_traits<It>::value_type value_type;
  18. typedef typename std::iterator_traits<It>::difference_type difference_type;
  19. typedef It pointer;
  20. typedef typename std::iterator_traits<It>::reference reference;
  21. input_iterator() : it_() {}
  22. explicit input_iterator(It it) : it_(it) {}
  23. reference operator*() const {return *it_;}
  24. pointer operator->() const {return it_;}
  25. input_iterator& operator++() {++it_; return *this;}
  26. input_iterator operator++(int) {input_iterator tmp(*this); ++(*this); return tmp;}
  27. friend bool operator==(const input_iterator& x, const input_iterator& y)
  28. {return x.it_ == y.it_;}
  29. friend bool operator!=(const input_iterator& x, const input_iterator& y)
  30. {return !(x == y);}
  31. };
  32. #endif // INPUT_ITERATOR_H