Technical Specification | ||||
Filesystem library(filesystem TS) | ||||
Library fundamentals(library fundamentals TS) | ||||
Library fundamentals 2(library fundamentals TS v2) | ||||
Library fundamentals 3(library fundamentals TS v3) | ||||
Extensions for parallelism(parallelism TS) | ||||
Extensions for parallelism 2(parallelism TS v2) | ||||
Extensions for concurrency(concurrency TS) | ||||
Extensions for concurrency 2(concurrency TS v2) | ||||
Concepts(concepts TS) | ||||
Ranges(ranges TS) | ||||
Reflection(reflection TS) | ||||
Mathematical special functions(special functions TR) | ||||
Experimental Non-TS | ||||
Pattern Matching | ||||
Linear Algebra | ||||
std::execution | ||||
Contracts | ||||
2D Graphics |
experimental::to_array | ||||
![]() | Merged into ISO C++ The functionality described on this page was merged into the mainline ISO C++ standard as of 7/2019, seestd::to_array(since C++20) |
Defined in header <experimental/array> | ||
template<class T,std::size_t N> constexprstd::array<std::remove_cv_t<T>, N> to_array(T(&a)[N]); | (library fundamentals TS v2) | |
Creates astd::array from the built-in arraya. The elements of thestd::array are copy-initialized from the corresponding element ofa.
Contents |
a | - | the built-in array to be used to initialize thestd::array |
Anstd::array object whose elements are copy-initialized from the corresponding element ofa.
namespace detail{template<class T,std::size_t N,std::size_t...I>constexprstd::array<std::remove_cv_t<T>, N> to_array_impl(T(&a)[N],std::index_sequence<I...>){return{{a[I]...}};}} template<class T,std::size_t N>constexprstd::array<std::remove_cv_t<T>, N> to_array(T(&a)[N]){return detail::to_array_impl(a,std::make_index_sequence<N>{});} |
#include <cassert>#include <cstdlib>#include <experimental/array>#include <unistd.h> // mkstemp(3) that workstemplate<std::size_t N>int tempfd(charconst(&tmpl)[N]){auto s= std::experimental::to_array(tmpl);int fd= mkstemp(s.data());if(fd!=-1) unlink(s.data()); return fd;} int main(){int fd= tempfd("/tmp/test.XXXXXX");int rt= close(fd);assert(rt==0);}
(library fundamentals TS v2) | creates astd::array object whose size and optionally element type are deduced from the arguments (function template)[edit] |