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.
11 Answer
table is an array of std::list of std::pair, so table[i] is a std::list and it has size() function.