本文整理汇总了C++中LinkedHashMap::keys方法的典型用法代码示例。如果您正苦于以下问题:C++ LinkedHashMap::keys方法的具体用法?C++ LinkedHashMap::keys怎么用?C++ LinkedHashMap::keys使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedHashMap
的用法示例。
在下文中一共展示了LinkedHashMap::keys方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: foreach
TEST(LinkedHashmapTest, Keys)
{
LinkedHashMap<string, int> map;
list<string> keys = {"foo", "bar", "food", "rad", "cat"};
// Insert keys into the map.
foreach (const string& key, keys) {
map[key] = 1;
}
map["foo"] = 1; // Re-insert a key.
// Ensure the keys returned are the same as insertion order.
ASSERT_EQ(keys, map.keys());
}
示例2: foreach
TEST(LinkedHashmapTest, Keys)
{
LinkedHashMap<string, int> map;
std::list<string> keys;
keys.push_back("foo");
keys.push_back("bar");
keys.push_back("food");
keys.push_back("rad");
keys.push_back("cat");
// Insert keys into the map.
foreach (const string& key, keys) {
map[key] = 1;
}
map["foo"] = 1; // Re-insert a key.
// Ensure the keys returned are the same as insertion order.
ASSERT_EQ(keys, map.keys());
}
示例3: foreachpair
TEST(LinkedHashMapTest, Foreach)
{
LinkedHashMap<string, int> map;
map["foo"] = 1;
map["bar"] = 2;
map["caz"] = 3;
map["foo"] = 4; // Re-insert a key.
list<string> keyList = map.keys();
list<int> valueList = map.values();
vector<string> keys{keyList.begin(), keyList.end()};
vector<int> values{valueList.begin(), valueList.end()};
{
int i = 0;
foreachpair (const string& key, int value, map) {
EXPECT_EQ(keys[i], key);
EXPECT_EQ(values[i], value);
i++;
}
}