From 54a229c4364a0d15fff7efae8c97a39431122e54 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Fri, 3 Mar 2023 20:04:38 -0400 Subject: TArray: Add `at()`, and `at_as()` --- context.h | 11 ++++++++++- include/pso/TArray.h | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/context.h b/context.h index a52d296..3ef2a01 100644 --- a/context.h +++ b/context.h @@ -192,8 +192,12 @@ public: return n * sizeof(T); }; - T &operator[](size_t i) { + T &at(size_t i) { return m_data[i]; + } + + T &operator[](size_t i) { + return at(i); }; T *start() { @@ -209,6 +213,11 @@ public: return reinterpret_cast(m_data); }; + template + T2 &at_as(size_t i) { + return reinterpret_cast(at(i)); + }; + template size_t size_as() { return byte_size() / sizeof(T2); diff --git a/include/pso/TArray.h b/include/pso/TArray.h index 8dd736b..cefe6c8 100644 --- a/include/pso/TArray.h +++ b/include/pso/TArray.h @@ -23,8 +23,12 @@ public: return n * sizeof(T); }; - T &operator[](size_t i) { + T &at(size_t i) { return m_data[i]; + } + + T &operator[](size_t i) { + return at(i); }; T *start() { @@ -40,6 +44,11 @@ public: return reinterpret_cast(m_data); }; + template + T2 &at_as(size_t i) { + return reinterpret_cast(at(i)); + }; + template size_t size_as() { return byte_size() / sizeof(T2); -- cgit v1.2.3-13-gbd6f