fork(1) download
  1. #include <iterator>
  2.  
  3. template<class type>
  4. class value_iterator {
  5. public:
  6. typedef size_t difference_type;
  7. typedef type value_type;
  8. typedef const type& reference;
  9. typedef const type* pointer;
  10. typedef std::random_access_iterator_tag iterator_category;
  11.  
  12. value_iterator() :ptr() {}
  13. value_iterator(difference_type offset, const type& value) :off(offset), ptr(&value) {}
  14. friend bool operator==(const value_iterator& lhs, const value_iterator& rhs) {return lhs.ptr==rhs.ptr && lhs.off==rhs.off;}
  15. friend bool operator!=(const value_iterator& lhs, const value_iterator& rhs) {return lhs.ptr!=rhs.ptr || lhs.off!=rhs.off;}
  16. value_iterator& operator++() {++off; return *this;}
  17. value_iterator operator++(int) {return value_iterator(off++, *ptr);}
  18. value_iterator& operator--() {--off; return *this;}
  19. value_iterator operator--(int) {return value_iterator(off--, *ptr);}
  20. value_iterator& operator+=(difference_type o) {off+=o; return *this;}
  21. friend value_iterator operator+(const value_iterator& it, difference_type o) {return value_iterator(it.off+o, *it.ptr);}
  22. friend value_iterator operator+(difference_type o, const value_iterator& it) {return value_iterator(it.off+o, *it.ptr);}
  23. value_iterator& operator-=(difference_type o) {off-=o; return *this;}
  24. friend value_iterator operator-(const value_iterator& it, difference_type o) {return value_iterator(it.off-o, *it.ptr);}
  25. friend difference_type operator-(value_iterator lhs, value_iterator rhs) {return lhs.off-rhs.off;}
  26. reference operator*() const {return *ptr;}
  27. pointer operator->() const {return ptr;}
  28. reference operator[](difference_type) const {return *ptr;}
  29. friend void swap(value_iterator& lhs, value_iterator& rhs) {std::swap(lhs.ptr, rhs.ptr); std::swap(lhs.off, rhs.off);}
  30. private:
  31. difference_type off;
  32. const type* ptr;
  33. };
  34. template<class type> value_iterator<type> make_value_iterator(size_t count, const type& value) {return value_iterator<type>(count, value);}
  35. template<class type> value_iterator<type> make_value_iterator(const type& value) {return value_iterator<type>(0, value);}
  36.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout

Standard output is empty