Skip to content

Commit 2076520

Browse files
Address a comment.
1 parent 2acfa1a commit 2076520

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

llvm/unittests/ADT/StringMapTest.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,4 +693,34 @@ TEST(StringMapCustomTest, StringMapEntrySize) {
693693
EXPECT_EQ(LargeValue, Key.size());
694694
}
695695

696+
TEST(StringMapCustomTest, NonConstIterator) {
697+
StringMap<int> Map;
698+
Map["key"] = 1;
699+
700+
// Check that Map.begin() returns a non-const iterator.
701+
static_assert(
702+
std::is_same_v<decltype(Map.begin()), StringMap<int>::iterator>);
703+
704+
// Check that we can construct a const_iterator from an iterator.
705+
static_assert(std::is_constructible_v<StringMap<int>::const_iterator,
706+
StringMap<int>::iterator>);
707+
708+
// Double check that we can actually construct a const_iterator.
709+
StringMap<int>::const_iterator const_it = Map.begin();
710+
(void)const_it;
711+
}
712+
713+
TEST(StringMapCustomTest, ConstIterator) {
714+
StringMap<int> Map;
715+
const StringMap<int> &ConstMap = Map;
716+
717+
// Check that ConstMap.begin() returns a const_iterator.
718+
static_assert(std::is_same_v<decltype(ConstMap.begin()),
719+
StringMap<int>::const_iterator>);
720+
721+
// Check that we cannot construct an iterator from a const_iterator.
722+
static_assert(!std::is_constructible_v<StringMap<int>::iterator,
723+
StringMap<int>::const_iterator>);
724+
}
725+
696726
} // end anonymous namespace

0 commit comments

Comments
 (0)