summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-03-03 20:04:38 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2023-03-03 20:04:38 -0400
commit54a229c4364a0d15fff7efae8c97a39431122e54 (patch)
tree04a56c3b0549afd18d2a9cc05342f9f961a5a700
parent310be43184c5af1cfe791bb955fd9e70ca861e0f (diff)
TArray: Add `at()`, and `at_as()`
-rw-r--r--context.h11
-rw-r--r--include/pso/TArray.h11
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() {
@@ -210,6 +214,11 @@ public:
};
template<typename T2>
+ T2 &at_as(size_t i) {
+ return reinterpret_cast<T2>(at(i));
+ };
+
+ template<typename T2>
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() {
@@ -41,6 +45,11 @@ public:
};
template<typename T2>
+ T2 &at_as(size_t i) {
+ return reinterpret_cast<T2>(at(i));
+ };
+
+ template<typename T2>
size_t size_as() {
return byte_size() / sizeof(T2);
};