Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Unified Diff: webrtc/base/array_view_unittest.cc

Issue 2312473002: Restrict the 1-argument ArrayView constructor to types with .size() and .data() (Closed)
Patch Set: comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/array_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/array_view_unittest.cc
diff --git a/webrtc/base/array_view_unittest.cc b/webrtc/base/array_view_unittest.cc
index 8bb1bcc4c6ce259a8d1c61c2d3618bc2594f35e5..9d5e1afc60be81ad4017fb6740f2021b232000ce 100644
--- a/webrtc/base/array_view_unittest.cc
+++ b/webrtc/base/array_view_unittest.cc
@@ -20,8 +20,45 @@
namespace rtc {
namespace {
+
+namespace test_has_data_and_size {
+
+template <typename C, typename T>
+using DS = internal::HasDataAndSize<C, T>;
+
+template <typename DR, typename SR>
+struct Test1 {
+ DR data();
+ SR size();
+};
+static_assert(DS<Test1<int*, int>, int>::value, "");
+static_assert(DS<Test1<int*, int>, const int>::value, "");
+static_assert(DS<Test1<const int*, int>, const int>::value, "");
+static_assert(!DS<Test1<const int*, int>, int>::value, ""); // Wrong const.
+static_assert(!DS<Test1<char*, size_t>, int>::value, ""); // Wrong ptr type.
+
+struct Test2 {
+ int* data;
+ size_t size;
+};
+static_assert(!DS<Test2, int>::value, ""); // Because they aren't methods.
+
+struct Test3 {
+ int* data();
+};
+static_assert(!DS<Test3, int>::value, ""); // Because .size() is missing.
+
+class Test4 {
+ int* data();
+ size_t size();
+};
+static_assert(!DS<Test4, int>::value, ""); // Because methods are private.
+
+} // namespace test_has_data_and_size
+
template <typename T>
void Call(ArrayView<T>) {}
+
} // namespace
TEST(ArrayViewTest, TestConstructFromPtrAndArray) {
« no previous file with comments | « webrtc/base/array_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698