mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[util] Add moving append() call to vector
Add a version of `append()` that takes an rvalue reference.
This commit is contained in:
@@ -110,13 +110,23 @@ public:
|
|||||||
/// Add an item onto the array by copying it.
|
/// Add an item onto the array by copying it.
|
||||||
/// \arg item The item to add
|
/// \arg item The item to add
|
||||||
/// \returns A reference to the added item
|
/// \returns A reference to the added item
|
||||||
T & append(const T& item)
|
T & append(const T &item)
|
||||||
{
|
{
|
||||||
ensure_capacity(m_size + 1);
|
ensure_capacity(m_size + 1);
|
||||||
m_elements[m_size] = item;
|
m_elements[m_size] = item;
|
||||||
return m_elements[m_size++];
|
return m_elements[m_size++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add an item onto the array by copying it.
|
||||||
|
/// \arg item The item to add
|
||||||
|
/// \returns A reference to the added item
|
||||||
|
T & append(T &&item)
|
||||||
|
{
|
||||||
|
ensure_capacity(m_size + 1);
|
||||||
|
m_elements[m_size] = std::move(item);
|
||||||
|
return m_elements[m_size++];
|
||||||
|
}
|
||||||
|
|
||||||
/// Construct an item in place onto the end of the array.
|
/// Construct an item in place onto the end of the array.
|
||||||
/// \returns A reference to the added item
|
/// \returns A reference to the added item
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
|
|||||||
Reference in New Issue
Block a user