Changeset 67748 in vbox
- Timestamp:
- Jul 3, 2017 9:29:29 AM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 116637
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/list.h
r62474 r67748 135 135 static inline void set(T2 *p, size_t i, const T1 &v) { p[i] = v; } 136 136 static inline T1 & at(T2 *p, size_t i) { return p[i]; } 137 static inline const T1 &atConst(T2 const *p, size_t i) { return p[i]; } 137 138 static inline size_t find(T2 *p, const T1 &v, size_t cElements) 138 139 { … … 161 162 static inline void set(T1 **p, size_t i, const T1 &v) { p[i] = new T1(v); } 162 163 static inline T1 & at(T1 **p, size_t i) { return *p[i]; } 164 static inline const T1 &atConst(T1 * const *p, size_t i) { return *p[i]; } 163 165 static inline size_t find(T1 **p, const T1 &v, size_t cElements) 164 166 { … … 407 409 408 410 /** 411 * Append a default item to the list. 412 * 413 * @return a mutable reference to the item 414 * @throws std::bad_alloc 415 */ 416 GET_RTYPE append() 417 { 418 m_guard.enterWrite(); 419 if (m_cElements == m_cCapacity) 420 growArray(m_cCapacity + kDefaultCapacity); 421 RTCListHelper<T, ITYPE>::set(m_pArray, m_cElements, T()); 422 GET_RTYPE rRet = RTCListHelper<T, ITYPE>::at(m_pArray, m_cElements); 423 ++m_cElements; 424 m_guard.leaveWrite(); 425 426 return rRet; 427 } 428 429 /** 409 430 * Append an item to the list. 410 431 * … … 628 649 629 650 /** 630 * Return the item at position @a i or default value if out of range. 651 * Return the item at position @a i as immutable reference. 652 * 653 * @param i The position of the item to return. This better not be out of 654 * bounds, however should it be the last element of the array 655 * will be return and strict builds will raise an assertion. 656 * Should the array be empty, a crash is very likely. 657 * @return The item at position @a i. 658 */ 659 const T &operator[](size_t i) const 660 { 661 m_guard.enterRead(); 662 AssertMsgStmt(i < m_cElements, ("i=%zu m_cElements=%zu\n", i, m_cElements), i = m_cElements - 1); 663 const T &rRet = RTCListHelper<T, ITYPE>::atConst(m_pArray, i); 664 m_guard.leaveRead(); 665 return rRet; 666 } 667 668 /** 669 * Return a copy of the item at position @a i or default value if out of range. 631 670 * 632 671 * @param i The position of the item to return. 633 * @return The item at position @a i or default value.672 * @return Copy of the item at position @a i or default value. 634 673 */ 635 674 T value(size_t i) const … … 647 686 648 687 /** 649 * Return the item at position @a i, or @a defaultVal if out of range.688 * Return a copy of the item at position @a i, or @a defaultVal if out of range. 650 689 * 651 690 * @param i The position of the item to return. 652 691 * @param defaultVal The value to return in case @a i is invalid. 653 * @return The item at position @a i or @a defaultVal.692 * @return Copy of the item at position @a i or @a defaultVal. 654 693 */ 655 694 T value(size_t i, const T &defaultVal) const
Note:
See TracChangeset
for help on using the changeset viewer.