#include <array>
template <std::size_t N>
constexpr auto transform(const std::array<float, N>& arr)
{
std::array<int, N> values;
for (std::size_t i{0}; const auto& k : arr)
{
static_assert(std::is_same_v<decltype(k), const float&>);
constexpr auto j = 0;
values[j] = k; // change this j to i and you get a different error as well
++i;
}
return values;
}
int main()
{
constexpr auto values = transform(std::array{0.f});
}
Repro code is
using C++ 20. Based on the repro in https://github.com/microsoft/vscode-cpptools/issues/8673 .
VS screenshot: