std::experimental:: make_array
|
헤더 파일에 정의됨
<experimental/array>
|
||
|
template
<
class
D
=
void
,
class
...
Types
>
constexpr std:: array < VT /* see below */ , sizeof... ( Types ) > make_array ( Types && ... t ) ; |
(라이브러리 펀더멘털 TS v2) | |
인수의 개수와 크기가 동일하고, 요소들이 해당 인수들로부터 초기화된 std::array 를 생성합니다. std:: array < VT, sizeof... ( Types ) > { std:: forward < Types > ( t ) ... }를 반환합니다.
만약
D
가
void
라면, 추론된 타입
VT
는
std::
common_type_t
<
Types...
>
입니다. 그렇지 않으면
D
입니다.
만약
D
가
void
이고
std::
decay_t
<
Types
>
...
중 어느 하나라도
std::reference_wrapper
의 특수화(specialization)인 경우, 프로그램은 형식이 잘못되었습니다(ill-formed).
목차 |
참고 사항
make_array
는 Library Fundamentals TS v3에서 제거되었습니다. 왜냐하면
deduction guide
가
std::array
와
std::to_array
에 대해 이미 C++20에 포함되었기 때문입니다.
가능한 구현
namespace details { template<class> struct is_ref_wrapper : std::false_type{}; template<class T> struct is_ref_wrapper<std::reference_wrapper<T>> : std::true_type{}; template<class T> using not_ref_wrapper = std::negation<is_ref_wrapper<std::decay_t<T>>>; template<class D, class...> struct return_type_helper { using type = D; }; template<class... Types> struct return_type_helper<void, Types...> : std::common_type<Types...> { static_assert(std::conjunction_v<not_ref_wrapper<Types>...>, "Types cannot contain reference_wrappers when D is void"); }; template<class D, class... Types> using return_type = std::array<typename return_type_helper<D, Types...>::type, sizeof...(Types)>; } template<class D = void, class... Types> constexpr details::return_type<D, Types...> make_array(Types&&... t) { return {std::forward<Types>(t)...}; } |
예제
#include <experimental/array> #include <iostream> #include <type_traits> int main() { auto arr = std::experimental::make_array(1, 2, 3, 4, 5); bool is_array_of_5_ints = std::is_same<decltype(arr), std::array<int, 5>>::value; std::cout << "Returns an array of five ints? "; std::cout << std::boolalpha << is_array_of_5_ints << '\n'; }
출력:
Returns an array of five ints? true
참고 항목
|
C++ documentation
for
std::array
deduction guides
|
|
|
내장 배열로부터
std::array
객체를 생성합니다
(함수 템플릿) |
|