UVTEMPLATE void UVBASE::swap_values (pointer p0, pointer p1) {
value_type t(move(*p0));
allocator.destroy(p0);
try { allocator.construct(p0,move(*p1)); }
catch (...) { allocator.construct(p0,sentinel()); throw; }
allocator.destroy(p1);
try { allocator.construct(p1,move(t)); }
catch (...) { allocator.construct(p1,sentinel()); throw; }
}I think that should work (though TBH I haven't had the chance to compile/test it) but the judicious use of try/catch blocks has me worried about performance. How do normal stl containers handle this? For example:
vector<const int> v; v.push_back(2); v.push_back(8); v.insert(v.begin(),10); cout << "v[0] = " << v[0] << endl;
works fine, compiles and runs as expected. How do they handle the situation where a copy constructor throws an exception when moving/copying/swapping items around?
Edited by Ryan_001, 19 October 2012 - 09:28 AM.






