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*/