fork download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <vector>
  4.  
  5. class my_iterator : public std::iterator<std::bidirectional_iterator_tag, int> {
  6. int d_val = 12;
  7. public:
  8. my_iterator operator--(int) { std::cout << "decrement--\n"; return my_iterator(); }
  9. my_iterator &operator--() { std::cout << "--decrement\n"; return *this; }
  10. my_iterator operator++(int) { std::cout << "increment++\n"; return my_iterator(); }
  11. my_iterator &operator++() { std::cout << "++increment\n"; return *this; }
  12.  
  13. int &operator*() { std::cout << "*dereference\n"; return d_val; }
  14.  
  15. bool operator==(my_iterator const &o) { return false; }
  16. bool operator!=(my_iterator const &o) { return true ; }
  17. };
  18.  
  19.  
  20. int main() {
  21. auto it = std::reverse_iterator<my_iterator>();
  22. int &i = *it;
  23. if (true)
  24. {
  25. std::cout << i << '\n';
  26. }
  27. else
  28. {
  29. std::vector<int> vec;
  30. vec.push_back(i);
  31. std::cout << vec[0] << '\n';
  32. }
  33. }
Runtime error #stdin #stdout 0s 3224KB
stdin
Standard input is empty
stdout
Standard output is empty