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::make_array | ||||
Defined in header <experimental/array> | ||
template<class D=void,class...Types> constexprstd::array<VT/* see below */, sizeof...(Types)> make_array( Types&&...t); | (library fundamentals TS v2) | |
Creates astd::array whose size is equal to the number of arguments and whose elements are initialized from the corresponding arguments. Returnsstd::array<VT, sizeof...(Types)>{std::forward<Types>(t)...}.
IfD
isvoid, then the deduced typeVT
isstd::common_type_t<Types...>. Otherwise, it isD
.
IfD
isvoid and any ofstd::decay_t<Types>... is a specialization ofstd::reference_wrapper, the program is ill-formed.
Contents |
make_array
is removed in Library Fundamentals TS v3 because thededuction guide forstd::array
andstd::to_array have been already in 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';}
Output:
Returns an array of five ints? true
C++ documentation for std::array deduction guides | |
creates astd::array object from a built-in array (function template)[edit] |