标签:type name other vector str 队列 font until val
以优先队列为例,从cppreference查得,它的模板为
template< class T, class Container = std::vector<T>, class Compare = std::less<typename Container::value_type> > class priority_queue;
所以我们要定义一个Compare类实现less的功能,在观察less类的内容,https://en.cppreference.com/w/cpp/utility/functional/less
std::less::operator() bool operator()( const T& lhs, const T& rhs ) const;(until C++14) constexpr bool operator()( const T& lhs, const T& rhs ) const;(since C++14) Checks whether lhs is less than rhs. Parameters lhs, rhs - values to compare Return value true if lhs < rhs, false otherwise.
constexpr bool operator()(const T &lhs, const T &rhs) const { return lhs < rhs; }
实现非常简单,只要对我们自定义的类实现operator()重载即可
标签:type name other vector str 队列 font until val
原文地址:https://www.cnblogs.com/bloomingFlower/p/9602174.html