}
StringRef CPU = ArchMap.lookup(A->getValue());
if (CPU.empty()) {
- std::vector<StringRef> ValidArchs;
- for (StringRef Key : ArchMap.keys())
- ValidArchs.push_back(Key);
+ std::vector<StringRef> ValidArchs{ArchMap.keys().begin(),
+ ArchMap.keys().end()};
sort(ValidArchs);
D.Diag(diag::warn_drv_invalid_arch_name_with_suggestion)
<< A->getValue() << (Triple.getArch() == llvm::Triple::x86)
explicit StringMapKeyIterator(StringMapConstIterator<ValueTy> Iter)
: base(std::move(Iter)) {}
- StringRef &operator*() {
- Key = this->wrapped()->getKey();
- return Key;
- }
-
-private:
- StringRef Key;
+ StringRef operator*() const { return this->wrapped()->getKey(); }
};
} // end namespace llvm
EXPECT_EQ(0, try1.first->second.copy);
}
-TEST_F(StringMapTest, IterMapKeys) {
+TEST_F(StringMapTest, IterMapKeysVector) {
+ StringMap<int> Map;
+ Map["A"] = 1;
+ Map["B"] = 2;
+ Map["C"] = 3;
+ Map["D"] = 3;
+
+ std::vector<StringRef> Keys{Map.keys().begin(), Map.keys().end()};
+ llvm::sort(Keys);
+
+ std::vector<StringRef> Expected{{"A", "B", "C", "D"}};
+ EXPECT_EQ(Expected, Keys);
+}
+
+TEST_F(StringMapTest, IterMapKeysSmallVector) {
StringMap<int> Map;
Map["A"] = 1;
Map["B"] = 2;