我正在运行以下代码,但是现在如何使用它初始化向量或变量。
constexpr uint32_t _RtlComputeCrc32(
_In_ DWORD dwInitial,
_In_reads_bytes_(stLength) const BYTE *pbyData,
_In_ INT stLength
)
{
ULONG crc = 0xFFFFFFFF;
while (stLength-- != 0)
{
pbyData++;
// crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32_table[(crc ^ *(pbyData++)) & 0x000000FF];
}
return crc ^ 0xFFFFFFFF;
}
constexpr uint32_t crccalc(const std::wstring_view field)
{
return _RtlComputeCrc32(0, (BYTE*)field.data(), (INT)field.size() * sizeof(wchar_t));
}
template<const wchar_t* T >
struct crcfield
{
//static constexpr const std::wstring_view sname = T;
static constexpr const uint32_t field = crccalc(T);
};
struct Field
{
std::wstring_view namee;
static const uint32_t crcfield;
};
如果我现在想要一个静态变量,它的外观如何:
static constexpr const wchar_t *namee = _T("test");
auto f = crcfield**<???>;**
例如,如果我执行以下操作:
auto f = crcfield<_T("t")>;
我得到了错误:
error C2762: 'crcfield': invalid expression as a template argument for 'T'