From 470146ea1486968bf837fd7eed3f57f999ce5965 Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Fri, 30 Jan 2026 08:21:28 -0700 Subject: [PATCH] :sparkles: Add `make_array` Problem: - We sometimes need to make arrays from various things, e.g. templates or factory functions. Solution: - Add `make_array`. Note: - Although `std::experimental::make_array` was largely obviated by CTAD, similar behaviour is included here for consistency. viz. `stdx::make_array(1,2,3)`. --- CMakeLists.txt | 1 + docs/intro.adoc | 1 + include/stdx/array.hpp | 42 +++++++++++++++++++++++++++++++++++++++ test/CMakeLists.txt | 1 + test/array.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 include/stdx/array.hpp create mode 100644 test/array.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b5dba32..0d7df84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ target_sources( include FILES include/stdx/algorithm.hpp + include/stdx/array.hpp include/stdx/atomic.hpp include/stdx/atomic_bitset.hpp include/stdx/bit.hpp diff --git a/docs/intro.adoc b/docs/intro.adoc index 90f22ae..5a446cc 100644 --- a/docs/intro.adoc +++ b/docs/intro.adoc @@ -67,6 +67,7 @@ into headers whose names match the standard. The following headers are available: * https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/algorithm.hpp[`algorithm.hpp`] +* https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/array.hpp[`array.hpp`] * https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/atomic.hpp[`atomic.hpp`] * https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/atomic_bitset.hpp[`atomic_bitset.hpp`] * https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/bit.hpp[`bit.hpp`] diff --git a/include/stdx/array.hpp b/include/stdx/array.hpp new file mode 100644 index 0000000..b0952de --- /dev/null +++ b/include/stdx/array.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include + +namespace stdx { +inline namespace v1 { + +template +constexpr auto make_array(Ts &&...ts) { + if constexpr (not std::is_void_v) { + return std::array{std::forward(ts)...}; + } else { + using A = std::common_type_t; + return std::array{std::forward(ts)...}; + } +} + +template