std::to_array function is used to create std::array objects. It takes an initializers list and optionally type of the element and size as type template argument. For example:

constexpr auto ids{std::to_array<short, 6>({1, 2, 3, 4})};

It is possible to just provide type and omit the size as shown below:

constexpr auto ids{std::to_array<short>({1, 2, 3, 4})};

Tip

TAD (template argument deduction) supports partial omission of type template arguments for function template resolution. As shown in above example, length is determined

However, using this function is expensive because it first creates a temporary object and then copy initializes to actual array(ids in our case).

References

  1. https://www.learncpp.com/cpp-tutorial/introduction-to-stdarray/