[英]Using fold expression to initialize static constexpr class data member doesn't compile
我很困惑,即使編譯非常相似的代碼片段,也無法編譯的特定代碼片段。
這不會編譯:
#include <bitset>
template<std::size_t ...GROUPS>
class Foo
{
static constexpr std::size_t BIT_COUNT = (GROUPS + ...);
using Bits = std::bitset<BIT_COUNT>;
Bits bits;
};
class Bar : public Foo<6, 6, 6, 6>{};
帶有啟發性錯誤1>c:\\...\\source.cpp(5): error C2059: syntax error: '...'
。
這編譯:
#include <bitset>
template<std::size_t ...GROUPS>
class Foo
{
using Bits = std::bitset<(GROUPS + ...)>;
Bits bits;
};
class Bar : public Foo<6, 6, 6, 6>{};
這也編譯:
#include <bitset>
template<auto... t>
constexpr auto static_sum()
{
return (t + ...);
}
template<std::size_t ...GROUPS>
class Foo
{
static constexpr std::size_t BIT_COUNT = static_sum<GROUPS...>();
using Bits = std::bitset<BIT_COUNT>;
Bits bits;
};
class Bar : public Foo<6, 6, 6, 6>{};
我正在使用Visual Studio 15.9.8中的MSVC ++進行編譯。 我錯過了什么?
編輯:我正在使用/std:c++17
標志進行編譯。 嘗試/std:latest
沒有幫助。
報告為可能的編譯器錯誤: 錯誤報告
編輯:這是一個確認的錯誤,並在Visual Studio 2019中發布了一個修復程序。
我還略微簡化了我對以下內容的最終解決方案:
static constexpr std::size_t BIT_COUNT = [](int i) { return i; }((GROUPS + ...));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.