From a7beb0df189402b348eed6fd621c56e8aea3f1e8 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Mon, 10 Jul 2023 01:45:31 -0700 Subject: [PATCH] [util] Add moving append() call to vector Add a version of `append()` that takes an rvalue reference. --- src/libraries/util/util/vector.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libraries/util/util/vector.h b/src/libraries/util/util/vector.h index c177c17..9c5f544 100644 --- a/src/libraries/util/util/vector.h +++ b/src/libraries/util/util/vector.h @@ -110,13 +110,23 @@ public: /// Add an item onto the array by copying it. /// \arg item The item to add /// \returns A reference to the added item - T & append(const T& item) + T & append(const T &item) { ensure_capacity(m_size + 1); m_elements[m_size] = item; 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. /// \returns A reference to the added item template