fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. #include <cassert>
  6.  
  7. int main() {
  8.  
  9. using namespace std;
  10.  
  11. int value = 1;
  12. vector<int> values;
  13. for( int cnt = 0; cnt != 10; ++cnt )
  14. values.push_back( value++ );
  15.  
  16. // values = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
  17. assert( values.front() == 1 && values.back() == 10 );
  18.  
  19. // find the position of element 5
  20. vector<int>::reverse_iterator found = find( values.rbegin(), values.rend(), 5 );
  21. // { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
  22. // ^
  23. assert( *found == 5 );
  24. // { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
  25. // ^
  26. assert( *found.base() == 6 );
  27. // { 1, 2, 3, 4, 6, 7, 8, 9, 10 }
  28. values.erase( ++found.base() );
  29. assert( values[ 5 ] == 6 );
  30. }
Success #stdin #stdout 0.02s 2852KB
stdin
Standard input is empty
stdout
Standard output is empty