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
default
VC++ error LNK2001 with combined use of non-type template parameters
hangman
throwing an exception containing a unique_ptr is dangerous
#9
Temp 1
what is this
PTaHHHa
ExtThes_Uniquify
CT1