C++实现的支持插入顺序的高效map

https://github.com/nlohmann/fifo_map

#include "src/fifo_map.hpp"

// for convenience
using nlohmann::fifo_map;

int main() {
    // create fifo_map with template arguments
    fifo_map<int, std::string> m;

    // add elements
    m[2] = "two";
    m[3] = "three";
    m[1] = "one";
    
    // output the map; will print
    // 2: two
    // 3: three
    // 1: one
    for (auto x : m) {
        std::cout << x.first << ": " << x.second << "\n";
    }
    
    // delete an element
    m.erase(2);
    
    // re-add element
    m[2] = "zwei";
    
    // output the map; will print
    // 3: three
    // 1: one
    // 2: zwei
    for (auto x : m) {
        std::cout << x.first << ": " << x.second << "\n";
    }
}

猜你喜欢

转载自blog.csdn.net/v6543210/article/details/83016798