Почему это не работает (GCC с STD 26)?#include
#include
template
consteval auto identity()
{
std::array mat;
for (int i = 0; i < M; ++i)
for (int j = 0; j < N; ++j)
mat[i * N + j] = i == j;
return mat;
}
consteval auto count_non_zeros(std::ranges::input_range auto&& range)
{
size_t i = 0;
for (auto x : range)
i += x != 0;
return i;
}
template
consteval auto create_triplets(
std::ranges::input_range auto&& mat)
{
using Tp = std::tuple;
constexpr auto non_zeros = count_non_zeros(mat);
auto tplist = std::array {};
auto it = tplist.begin();
for (size_t i = 0; i < M; ++i)
for (size_t j = 0; j < N; ++j) {
const auto val = mat[i * N + j];
if (val == 0)
continue;
*it++ = Tp(i, j, val);
}
return tplist;
}
int main()
{
constexpr auto N = 10, M = 10;
constexpr auto mat = identity();
constexpr auto tplist = create_triplets(mat);
return 0;
}
< /code>
Сообщение об ошибке: < /p>
main.cc: In instantiation of ‘consteval auto create_triplets(auto:49&&) [with long unsigned int N = 10; long unsigned int M = 10; T = float; auto:49 = const std::array&]’:
main.cc:46:50: required from here
46 | constexpr auto tplist = create_triplets(mat);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~
main.cc:27:47: in ‘constexpr’ expansion of ‘count_non_zeros((* & mat))’
main.cc:17:15: error: ‘* & mat’ is not a constant expression
17 | for (auto x : range)
| ^
Подробнее здесь: https://stackoverflow.com/questions/794 ... l-function
Ошибка: '* & mat' не является постоянным выражением в постоянной функции ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
У меня есть несколько вопросов относительно кнопки mat-icon, mat-icon и mat-menu.
Anonymous » » в форуме CSS - 0 Ответы
- 58 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Ошибка! Переменная contexpr должна быть инициализирована постоянным выражением contexpr
Anonymous » » в форуме C++ - 0 Ответы
- 24 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Ошибка! Переменная contexpr должна быть инициализирована постоянным выражением contexpr
Anonymous » » в форуме C++ - 0 Ответы
- 3 Просмотры
-
Последнее сообщение Anonymous
-