Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
"Mostly invalid states" and unordered_set
#include <unordered_set> #include <stdio.h> static int throw_when_hashing = 0; struct H { size_t operator()(int i) const { if (i == throw_when_hashing) throw "oops"; return i; } }; int main() { std::unordered_set<int, H> s; for (int i : {1,2,3,4,5,6,7,8}) { printf("Inserting %d...\n", i); s.emplace(i); } throw_when_hashing = 5; try { s.emplace(9); } catch (...) {} auto it = std::find(s.begin(), s.end(), 6); auto jt = s.find(6); printf("std::find %s with s.find\n", (it == jt) ? "agrees" : "disagrees"); printf("s holds:\n"); for (auto&& elt : s) printf("%d\n", elt); printf("But s.count(6) returns: %zu\n", s.count(6)); }
run
|
edit
|
history
|
help
0
MSVC14 <exception> header
Default constructor - none defined
Computing factorial of an integer with recursion and iteration [EDIT]
rang_warnings
C++ string format
Default constructor - deleted
Copy double[2][3] into vector<vector<double>>
vaska
Progress bar
Hangman