std::experi...::make_array(3)
π NAME π
okay so bestie, you've landed on the std::experi...::make_array(3) page in the C++ Standard Libary manual β section 3, and yes the header really spells it βLibaryβ, we are not fixing it ππ. The page name is std::experimental::make_array β std::experimental::make_array (the NAME line said it twice, and honestly? iconic. it ate. π
).
πΈ Synopsis πΈ
Defined in header <experimental/array>.
template< class D = void, class... Types >
constexpr std::array<VT /* see below */, sizeof...(Types)> make_array( Types&&... t );
The page also tags this as (library fundamentals TS v2). π
Okay so the vibe: it creates a std::array whose size is equal to the number of arguments, and whose elements are initialized from the corresponding arguments. It returns std::array<VT, sizeof...(Types)>{std::forward<Types>(t)...}. Literally main character energy β¨.
If D is void, then the deduced type VT is std::common_type_t<Types...>. Otherwise, it is D.
π¨ IfDisvoidand any ofstd::decay_t<Types>...is a specialization ofstd::reference_wrapper, the program is ill-formed. Not cute, not allowed, no cap. π
π§ Notes π§
make_array is removed in Library Fundamentals TS v3 because the deduction guide for std::array and std::to_array have been already in C++20. So yeah, it's giving βwe have newer toys nowβ energy, fr fr. π¦
π οΈ Possible implementation π οΈ
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)...}; }
π Example π
// Run this code
#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
π₯ See also π₯
- C++ documentation for
std::arraydeduction guides β yes, that's a whole thing, iykyk. to_arraycreates astd::arrayobject from a built-in array (function template) β another icon, lowkey.
mwah π source/version/date check: http://cppreference.com, 2024.06.10, footer label std::experi...::make_array(3) β have the day you deserve, bestie π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms