C++ 模板多继承

#include <iostream>
#include<string>
#include <unordered_set>

class Customer{
private:
    std::string name;
public:
    Customer(std::string const&n):name(n){}
    std::string getName() const{
        return name;
    }
};

struct CustomerEq{
    bool operator()(Customer const&c1,Customer const&c2)const{
        return c1.getName() == c2.getName();
    }
};
struct CustomerHash {
    std::size_t operator()(Customer const &c) const {
        return std::hash<std::string>()(c.getName());
    }
};
template<typename ...Bases>
struct Overloader:Bases...
{
    using Bases::operator()...;
};

int main() {
    using CustomerOP = Overloader<CustomerHash,CustomerEq>;

    std::unordered_set<Customer,CustomerHash,CustomerEq>col1;

    std::unordered_set<Customer,CustomerOP,CustomerOP>col2;
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

上一篇:对象网关服务器端加密


下一篇:手写一个简化版的Spring