Skip to content

Commit ab0a82b

Browse files
add an example in the comment for pairs() method of vtr::vector
1 parent 2266adb commit ab0a82b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

libs/libvtrutil/src/vtr_vector.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ class vector : private std::vector<V, Allocator> {
160160
*
161161
* This function allows for easy enumeration, yielding a tuple of (index, element)
162162
* pairs in each iteration. It is similar in functionality to Python's `enumerate()`.
163+
* This function can be used in range-based with structured binding to iterate over
164+
* indices and values at the same time.
165+
*
166+
* vtr::vector<IdType, ValueType> vec;
167+
* for (const auto& [idx, value] : vec) {
168+
* ...
169+
* }
170+
* It should be noted that value is returned by reference even if "&"
171+
* does not appear after auto keyword. However, it is recommended to use "&"
172+
* explicitly to avoid any confusion about value's scope.
163173
*
164174
* @ return An iterable wrapper that can be used in a range-based for loop to obtain
165175
* (index, element) pairs.

0 commit comments

Comments
 (0)