deductiongu...rstd::array(3)
π NAME π
okay bestie, this is deductiongu...rstd::array(3), a C++ Standard Libary page about one very specific deduction guide β yes, the title is long enough to need its own emotional support water bottle π. It's giving template arcana, but make it cute π.
β¨ Synopsis β¨
First up: this is defined in header <array> π
β¨
template< class T, class... U >
array( T, U... ) (since C++17)
-> array<T, 1 + sizeof...(U)>;
So the tea is: one deduction guide is provided for std::array, and it exists to give you an equivalent of std::experimental::make_array for construction of std::array from a variadic parameter pack. slay. π«Ά
β οΈ technical caveat, no cap: the program is ill-formed if(std::is_same_v<T, U> && ...)is nottrue. Also note that(std::is_same_v<T, U> && ...)istruewhensizeof...(U)is zero. That's literally the rule, bestie. π
π Example π
Run this code β it's the example, and it ate:
#include <array>
#include <cassert>
int main()
{
int const x = 10;
std::array a{1, 2, 3, 5, x}; // OK, creates std::array<int, 5>
assert(a.back() == x);
// std::array b{1, 2u}; // Error, all arguments must have the same type
// std::array<short> c{3, 2, 1}; // Error, wrong number of template args
std::array c(std::to_array<short>({3, 2, 1})); // C++20 alternative,
// creates std::array<short, 3>
}
mwah π bye now β source/version: http://cppreference.com, date: 2024.06.10, manual page: deductiongu...rstd::array(3). go be a template icon πβ¨
π¦ 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