What do empty braces inside a method mean?

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
 
V

Victor Bazarov

James said:
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"?

It's a compound statement ("a block") which limits the scope of the 'tmp'
variable.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top