| 83 | // then the original Array<> remains untouched. |
| 84 | template <typename T> |
| 85 | void Array<T>::push_back(const T& newElement) |
| 86 | { |
| 87 | Array<T> copy{ m_size + 1 }; // Copy... |
| 88 | for (size_t i {}; i < m_size; ++i) |
| 89 | copy[i] = m_elements[i]; |
| 90 | |
| 91 | copy[m_size] = newElement; // ... modify ... |
| 92 | |
| 93 | swap(copy); // ... and swap! (noexcept) |
| 94 | } |
| 95 | |
| 96 | // Swap member function template |
| 97 | template <typename T> |
no test coverage detected