From ad59fac3801e7324b03b9be1ba9a26a9b9f8e41a Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 15 Jan 2026 15:37:42 -0500 Subject: [PATCH] xo-object2: + DArray::array() n-ary factory method --- xo-object2/include/xo/object2/DArray.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/xo-object2/include/xo/object2/DArray.hpp b/xo-object2/include/xo/object2/DArray.hpp index 33896473..afa4769a 100644 --- a/xo-object2/include/xo/object2/DArray.hpp +++ b/xo-object2/include/xo/object2/DArray.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace xo { @@ -57,6 +58,12 @@ namespace xo { static DArray * empty(obj mm, size_type cap); + /** create array containing elements @p args, using memory from @p mm. + * Nullptr if space exhausted. + **/ + template + requires (std::same_as> && ...) + static DArray * array(obj mm, Args... args); ///@} /** @defgroup darray-access acecss methods **/ @@ -125,6 +132,18 @@ namespace xo { ///@} }; + template + requires (std::same_as> && ...) + DArray * + DArray::array(obj mm, Args... args) + { + DArray * result = empty(mm, sizeof...(args)); + if (result) { + (result->push_back(args), ...); + } + return result; + } + } /*namespace scm*/ } /*namespace xo*/