Skip to content
Snippets Groups Projects

consequential use of OwningVector

Merged Wuttke, Joachim requested to merge da into main
35 files
+ 110
103
Compare changes
  • Side-by-side
  • Inline
Files
35
+ 5
1
@@ -29,7 +29,8 @@
//! Equips vector<unique_ptr<T>> with copy constructor.
//! For use with polymorphic objects, or in pimpl idiom.
//! The objects pointed to must posses a clone() function.
//! If the copy constructor or the copy assignment operator is used,
//! then there must be a function T::clone().
template <class T>
class OwningVector {
@@ -49,6 +50,7 @@ public:
for (T* e : other)
m_v.emplace_back(e->clone());
}
OwningVector(OwningVector&& other) = default;
~OwningVector() { clear(); }
OwningVector& operator=(const OwningVector& other)
{
@@ -58,7 +60,9 @@ public:
std::swap(m_v, ret.m_v);
return *this;
}
OwningVector& operator=(OwningVector&& other) = default;
void reserve(size_t n) { m_v.reserve(n); }
void emplace_back(T* e) { m_v.emplace_back(e); }
void clear()
{
Loading