[PATCH] D49402: [STLExtras] Add size() for arrays
Paul Semel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 16 14:10:29 PDT 2018
paulsemel created this revision.
paulsemel added reviewers: echristo, jhenderson.
Herald added a subscriber: dexonsmith.
Repository:
rL LLVM
https://reviews.llvm.org/D49402
Files:
include/llvm/ADT/STLExtras.h
unittests/ADT/STLExtrasTest.cpp
Index: unittests/ADT/STLExtrasTest.cpp
===================================================================
--- unittests/ADT/STLExtrasTest.cpp
+++ unittests/ADT/STLExtrasTest.cpp
@@ -364,4 +364,10 @@
EXPECT_EQ(5, count);
}
+TEST(STLExtrasTest, ArraySize) {
+ int a1[] = {1, 2, 3, 4};
+
+ EXPECT_EQ(size(a1), 4);
+}
+
} // namespace
Index: include/llvm/ADT/STLExtras.h
===================================================================
--- include/llvm/ADT/STLExtras.h
+++ include/llvm/ADT/STLExtras.h
@@ -1038,6 +1038,11 @@
return std::distance(Range.begin(), Range.end());
}
+template <class T, std::size_t N>
+constexpr size_t size(const T (&array)[N]) noexcept {
+ return N;
+}
+
//===----------------------------------------------------------------------===//
// Extra additions to <memory>
//===----------------------------------------------------------------------===//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49402.155761.patch
Type: text/x-patch
Size: 900 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180716/06d09989/attachment.bin>
More information about the llvm-commits
mailing list