summaryrefslogtreecommitdiff
path: root/src/common/dumb_ptr.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/dumb_ptr.hpp')
-rw-r--r--src/common/dumb_ptr.hpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/common/dumb_ptr.hpp b/src/common/dumb_ptr.hpp
index d0b35f2..91293c6 100644
--- a/src/common/dumb_ptr.hpp
+++ b/src/common/dumb_ptr.hpp
@@ -21,6 +21,8 @@
#include "sanity.hpp"
+#include <algorithm>
+
// unmanaged new/delete-able pointer
// should be replaced by std::unique_ptr<T>
template<class T>
@@ -64,11 +66,11 @@ public:
}
explicit
- operator bool()
+ operator bool() const
{
return impl;
}
- bool operator !()
+ bool operator !() const
{
return !impl;
}
@@ -95,12 +97,12 @@ public:
}
void new_(size_t z)
{
- impl = new T[z];
+ impl = new T[z]();
}
static
dumb_ptr<T[]> make(size_t z)
{
- return dumb_ptr<T[]>(new T[z], z);
+ return dumb_ptr<T[]>(new T[z](), z);
}
void forget()
{
@@ -108,17 +110,35 @@ public:
sz = 0;
}
+ size_t size() const
+ {
+ return sz;
+ }
+ void resize(size_t z)
+ {
+ if (z == sz)
+ return;
+ T *np = new T[z]();
+ // not exception-safe, but we don't have a dtor anyway
+ size_t i = std::min(z, sz);
+ while (i-->0)
+ np[i] = std::move(impl[i]);
+ delete[] impl;
+ impl = np;
+ sz = z;
+ }
+
T& operator[](size_t i) const
{
return impl[i];
}
explicit
- operator bool()
+ operator bool() const
{
return impl;
}
- bool operator !()
+ bool operator !() const
{
return !impl;
}