# deduction guides for std::array

> C++ Atlas: `cppatlas.com/w/cpp/container/array/deduction_guides` | Source: https://en.cppreference.com/w/cpp/container/array/deduction_guides | Domain: Containers | Standards: C++17

One deduction guide is provided for std::array to provide an equivalent of std::experimental::make_array for construction of std::array from a variadic parameter pack.

## Official Specification Summary (cppreference)

```cpp
// Defined in header <array>

template< class T, class... U >
array( T, U... ) -> array<T, 1 + sizeof...(U)>; // (since C++17)
```

One deduction guide is provided for `std::array` to provide an equivalent of `std::experimental::make_array` for construction of `std::array` from a variadic parameter pack.

The program is ill-formed if `(std::is_same_v<T, U> &&...)` is not true. Note that `(std::is_same_v<T, U> &&...)` is true when `sizeof...(U)` is zero.

### Example

```cpp
#include <algorithm>
#include <array>
#include <cassert>
#include <type_traits>

int main()
{
    const int 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 facility
    assert(std::ranges::equal(c, std::array{3, 2, 1}));
    static_assert(std::is_same_v<short, decltype(c)::value_type>);
}
```

---
Attribution: content from https://en.cppreference.com/w/cpp/container/array/deduction_guides (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.