阅读背景:

使用'std :: algorithm'迭代自定义对的向量,没有显式循环

来源:互联网 

i wrote my own Pairs class:

我写了自己的Pairs类:

#include <string>
#include <utility>
template<class K, class V>
class MyPair : public std::pair<K, V>
{
public:
    MyPair(){};
    MyPair(const K & x, const V & y) : std::pair<K, V>(x, y) {} 
    friend bool operator==(const MyPair& p1, const MyPair &p2)
    {
        return p1.first == p2.first; // requires that type K implements operator=
    }
    bool operator() (const MyPair& p1, const MyPair &p2)
    {
        return ( p1.first < p2.first ); // requires that type K implements operator<
    }
};
#



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: