Search code examples
c++algorithmmaxstd

Is there a handy way of finding largest element in container using STL?


Is there a way finding largest container inside a container using STL? ATM, I have this rather naïve way of doing it:


int main()
{
        std::vector<std::vector<int> > v;

        ...

        unsigned int h = 0;

        for (std::vector<std::vector<int> >::iterator i = v.begin(); i != v.end(); ++i) {
                if (*i.size() > h) {
                        h = *i.size();
                }
        }
}


Solution

  • You can always use std::max_element and pass a custom comparator that compares the size of two std::vector<int> as arguments.