Is There a Size() Member Function for Std: :Pair?
I Was Following a Hash Table Implementation Tutorial and Came Across This: Class Hashtable { Private: Static Const Int hashGroups = 10; Std: :List...
I was following a hash table implementation tutorial and came across this:
class HashTable {
private:
static const int hashGroups = 10;
std::list<std::pair<int,std::string>> table[hashGroups];
bool HashTable::isEmpty() const {
int sum{};
for(int i{}; i < hashGroups; i++) {
sum += table[i].size();
}
if(!sum) {
return true;
}
return false;
}
In the isEmpty() member function, why is table[i].size() valid? In my interpretation, table is a list of pairs, therefore, table[i] should return a pair at index [i]. However, there are no member function size() in std::pair.
1 Answer
table is an array of std::list of std::pair, so table[i] is a std::list and it has size() function.