J
James Aguilar
Here is some example code I found from Google's hashtable implementation:
// Many STL algorithms use swap instead of copy constructors
void swap(sparse_hashtable& ht) {
STL_NAMESPACE::swap(hash, ht.hash);
STL_NAMESPACE::swap(equals, ht.equals);
STL_NAMESPACE::swap(get_key, ht.get_key);
STL_NAMESPACE::swap(num_deleted, ht.num_deleted);
STL_NAMESPACE::swap(use_deleted, ht.use_deleted);
{ value_type tmp; // for annoying reasons, swap() doesn't work
set_value(&tmp, delval);
set_value(&delval, ht.delval);
set_value(&ht.delval, tmp);
}
table.swap(ht.table);
reset_thresholds();
ht.reset_thresholds();
}
What do those braces with no identifier attached mean? Specifically, I mean the
block that starts on the same line as "// for annoying reasons, swap() doesn't
work"?
- JFA1
// Many STL algorithms use swap instead of copy constructors
void swap(sparse_hashtable& ht) {
STL_NAMESPACE::swap(hash, ht.hash);
STL_NAMESPACE::swap(equals, ht.equals);
STL_NAMESPACE::swap(get_key, ht.get_key);
STL_NAMESPACE::swap(num_deleted, ht.num_deleted);
STL_NAMESPACE::swap(use_deleted, ht.use_deleted);
{ value_type tmp; // for annoying reasons, swap() doesn't work
set_value(&tmp, delval);
set_value(&delval, ht.delval);
set_value(&ht.delval, tmp);
}
table.swap(ht.table);
reset_thresholds();
ht.reset_thresholds();
}
What do those braces with no identifier attached mean? Specifically, I mean the
block that starts on the same line as "// for annoying reasons, swap() doesn't
work"?
- JFA1