From 4938d5cc76b0ba1037be1b9b589dd2093c62509f Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Thu, 21 Sep 2017 16:30:22 -0500 Subject: COMMON: Add standard data method to Common::Array This matches the C++11 std::vector method of the same name, and replaces usage of taking the address of the first element of an array by &array[0] or &array.front() or &*array.begin(). The data method is better than these usages because it can be used even when the array is empty. --- test/common/array.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test') diff --git a/test/common/array.h b/test/common/array.h index 7506162821..45be99371f 100644 --- a/test/common/array.h +++ b/test/common/array.h @@ -353,6 +353,15 @@ class ArrayTestSuite : public CxxTest::TestSuite TS_ASSERT_EQUALS(array2.size(), (unsigned int)3); } + void test_data() { + Common::Array array; + TS_ASSERT(array.data() == nullptr); + array.resize(2); + TS_ASSERT(array.data() != nullptr); + TS_ASSERT_EQUALS(array.data(), &array.front()); + TS_ASSERT_EQUALS(array.data() + array.size() - 1, &array.back()); + } + void test_front_back_push_pop() { Common::Array container; -- cgit v1.2.3