diff --git a/include/xo/object2/DArray.hpp b/include/xo/object2/DArray.hpp index 64d7f52..5f57133 100644 --- a/include/xo/object2/DArray.hpp +++ b/include/xo/object2/DArray.hpp @@ -76,6 +76,11 @@ namespace xo { static DArray * _empty(obj mm, size_type cap); + /** ofp version of _empty(mm,cap) **/ + template + static obj empty(obj mm, + size_type cap); + /** create copy of @p src using memory from @p mm * with capacity for @p new_cap elements **/ @@ -198,6 +203,15 @@ namespace xo { ///@} }; + template + obj + DArray::empty(obj mm, DArray::size_type cap) + { + DArray * retval = _empty(mm, cap); + + return obj(retval); + } + template requires (std::convertible_to> && ...) DArray * diff --git a/src/object2/DArray.cpp b/src/object2/DArray.cpp index 2a5c590..050f757 100644 --- a/src/object2/DArray.cpp +++ b/src/object2/DArray.cpp @@ -84,7 +84,8 @@ namespace xo { } bool - DArray::push_back(obj mm, obj elt) noexcept + DArray::push_back(obj mm, + obj elt) noexcept { if (size_ >= capacity_) { return false; diff --git a/utest/DArray.test.cpp b/utest/DArray.test.cpp index 8935360..15da135 100644 --- a/utest/DArray.test.cpp +++ b/utest/DArray.test.cpp @@ -63,6 +63,9 @@ namespace xo { auto alloc = with_facet::mkobj(&arena); obj null_mm; + REQUIRE(!null_mm.data()); + REQUIRE(!null_mm._has_null_vptr()); // any + DArray * arr = DArray::_empty(alloc, 16); REQUIRE(arr != nullptr); REQUIRE(arr->capacity() == 16);