From c7ff46bd36714baa0b7745d711feb9ed72fee234 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 --- include/xo/object2/DArray.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/xo/object2/DArray.hpp b/include/xo/object2/DArray.hpp index 3389647..afa4769 100644 --- a/include/xo/object2/DArray.hpp +++ b/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*/