aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/array.h17
-rw-r--r--common/memory.h4
2 files changed, 19 insertions, 2 deletions
diff --git a/common/array.h b/common/array.h
index 04ec9f9ccb..ed54cd5c87 100644
--- a/common/array.h
+++ b/common/array.h
@@ -59,6 +59,23 @@ protected:
public:
Array() : _capacity(0), _size(0), _storage(0) {}
+ /**
+ * Constructs an array with `count` default-inserted instances of T. No
+ * copies are made.
+ */
+ explicit Array(size_type count) : _size(0) {
+ allocCapacity(count);
+ resize(count);
+ }
+
+ /**
+ * Constructs an array with `count` copies of elements with value `value`.
+ */
+ Array(size_type count, const T &value) : _size(count) {
+ allocCapacity(count);
+ uninitialized_fill_n(_storage, count, value);
+ }
+
Array(const Array<T> &array) : _capacity(array._size), _size(array._size), _storage(0) {
if (array._storage) {
allocCapacity(_size);
diff --git a/common/memory.h b/common/memory.h
index c32af42ba5..91a320080b 100644
--- a/common/memory.h
+++ b/common/memory.h
@@ -55,11 +55,11 @@ void uninitialized_fill(Type *first, Type *last, const Value &x) {
* It requires the range [dst, dst + n) to be valid and
* uninitialized.
*/
-/*template<class Type, class Value>
+template<class Type, class Value>
void uninitialized_fill_n(Type *dst, size_t n, const Value &x) {
while (n--)
new ((void *)dst++) Type(x);
-}*/
+}
} // End of namespace Common