Is There a Size() Member Function for Std: :Pair?

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

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

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.