summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/IteratorTest.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2018-05-10 23:01:54 +0000
committerVedant Kumar <vsk@apple.com>2018-05-10 23:01:54 +0000
commite0b5f86b3083747beaf5d7639333af0109c9e6ef (patch)
treef76486dec408880ad53ce624064ccb10f2b9faea /llvm/unittests/ADT/IteratorTest.cpp
parent4855c5f717fde5207033e97989b20b273298a57b (diff)
downloadbcm5719-llvm-e0b5f86b3083747beaf5d7639333af0109c9e6ef.tar.gz
bcm5719-llvm-e0b5f86b3083747beaf5d7639333af0109c9e6ef.zip
[STLExtras] Add distance() for ranges, pred_size(), and succ_size()
This commit adds a wrapper for std::distance() which works with ranges. As it would be a common case to write `distance(predecessors(BB))`, this also introduces `pred_size()` and `succ_size()` helpers to make that easier to write. Differential Revision: https://reviews.llvm.org/D46668 llvm-svn: 332057
Diffstat (limited to 'llvm/unittests/ADT/IteratorTest.cpp')
-rw-r--r--llvm/unittests/ADT/IteratorTest.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/IteratorTest.cpp b/llvm/unittests/ADT/IteratorTest.cpp
index 5b9320e80a3..69033bbf593 100644
--- a/llvm/unittests/ADT/IteratorTest.cpp
+++ b/llvm/unittests/ADT/IteratorTest.cpp
@@ -365,4 +365,12 @@ TEST(ZipIteratorTest, Reverse) {
EXPECT_TRUE(all_of(ascending, [](unsigned n) { return (n & 0x01) == 0; }));
}
+TEST(RangeTest, Distance) {
+ std::vector<int> v1;
+ std::vector<int> v2{1, 2, 3};
+
+ EXPECT_EQ(std::distance(v1.begin(), v1.end()), distance(v1));
+ EXPECT_EQ(std::distance(v2.begin(), v2.end()), distance(v2));
+}
+
} // anonymous namespace
OpenPOWER on IntegriCloud