File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,6 +27,49 @@ namespace gl {
2727// / an offsets array (*offsets*) to track segment boundaries. This design provides excellent cache locality
2828// / and efficient iteration over individual segments.
2929// /
30+ // / ### Example Usage
31+ // / ```cpp
32+ // / #include <gl/types/flat_jagged_vector.hpp>
33+ // /
34+ // / #include <iostream>
35+ // /
36+ // / int main() {
37+ // / gl::flat_jagged_vector<int> vec = { // (1)!
38+ // / {1, 2, 3},
39+ // / {4, 5},
40+ // / {6, 7, 8, 9}
41+ // / };
42+ // /
43+ // / vec.push_back({10, 11}); // (2)!
44+ // / vec.push_back(1uz, 99); // (3)!
45+ // /
46+ // / for (const auto [i, segment] : vec) { // (4)!
47+ // / std::cout << "Segment " << i << ": ";
48+ // / for (int value : segment)
49+ // / std::cout << value << " ";
50+ // / std::cout << '\n';
51+ // / }
52+ // /
53+ // / return 0;
54+ // / }
55+ // / ```
56+ // /
57+ // / 1\. Initialize the `flat_jagged_vector` with an initializer list of segments, where each segment can have a different length.
58+ // /
59+ // / 2\. Append a new segment to the end of the container using `push_back()`.
60+ // /
61+ // / 3\. Append an element to the second segment (index 1).
62+ // /
63+ // / 4\. Iterate over the segments and their elements using the `operator[]` to access each segment as a range.
64+ // /
65+ // / **Output:**
66+ // / ```text
67+ // / Segment 0: 1 2 3
68+ // / Segment 1: 4 5 99
69+ // / Segment 2: 6 7 8 9
70+ // / Segment 3: 10 11
71+ // / ```
72+ // /
3073// / > [!NOTE] Container behaviour
3174// / >
3275// / > Behavior is similar to `std::vector<std::vector<T>>` but with flattened memory layout.
Original file line number Diff line number Diff line change @@ -28,6 +28,49 @@ namespace gl {
2828// / using row-major ordering. Row accesses are contiguous in memory, while column accesses are resolved mathematically
2929// / via strided views. Both provide $O(1)$ random access and native compatibility with C++20/23 ranges.
3030// /
31+ // / ### Example Usage
32+ // / ```cpp
33+ // / #include <gl/types/flat_matrix.hpp>
34+ // /
35+ // / #include <iostream>
36+ // /
37+ // / int main() {
38+ // / gl::flat_matrix<int> mat = { // (1)!
39+ // / {1, 2, 3},
40+ // / {4, 5, 6}
41+ // / };
42+ // /
43+ // / mat[1uz, 2uz] = 99; // (2)!
44+ // / mat.push_row({7, 8, 9}); // (3)!
45+ // / mat.push_col({10, 11, 12}); // (4)!
46+ // /
47+ // / for (const auto row : mat) { // (5)!
48+ // / for (const auto element : row)
49+ // / std::cout << element << "\t";
50+ // / std::cout << '\n';
51+ // / }
52+ // /
53+ // / return 0;
54+ // / }
55+ // / ```
56+ // /
57+ // / 1\. Initialize the `flat_matrix` with an initializer list of rows, where each row is a list of elements.
58+ // /
59+ // / 2\. Modify an element using 2D coordinates (row 1, col 2).
60+ // /
61+ // / 3\. Append a new row to the bottom.
62+ // /
63+ // / 4\. Append a new column to the right.
64+ // /
65+ // / 5\. Iterate over the matrix.
66+ // /
67+ // / **Output:**
68+ // / ```text
69+ // / 1 2 3 10
70+ // / 4 5 99 11
71+ // / 7 8 9 12
72+ // / ```
73+ // /
3174// / > [!IMPORTANT] Iterator invalidation policy
3275// / >
3376// / > Iterator invalidation follows `std::vector` semantics: modifying the dimensions or structural
You can’t perform that action at this time.
0 commit comments