Difference between revisions of "cpp/experimental/to array"
From cppreference.com
< cpp | experimental
m (→Example: more C++ headers) |
Andreas Krug (Talk | contribs) m (fmt, {{c}}, headers sorted) |
||
(One intermediate revision by one user not shown) | |||
Line 1: | Line 1: | ||
− | {{cpp/experimental/title | to_array}} | + | {{cpp/experimental/title|to_array}} |
{{cpp/experimental/lib_extensions_2/navbar}} | {{cpp/experimental/lib_extensions_2/navbar}} | ||
− | + | ||
{{dcl begin}} | {{dcl begin}} | ||
− | {{dcl header |experimental/array}} | + | {{dcl header|experimental/array}} |
− | {{dcl| since=libfund_ts_2 | 1= | + | {{dcl|since=libfund_ts_2|1= |
− | template <class T, std::size_t N> | + | template< class T, std::size_t N > |
constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&a)[N]); | constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&a)[N]); | ||
}} | }} | ||
{{dcl end}} | {{dcl end}} | ||
− | Creates a {{lc|std::array}} from the built-in array {{ | + | Creates a {{lc|std::array}} from the built-in array {{|a}}. The elements of the {{lc|std::array}} are copy-initialized from the corresponding element of {{|a}}. |
===Parameters=== | ===Parameters=== | ||
{{par begin}} | {{par begin}} | ||
− | {{par | a | the built-in array to be used to initialize the {{lc|std::array}}}} | + | {{par|a|the built-in array to be used to initialize the {{lc|std::array}}}} |
{{par end}} | {{par end}} | ||
===Return value=== | ===Return value=== | ||
− | An {{lc|std::array}} object whose elements are copy-initialized from the corresponding element of {{ | + | An {{lc|std::array}} object whose elements are copy-initialized from the corresponding element of {{|a}}. |
===Possible implementation=== | ===Possible implementation=== | ||
{{eq fun|1= | {{eq fun|1= | ||
− | namespace detail | + | namespace detail |
− | + | ||
− | + | ||
− | + | ||
{ | { | ||
− | return { {a[I]...} }; | + | |
− | } | + | |
+ | |||
+ | |||
+ | return { {a[I]...} }; | ||
+ | } | ||
} | } | ||
− | template <class T, std::size_t N> | + | template<class T, std::size_t N> |
constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&a)[N]) | constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&a)[N]) | ||
{ | { | ||
Line 40: | Line 41: | ||
===Example=== | ===Example=== | ||
{{example | {{example | ||
− | + | |code= | |
− | + | ||
#include <cassert> | #include <cassert> | ||
+ | |||
#include <experimental/array> | #include <experimental/array> | ||
#include <unistd.h> | #include <unistd.h> | ||
// mkstemp(3) that works | // mkstemp(3) that works | ||
− | template <std::size_t N> | + | template<std::size_t N> |
int tempfd(char const (&tmpl)[N]) | int tempfd(char const (&tmpl)[N]) | ||
{ | { | ||
Line 64: | Line 65: | ||
assert(rt == 0); | assert(rt == 0); | ||
} | } | ||
− | + | |output= | |
− | + | ||
}} | }} | ||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc inc | cpp/experimental/dsc make array}} | + | {{dsc inc|cpp/experimental/dsc make array}} |
{{dsc end}} | {{dsc end}} | ||
− | {{langlinks|zh}} | + | {{langlinks|zh}} |