Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The deduction guide for std::array

In the C++ 17 and C++ 20 Working Drafts of the C++ Standard the deduction guide for the class template std::array is defined the following way

template<class T, class... U>
array(T, U...) -> array<T, 1 + sizeof...(U)>;

As a result for example this declaration

std::array a = { 1ll, 2llu };

should be compiled and the deduced type of the variable a is std::array<long long, 2>.

However compilers use another deduction guide that checks that all initializers have the same type.

Is it a bug of compilers or was the deduction guide indeed changed in C++ 17 and C++20 Standards?

like image 852
Vlad from Moscow Avatar asked May 17 '26 12:05

Vlad from Moscow


1 Answers

C++17 has that requirement in the deduction guide.

template<class T, class... U>
array(T, U...) -> array<T, 1 + sizeof...(U)>;

Requires: (is_­same_­v<T, U> && ...) is true. Otherwise the program is ill-formed.

[array.cons#2]

like image 108
Caleth Avatar answered May 20 '26 01:05

Caleth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!