MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / push_back

Method push_back

Examples/NoModules/Chapter 18/Ex18_06/Array.h:137–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135// push_back() overload for lvalue references
136template <typename T>
137void Array<T>::push_back(T element) // Pass by value (copy of lvalue, or moved rvalue!)
138{
139 Array<T> newArray{m_size + 1}; // Allocate a larger Array<>
140 for (size_t i {}; i < m_size; ++i) // Move existing elements (copy if not noexcept)...
141 newArray[i] = move_assign_if_noexcept(m_elements[i]);
142
143 newArray[m_size] = move_assign_if_noexcept(element); // Move (or copy) the new one...
144
145 swap(newArray); // ... and swap!
146}
147
148#endif

Callers 15

mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
computeValuesFunction · 0.45
find_wordsFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 2

move_assign_if_noexceptFunction · 0.85
swapFunction · 0.70

Tested by

no test coverage detected