summaryrefslogtreecommitdiff
path: root/FL/Fl_Int_Vector.H
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2022-11-07 10:30:20 -0800
committerGreg Ercolano <erco@seriss.com>2022-11-07 10:33:35 -0800
commit6f24175e64cd10e5cbabc01a1967b37c117a4a78 (patch)
treeeecd5df17798f7c8cdd458663a448003374fbe34 /FL/Fl_Int_Vector.H
parent2a43a12b7b870c6fd775f417c1c2e85222e47238 (diff)
Added assignment by index example, doc clarifications.
Diffstat (limited to 'FL/Fl_Int_Vector.H')
-rw-r--r--FL/Fl_Int_Vector.H8
1 files changed, 7 insertions, 1 deletions
diff --git a/FL/Fl_Int_Vector.H b/FL/Fl_Int_Vector.H
index 9a2cd45f9..af1b77423 100644
--- a/FL/Fl_Int_Vector.H
+++ b/FL/Fl_Int_Vector.H
@@ -42,6 +42,9 @@
v.push_back(22); // add second element
v.push_back(33); // add third element
+ // Assignment by subscript
+ v[1] = 222; // changes 2nd element from 22 to 222
+
// Loop through printing the values
for ( unsigned int i=0; i<v.size(); i++ )
printf("%d ", v[i]); // access the elements
@@ -56,7 +59,6 @@
- Add other std::vector methods like erase(), etc.
- Make memory blocking size flexible, and add related methods like capacity(), reserve(), shrink_to_fit(), etc.
- Add non-std methods that are nevertheless needed, e.g. insert(index,val), delete(index), delete(start, end), swap(a_idx,b_idx)
- - Add a way to change the elements by index, e.g. v[2] = 222; (which is currently NOT supported)
*/
class FL_EXPORT Fl_Int_Vector {
int *arr_;
@@ -107,6 +109,10 @@ public:
/**
Access the specified integer element at index position \p x as a reference.
+
+ This allows assignment by index through the returned reference, e.g. arr[1] = 222;
+ where arr[1] ends up being a reference to ptr[1], and then 222 is assigned to that ref.
+
\warning No range checking is done on \p x, which must be less than size().
*/
int &operator[](int x) {