KDAB / KDAlgorithms

Algorithm wrappers
Other
82 stars 14 forks source link

min_element() fails to compile on custom container without an empty() method #51

Closed dfaure-kdab closed 1 year ago

dfaure-kdab commented 1 year ago

In my own class called Node, I wrote

            using value_type     = std::unique_ptr<AbstractPrintItem>;
        using const_iterator = std::vector<std::unique_ptr<AbstractPrintItem>>::const_iterator;
        const_iterator begin() const
        {
            return m_printItems.begin();
        }
        const_iterator end() const
        {
            return m_printItems.end();
        }

This works fine for range-for, and STL algorithms. But kdalgorithms::min_element failed to build with

kdalgorithms.h:214:19: error: ‘const class Node’ has no member named ‘empty’
  214 |     if (container.empty())

Shouldn't this be a begin()==end() test instead?