Программы на C++. Форум разработчиков
-
Anonymous
Статическая функция шаблона constexpr C++ в структуре
Сообщение
Anonymous »
Я сократил свой код до следующего минимального примера:
Код: Выделить всё
#include
#include
#include
enum Indices : u_int16_t
{
kIndex1 = 0,
kIndex2 = 1,
kNumIndices = 2
};
struct TestStruct
{
static constexpr std::array myvals{4,7};
template
static constexpr uint32_t GetValue()
{
return myvals[myIndex]*5;
}
static constexpr std::array newVals{GetValue(), GetValue()};
};
int main()
{
auto myArr = TestStruct::newVals;
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79384568/c-static-constexpr-template-function-in-struct[/url]
1737726421
Anonymous
Я сократил свой код до следующего минимального примера:
[code]#include
#include
#include
enum Indices : u_int16_t
{
kIndex1 = 0,
kIndex2 = 1,
kNumIndices = 2
};
struct TestStruct
{
static constexpr std::array myvals{4,7};
template
static constexpr uint32_t GetValue()
{
return myvals[myIndex]*5;
}
static constexpr std::array newVals{GetValue(), GetValue()};
};
int main()
{
auto myArr = TestStruct::newVals;
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79384568/c-static-constexpr-template-function-in-struct[/url]