Skip to content

Instantly share code, notes, and snippets.

@kurenaif
Created April 19, 2016 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurenaif/4e9a649b1c983d0d7d755698c3f7b78c to your computer and use it in GitHub Desktop.
Save kurenaif/4e9a649b1c983d0d7d755698c3f7b78c to your computer and use it in GitHub Desktop.
#define oorret 0
#define oor(x) [&](){try{x;} catch(const std::out_of_range& oor){return oorret;} return x;}()
int main(void) {
vector<int> v;
v.push_back(100);
{
cout << v[0] << endl;
cout << oor(v.at(10000)) << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment