Vector: Simplify functions that take both T&& and const T&.

We can implement foo(const T&) by invoking foo(T&&) with a temporary T.
This commit is contained in:
Andreas Kling 2019-07-04 13:54:37 +02:00
parent 1791ebaacd
commit 57da8792fd

View file

@ -240,16 +240,7 @@ public:
void insert(int index, const T& value)
{
ASSERT(index <= size());
if (index == size())
return append(value);
grow_capacity(size() + 1);
++m_size;
for (int i = size() - 1; i > index; --i) {
new (slot(i)) T(move(at(i - 1)));
at(i - 1).~T();
}
new (slot(index)) T(value);
insert(index, T(value));
}
Vector& operator=(const Vector& other)
@ -275,6 +266,13 @@ public:
unchecked_append(move(v));
}
void append(const Vector& other)
{
grow_capacity(size() + other.size());
for (auto& value : other)
unchecked_append(value);
}
template<typename Callback>
void remove_first_matching(Callback callback)
{
@ -295,8 +293,7 @@ public:
void unchecked_append(const T& value)
{
new (slot(m_size)) T(value);
++m_size;
unchecked_append(T(value));
}
void append(T&& value)
@ -308,9 +305,7 @@ public:
void append(const T& value)
{
grow_capacity(size() + 1);
new (slot(m_size)) T(value);
++m_size;
append(T(value));
}
void prepend(const T& value)