From c54ede3a9ef7eb25507f297b7af23c5b9ecc62d2 Mon Sep 17 00:00:00 2001 From: "Gregory Meyer (gregjm)" Date: Fri, 6 Jan 2023 06:46:34 -0800 Subject: [PATCH] Add const overloads for iterator functions. (#753) This commit adds `const`-correct overloads for `Array::{begin,end,rbegin,rend}`. These overloads are necessary for usage with [the GMock Container Matchers](http://google.github.io/googletest/reference/matchers.html#container-matchers), which cast the `Container` argument to a constant reference. --- include/cutlass/array.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/cutlass/array.h b/include/cutlass/array.h index 4f9c9185..61829091 100644 --- a/include/cutlass/array.h +++ b/include/cutlass/array.h @@ -454,6 +454,11 @@ public: return iterator(storage); } + CUTLASS_HOST_DEVICE + const_iterator begin() const { + return cbegin(); + } + CUTLASS_HOST_DEVICE const_iterator cbegin() const { return const_iterator(storage); @@ -464,6 +469,11 @@ public: return iterator(reinterpret_cast(storage + kStorageElements)); } + CUTLASS_HOST_DEVICE + const_iterator end() const { + return cend(); + } + CUTLASS_HOST_DEVICE const_iterator cend() const { return const_iterator(reinterpret_cast(storage + kStorageElements)); @@ -474,6 +484,11 @@ public: return reverse_iterator(reinterpret_cast(storage + kStorageElements)); } + CUTLASS_HOST_DEVICE + const_reverse_iterator rbegin() const { + return crbegin(); + } + CUTLASS_HOST_DEVICE const_reverse_iterator crbegin() const { return const_reverse_iterator(reinterpret_cast(storage + kStorageElements)); @@ -484,6 +499,11 @@ public: return reverse_iterator(reinterpret_cast(storage)); } + CUTLASS_HOST_DEVICE + const_reverse_iterator rend() const { + return crend(); + } + CUTLASS_HOST_DEVICE const_reverse_iterator crend() const { return const_reverse_iterator(reinterpret_cast(storage));