使用 boost::tuple 作为键的地图查找

Map lookup using boost::tuple as key

我想了解如何在地图中查找 boost::tuple 形式的键,其中 Compare=std::less。例如,这是我正在处理的代码片段:

typedef boost::tuple<std::string, std::string> Key;
void *Data;

typedef std::map<Key, Data> FileDataMap;
FileDataMap file_map;

lookup_data(std::string s1, std::string s2)
{
    ...
    fk = boost::make_tuple(s1, s2);

    FileDataMap::iterator itr = file_map.find(fk);
    ...
    ...
}

insert_data(std::string s1, std::string s2, void *fdata)
{
    ...
    fk = boost::make_tuple(s1, s2);
    file_map.insert(std::make_pair(fk, fdata));
    ...
    ...
}

在向映射中插入值时,假设 s1abcs2xyz。在查找过程中,关键匹配是如何确定的?

s1s2 的字符串比较是否分别与 abcxyz 分别完成?如果是,是否使用了 std::string 比较运算符?

谢谢!

我写了代码来测试这个。测试表明确实使用定义的比较运算符对字符串进行了单独比较。

文档中的内容类似: http://en.cppreference.com/w/cpp/utility/tuple/operator_cmp