std::experimental::to_array
Min standard notice:
Header: <experimental/array>
Creates a std::array from the built-in array a. The elements of the std::array are copy-initialized from the corresponding element of a.
# Declarations
template< class T, std::size_t N >
constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&a)[N]);
(library fundamentals TS v2)
# Parameters
a: the built-in array to be used to initialize the std::array
# Return value
An std::array object whose elements are copy-initialized from the corresponding element of a.
# Example
#include <cassert>
#include <cstdlib>
#include <experimental/array>
#include <unistd.h>
// mkstemp(3) that works
template<std::size_t N>
int tempfd(char const (&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);
}