From 09c5a3236adf8ab2f4bdd7fabfc6e8b6d9395a75 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Wed, 20 Aug 2025 18:02:35 +0800 Subject: [PATCH 1/6] Update `get` syntax in `` functions reference --- docs/standard-library/array-functions.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/standard-library/array-functions.md b/docs/standard-library/array-functions.md index 60e9c8027c5..a1fadf65b8c 100644 --- a/docs/standard-library/array-functions.md +++ b/docs/standard-library/array-functions.md @@ -14,14 +14,17 @@ The `` header includes two non-member functions, `get` and `swap`, that o Returns a reference to the specified element of the array. ```cpp -template -constexpr T& get(array& arr) noexcept; +template +constexpr T& get(std::array& arr) noexcept; -template -constexpr const T& get(const array& arr) noexcept; +template +constexpr const T& get(const std::array& arr) noexcept; -template -constexpr T&& get(array&& arr) noexcept; +template +constexpr T&& get(std::array&& arr) noexcept; + +template +constexpr const T&& get(const std::array&& arr) noexcept; ``` ### Parameters @@ -29,10 +32,10 @@ constexpr T&& get(array&& arr) noexcept; *`Index`*\ The element offset. -*`T`*\ +*`Type`*\ The type of an element. -*`N`*\ +*`Size`*\ The number of elements in the array. *`arr`*\ From b0d9bb4624e248765637fdfcb37f922b81838992 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Wed, 20 Aug 2025 18:06:39 +0800 Subject: [PATCH 2/6] Update `swap` syntax in `` functions reference --- docs/standard-library/array-functions.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/standard-library/array-functions.md b/docs/standard-library/array-functions.md index a1fadf65b8c..4ffdc5b50b4 100644 --- a/docs/standard-library/array-functions.md +++ b/docs/standard-library/array-functions.md @@ -78,16 +78,16 @@ int main() A non-member template specialization of `std::swap` that swaps two **array** objects. ```cpp -template -void swap(array& left, array& right); +template +void swap(std::array& left, std::array& right); ``` ### Parameters -*`Ty`*\ +*`Type`*\ The type of an element. -*`N`*\ +*`Size`*\ The size of the array. *`left`*\ From e30b46e83f88f3f2fc1d38759a107a6df07d6a98 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Wed, 20 Aug 2025 18:11:17 +0800 Subject: [PATCH 3/6] Add "Template parameters" headings in `` functions reference --- docs/standard-library/array-functions.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/standard-library/array-functions.md b/docs/standard-library/array-functions.md index 4ffdc5b50b4..c73093fd750 100644 --- a/docs/standard-library/array-functions.md +++ b/docs/standard-library/array-functions.md @@ -27,7 +27,7 @@ template constexpr const T&& get(const std::array&& arr) noexcept; ``` -### Parameters +### Template parameters *`Index`*\ The element offset. @@ -38,6 +38,8 @@ The type of an element. *`Size`*\ The number of elements in the array. +### Parameters + *`arr`*\ The array to select from. @@ -82,7 +84,7 @@ template void swap(std::array& left, std::array& right); ``` -### Parameters +### Template parameters *`Type`*\ The type of an element. @@ -90,6 +92,8 @@ The type of an element. *`Size`*\ The size of the array. +### Parameters + *`left`*\ The first array to swap. From 183ce44376e3e3e245e936ba5fca94e085386cc0 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Wed, 20 Aug 2025 18:47:55 +0800 Subject: [PATCH 4/6] Document C++20 `std::to_array` function --- docs/standard-library/array-functions.md | 74 +++++++++++++++++++++++- docs/standard-library/array.md | 1 + 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/docs/standard-library/array-functions.md b/docs/standard-library/array-functions.md index c73093fd750..d2e34dae34d 100644 --- a/docs/standard-library/array-functions.md +++ b/docs/standard-library/array-functions.md @@ -2,12 +2,12 @@ title: " functions" description: "Learn more about: functions" ms.date: 11/04/2016 -f1_keywords: ["array/std::array::get", "array/std::get", "array/std::swap"] -helpviewer_keywords: ["std::array [C++], get", "std::get [C++]", "std::swap [C++]"] +f1_keywords: ["array/std::array::get", "array/std::get", "array/std::swap", "array/std::to_array"] +helpviewer_keywords: ["std::array [C++], get", "std::get [C++]", "std::swap [C++]", "std::to_array [C++]"] --- # `` functions -The `` header includes two non-member functions, `get` and `swap`, that operate on **array** objects. +The `` header includes three non-member functions, `get`, `swap`, and `to_array` that operate on **array** objects. ## `get` @@ -150,6 +150,74 @@ int main() 0 1 2 3 ``` +## `to_array` + +Converts a built-in array to a `std::array` object. + +```cpp +// C++20 +template +constexpr std::array, Size> to_array(Type (&arr)[Size]); + +// C++20 +template +constexpr std::array, Size> to_array(Type (&&arr)[Size]); +``` + +### Template parameters + +*`Type`*\ +The type of an element. + +*`Size`*\ +The size of the input array. + +### Parameters + +*`arr`*\ +The input array used for conversion. + +### Example + +```cpp +// std_to_array.cpp +// Requires /std:c++20 or later + +#include +#include + +int main() +{ + int arr1[]{ 1, 2, 3 }; + std::array arr2 = std::to_array(arr1); + + std::cout << "std::to_array(arr1):\n"; + for (const auto& i : arr2) + { + std::cout << i << " "; + } + std::cout << std::endl; + + // The size is 7 as it includes the null terminator + std::array arr3 = std::to_array("string"); + + std::cout << "\nstd::to_array(\"string\"):\n"; + for (const auto& i : arr3) + { + std::cout << i << " "; + } + std::cout << std::endl; +} +``` + +```Output +std::to_array(arr1): +1 2 3 + +std::to_array("string"): +s t r i n g +``` + ## See also [``](../standard-library/array.md) diff --git a/docs/standard-library/array.md b/docs/standard-library/array.md index 85273440ba3..1bf0296e70b 100644 --- a/docs/standard-library/array.md +++ b/docs/standard-library/array.md @@ -45,6 +45,7 @@ Defines the container class template **array** and several supporting templates. |-|-| |[get](../standard-library/array-functions.md#get)|Get specified array element.| |[swap](../standard-library/array-functions.md#swap)|Exchanges the contents of one array with the contents of another array.| +| [`to_array`](array-functions.md#to_array) | Converts a built-in array to a `std::array` object. | ## See also From 99323ab1dc7aabbc3ed16af1bd1c03fc683d93e1 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Wed, 20 Aug 2025 18:49:18 +0800 Subject: [PATCH 5/6] Simplify single "See also" link in `` functions reference --- docs/standard-library/array-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard-library/array-functions.md b/docs/standard-library/array-functions.md index d2e34dae34d..a3924b24921 100644 --- a/docs/standard-library/array-functions.md +++ b/docs/standard-library/array-functions.md @@ -220,4 +220,4 @@ s t r i n g ## See also -[``](../standard-library/array.md) +[``](array.md) From d1f2f14af18e9b9aac6a18cf2ded9809e047f36b Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Wed, 20 Aug 2025 18:50:57 +0800 Subject: [PATCH 6/6] Update metadata in 2 standard library topics --- docs/standard-library/array-functions.md | 2 +- docs/standard-library/array.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/standard-library/array-functions.md b/docs/standard-library/array-functions.md index a3924b24921..709189a51eb 100644 --- a/docs/standard-library/array-functions.md +++ b/docs/standard-library/array-functions.md @@ -1,7 +1,7 @@ --- title: " functions" description: "Learn more about: functions" -ms.date: 11/04/2016 +ms.date: 08/20/2025 f1_keywords: ["array/std::array::get", "array/std::get", "array/std::swap", "array/std::to_array"] helpviewer_keywords: ["std::array [C++], get", "std::get [C++]", "std::swap [C++]", "std::to_array [C++]"] --- diff --git a/docs/standard-library/array.md b/docs/standard-library/array.md index 1bf0296e70b..331316ee9e2 100644 --- a/docs/standard-library/array.md +++ b/docs/standard-library/array.md @@ -1,7 +1,7 @@ --- -description: "Learn more about: " title: "" -ms.date: "11/04/2016" +description: "Learn more about: " +ms.date: 11/04/2016 f1_keywords: [""] helpviewer_keywords: ["array header"] ---