核心点:override >
直接上demo
工具类Logger可以直接用cout进行代替,这里使用的是封装后的的spdlog库
#include <boost/bimap.hpp>
struct User {
User() {}
User(std::string name,uint32_t ids,std::string psw):username(name),id(ids),password(psw){}
std::string username;
uint32_t id;
std::string password;
bool operator < (const User& other) const {
if (username > other.username) {
return true;
}
if (username > other.username) {
return false;
}
return false;
}
};
void main() {
typedef std::string string;
typedef boost::bimap<string, User> bimap;
LOGGER logger = ConsoleUtils::get_mutable_instance().getConsoleLogger("main");
bimap users;
User user1(string("lkj1"), 21, string("lkj21"));
User user2(string("lkj2"), 22, string("lkj22"));
User user3(string("lkj3"), 23, string("lkj23"));
User user4(string("lkj4"), 24, string("lkj24"));
users.insert(bimap::value_type("zhang1", user1));
users.insert(bimap::value_type("lkj1", user2));
users.insert(bimap::value_type("lkj2", user3));
users.insert(bimap::value_type("lkj3", user4));
//bimap::left_map::iterator it=users.left.find("lkj3");
//logger->info("{},{},{}",it->second.id,it->second.password,it->second.username);
User usersearch;
usersearch.username = "lkj1";
bimap::right_map::iterator it = users.right.find(usersearch);
logger->info("{},{},{}",it->first.id,it->first.password,it->first.username);
system("pause");
}