使用最新的 GCC 和 Clang 稳定版本时,以下代码可以正常编译。
然而,MSVC 给出了一个错误,即矩阵的初始化未计算为常量。这是 MSVC 错误还是我错过了什么?
实例:
<source>(72): error C2131: expression did not evaluate to a constant
<source>(71): note: failure was caused by out of range index 4; allowed range is 0 <= index < 4
Run Code Online (Sandbox Code Playgroud)
#include <cassert>
#include <cstring>
#include <iostream>
#include <utility>
#include <stdexcept>
struct index_t final
{
constexpr index_t() = default;
constexpr index_t(const std::size_t r, const std::size_t c) :
row{ r },
col{ c }
{
}
std::size_t row{};
std::size_t col{};
};
template<typename …
Run Code Online (Sandbox Code Playgroud)