std::experimental:: to_array
From cppreference.net
<
cpp
|
experimental
|
헤더 파일에 정의됨
<experimental/array>
|
||
|
template
<
class
T,
std::
size_t
N
>
constexpr std:: array < std:: remove_cv_t < T > , N > to_array ( T ( & a ) [ N ] ) ; |
(라이브러리 fundamentals TS v2) | |
내장 배열 a 로부터 std::array 를 생성합니다. std::array 의 요소들은 a 의 해당 요소들로부터 복사 초기화됩니다.
목차 |
매개변수
| a | - | 내장 배열로, std::array 초기화에 사용됨 |
반환값
std::array 객체로, 해당 요소들이 a 의 해당 요소들로부터 복사 초기화됩니다.
가능한 구현
namespace detail { template<class T, std::size_t N, std::size_t... I> constexpr std::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> constexpr std::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) 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); }
참고 항목
|
(library fundamentals TS v2)
|
인수들로부터 크기와 선택적으로 요소 타입이 추론되는
std::array
객체를 생성합니다
(함수 템플릿) |