一元按位或折叠位集构造函数
Unary bitwise-or fold in bitset constructor
我正在尝试创建一个结构来封装一些关于函数的信息。其中包括一个代表某些 true/false 行为的位集。我试图将参数包折叠到位集的构造函数中,但它失败了。
这是我的代码:
template<uint8_t ID_in, uint8_t...categories_in>
struct Function_Data {
static constexpr const uint8_t ID = ID_in;
// only two categories so far
static constexpr const bitset<2> categories(categories_in|...);
constexpr inline explicit Function_Data() {}
};
我希望 categories(categories_in|...)
的解析能够理解我正在尝试使用折叠操作,但我收到错误 ‘categories_in’ is not a type
,然后收到 expected ',' or '...' before '|'
令牌。
尝试行 categories(...|categories_in)
会产生形式不同但相似的消息 "was expecting X instead of Y".
对 unsigned long long int(对于构造函数参数类型)使用静态转换会导致 expected identifier before static cast
,这感觉很奇怪,因为前面有一个名称。
如果能帮助结构正常工作,我们将不胜感激。
fold expression 需要额外的括号:
static constexpr const bitset<2> categories{(categories_in|...)};
正如您在 class 定义中一样,使用 {}
(或 = bitset<2>((categories_in|...))
)而不是 ()
来构造成员。
我正在尝试创建一个结构来封装一些关于函数的信息。其中包括一个代表某些 true/false 行为的位集。我试图将参数包折叠到位集的构造函数中,但它失败了。
这是我的代码:
template<uint8_t ID_in, uint8_t...categories_in>
struct Function_Data {
static constexpr const uint8_t ID = ID_in;
// only two categories so far
static constexpr const bitset<2> categories(categories_in|...);
constexpr inline explicit Function_Data() {}
};
我希望 categories(categories_in|...)
的解析能够理解我正在尝试使用折叠操作,但我收到错误 ‘categories_in’ is not a type
,然后收到 expected ',' or '...' before '|'
令牌。
尝试行 categories(...|categories_in)
会产生形式不同但相似的消息 "was expecting X instead of Y".
对 unsigned long long int(对于构造函数参数类型)使用静态转换会导致 expected identifier before static cast
,这感觉很奇怪,因为前面有一个名称。
如果能帮助结构正常工作,我们将不胜感激。
fold expression 需要额外的括号:
static constexpr const bitset<2> categories{(categories_in|...)};
正如您在 class 定义中一样,使用 {}
(或 = bitset<2>((categories_in|...))
)而不是 ()
来构造成员。