【发布时间】:2019-09-24 22:37:39
【问题描述】:
我需要对 constexpr 数组进行检查,但不知道如何将数组传递给检查函数。
#include <cstdlib>
constexpr int is[2] = {23, 42};
void inline check(const int (&elems)[2])
{
static_assert(elems[0] == 23, "Does not work");
}
void bar()
{
static_assert (is[0] == 23, "Works");
check(is);
}
有没有办法在不丢失 constexpr 属性的情况下将数组传递给检查函数?
【问题讨论】:
-
将其作为模板参数传递。
-
你甚至不能像普通的
int那样做。consteval可能会在一年左右的时间内成为另一个解决方案。