Skip to content

Commit ff997b1

Browse files
committed
Array<T>: add get(i)/set(i,v) methods for Java-style access and bool[] compatibility
1 parent b1c30d7 commit ff997b1

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/Processing.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,6 +2681,17 @@ class Array {
26812681
return data[(size_t)index];
26822682
}
26832683

2684+
// get/set methods for Java-style access and bool[] compatibility
2685+
T get(int index) const {
2686+
if (index < 0 || index >= (int)data.size())
2687+
throw std::out_of_range("Array index " + std::to_string(index) + " out of bounds");
2688+
return data[(size_t)index];
2689+
}
2690+
void set(int index, const T& val) {
2691+
if (index < 0 || index >= (int)data.size())
2692+
throw std::out_of_range("Array index " + std::to_string(index) + " out of bounds");
2693+
data[(size_t)index] = val;
2694+
}
26842695
auto begin() { return data.begin(); }
26852696
auto end() { return data.end(); }
26862697
auto begin() const { return data.begin(); }

0 commit comments

Comments
 (0)