M
Mike Austin
Hi all. Just working on a small virtual machine, and thought about using
vector iterators instead of pointer arithmetic. Question is, why does an
iterator plus any number out of range not generate a out_of_range exception?
Maybe this is a gcc issue?
I'm using gcc version 3.3.3 (cygwin special).
Here's the full sample code:
#include <iostream>
#include <vector>
#include <stdexcept>
using namespace std;
int main() {
vector<int> code;
code.push_back( 10L );
code.push_back( 20L );
vector<int>::iterator iter = code.begin();
try {
cout << *(iter + 5) << endl; // 0
cout << code.at( 10 ) << endl; // vector [] access out of range
} catch( out_of_range e ) {
cout << e.what() << endl;
}
return 0;
}
Thanks,
Mike
vector iterators instead of pointer arithmetic. Question is, why does an
iterator plus any number out of range not generate a out_of_range exception?
Maybe this is a gcc issue?
I'm using gcc version 3.3.3 (cygwin special).
Here's the full sample code:
#include <iostream>
#include <vector>
#include <stdexcept>
using namespace std;
int main() {
vector<int> code;
code.push_back( 10L );
code.push_back( 20L );
vector<int>::iterator iter = code.begin();
try {
cout << *(iter + 5) << endl; // 0
cout << code.at( 10 ) << endl; // vector [] access out of range
} catch( out_of_range e ) {
cout << e.what() << endl;
}
return 0;
}
Thanks,
Mike