有没有一种方法可以在编译时已知的索引上静态声明并且在运行时断言?例如: template <class T, int Dim>
class Foo
{
T _data[Dim];
public:
const T &operator[](int idx) const
{
static_assert(idx < Dim, "out of r
读cppreference.com: 静态断言声明可以在块范围出现(作为块 声明)和类体内(作为成员声明) 好了,现在我有以下代码: struct foo_t
{
static constexpr std::size_t maxAlignment()
{
// This is just a sample; I removed real code from this
我的问题是,下面的代码是否有效: template<int i> class Class
{
static_assert(sizeof(i) == 0, "Class instantiated with i != 1");
};
template<> class Class<1> {};
这个片段与g++编译。但clang++被困在static_assert: error: