Index: llvm/include/llvm/ADT/StringMap.h =================================================================== --- llvm/include/llvm/ADT/StringMap.h +++ llvm/include/llvm/ADT/StringMap.h @@ -359,6 +359,11 @@ return find(Key) == end() ? 0 : 1; } + template + size_type count(const StringMapEntry &MapEntry) const { + return count(MapEntry.getKey()); + } + /// insert - Insert the specified key/value pair into the map. If the key /// already exists in the map, return false and ignore the request, otherwise /// insert it and return true. Index: llvm/include/llvm/ADT/StringSet.h =================================================================== --- llvm/include/llvm/ADT/StringSet.h +++ llvm/include/llvm/ADT/StringSet.h @@ -45,6 +45,12 @@ for (auto It = Begin; It != End; ++It) base::insert(std::make_pair(*It, '\0')); } + + template + std::pair + insert(const StringMapEntry &MapEntry) { + return insert(MapEntry.getKey()); + } }; } // end namespace llvm Index: llvm/unittests/ADT/CMakeLists.txt =================================================================== --- llvm/unittests/ADT/CMakeLists.txt +++ llvm/unittests/ADT/CMakeLists.txt @@ -52,6 +52,7 @@ STLExtrasTest.cpp ScopeExitTest.cpp SequenceTest.cpp + SetOperationsTest.cpp SetVectorTest.cpp SimpleIListTest.cpp SmallPtrSetTest.cpp Index: llvm/unittests/ADT/SetOperationsTest.cpp =================================================================== --- /dev/null +++ llvm/unittests/ADT/SetOperationsTest.cpp @@ -0,0 +1,29 @@ +//===- llvm/unittest/ADT/StringMapMap.cpp - StringMap unit tests ----------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/SetOperations.h" +#include "llvm/ADT/StringSet.h" +#include "gtest/gtest.h" +using namespace llvm; + +namespace { + +// Test fixture +class SetOperationsTest : public testing::Test {}; +TEST_F(SetOperationsTest, StringSetDiffTest) { + StringSet<> SS1{"a", "b"}; + StringSet<> SS2{"a"}; + + auto Diff = set_difference(SS1, SS2); + auto DiffVec = to_vector<1>(Diff.keys()); + + SmallVector Expected{"b"}; + EXPECT_EQ(Expected, DiffVec); +} + +} // end anonymous namespace