[PATCH] D24689: [ADT] Add missing const_iterator DenseSet::find() const
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 19 11:02:04 PDT 2016
vitalybuka updated this revision to Diff 71850.
vitalybuka added a comment.
Unittest
https://reviews.llvm.org/D24689
Files:
include/llvm/ADT/DenseSet.h
unittests/ADT/DenseSetTest.cpp
Index: unittests/ADT/DenseSetTest.cpp
===================================================================
--- unittests/ADT/DenseSetTest.cpp
+++ unittests/ADT/DenseSetTest.cpp
@@ -7,19 +7,16 @@
//
//===----------------------------------------------------------------------===//
+#include <type_traits>
#include "gtest/gtest.h"
#include "llvm/ADT/DenseSet.h"
using namespace llvm;
namespace {
-// Test fixture
-class DenseSetTest : public testing::Test {
-};
-
// Test hashing with a set of only two entries.
-TEST_F(DenseSetTest, DoubleEntrySetTest) {
+TEST(DenseSetTest, DoubleEntrySetTest) {
llvm::DenseSet<unsigned> set(2);
set.insert(0);
set.insert(1);
@@ -42,12 +39,30 @@
}
};
-TEST(DenseSetCustomTest, FindAsTest) {
- DenseSet<unsigned, TestDenseSetInfo> set;
- set.insert(0);
- set.insert(1);
- set.insert(2);
+// Test fixture
+template <typename T>
+class DenseSetTest : public testing::Test {
+ protected:
+ T Set = GetTestSet();
+
+ private:
+ static T GetTestSet() {
+ typename std::remove_const<T>::type Set;
+ Set.insert(0);
+ Set.insert(1);
+ Set.insert(2);
+ return Set;
+ }
+};
+
+// Register these types for testing.
+typedef ::testing::Types<DenseSet<unsigned, TestDenseSetInfo>,
+ const DenseSet<unsigned, TestDenseSetInfo>
+ > DenseSetTestTypes;
+TYPED_TEST_CASE(DenseSetTest, DenseSetTestTypes);
+TYPED_TEST(DenseSetTest, FindAsTest) {
+ auto& set = this->Set;
// Size tests
EXPECT_EQ(3u, set.size());
Index: include/llvm/ADT/DenseSet.h
===================================================================
--- include/llvm/ADT/DenseSet.h
+++ include/llvm/ADT/DenseSet.h
@@ -135,6 +135,7 @@
const_iterator end() const { return ConstIterator(TheMap.end()); }
iterator find(const ValueT &V) { return Iterator(TheMap.find(V)); }
+ const_iterator find(const ValueT &V) const { return ConstIterator(TheMap.find(V)); }
/// Alternative version of find() which allows a different, and possibly less
/// expensive, key type.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24689.71850.patch
Type: text/x-patch
Size: 2063 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160919/096c78dd/attachment.bin>
More information about the llvm-commits
mailing list