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<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

1 Answer

table is an array of std::list of std::pair, so table[i] is a std::list and it has size() function.

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like