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. --- common/array.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/array.h b/common/array.h index ed54cd5c87..bb7e03c4f7 100644 --- a/common/array.h +++ b/common/array.h @@ -87,10 +87,10 @@ public: * Construct an array by copying data from a regular array. */ template - Array(const T2 *data, size_type n) { + Array(const T2 *array, size_type n) { _size = n; allocCapacity(n); - uninitialized_copy(data, data + _size, _storage); + uninitialized_copy(array, array + _size, _storage); } ~Array() { @@ -123,6 +123,16 @@ public: _storage[_size].~T(); } + /** Returns a pointer to the underlying memory serving as element storage. */ + const T *data() const { + return _storage; + } + + /** Returns a pointer to the underlying memory serving as element storage. */ + T *data() { + return _storage; + } + /** Returns a reference to the first element of the array. */ T &front() { assert(_size > 0); -- cgit v1.2.3