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

Method push_back

Examples/NoModules/Chapter 21/Ex21_03/Array.h:124–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122// push_back() overload for lvalue references
123template <typename T> requires std::default_initializable<T> && std::destructible<T>
124void Array<T>::push_back(T element) requires std::movable<T>
125{
126 Array<T> newArray{m_size + 1}; // Allocate a larger Array<>
127 for (size_t i{}; i < m_size; ++i) // Move all existing elements...
128 newArray[i] = std::move(m_elements[i]);
129
130 newArray[m_size] = std::move(element); // Move the new one (could itself be a copy already)...
131
132 swap(newArray); // ... and swap!
133}
134
135#endif

Callers 8

mainFunction · 0.45
mainFunction · 0.45
fillVector_1toNFunction · 0.45
fillVector_1toNFunction · 0.45
extractWordsFunction · 0.45
fillVector_1toNFunction · 0.45
fillVector_1toNFunction · 0.45
mainFunction · 0.45

Calls 1

swapFunction · 0.70

Tested by

no test coverage detected