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

Method push_back

Exercises/NoModules/Chapter 21/Soln21_06/Array.h:150–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148// push_back() overload for lvalue references
149template <typename T>
150void Array<T>::push_back(T element) // Pass by value (copy of lvalue, or moved rvalue!)
151{
152 Array<T> newArray{m_size + 1}; // Allocate a larger Array<>
153 for (size_t i {}; i < m_size; ++i) // Move existing elements (copy if not noexcept)...
154 newArray[i] = move_assign_if_noexcept(m_elements[i]);
155
156 newArray[m_size] = move_assign_if_noexcept(element); // Move (or copy) the new one...
157
158 swap(newArray); // ... and swap!
159}
160
161#endif

Callers 15

mainFunction · 0.45
fillVector_1toNFunction · 0.45
addBoxMethod · 0.45
extractWordsFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 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