[英]Why is std::bitset::size non-static
I can't possibly imagine why it was chose that std::bitset::size
is non-static. 我无法想象为什么选择
std::bitset::size
是非静态的。 It makes it much harder to get a constexpr
size; 这使得获得
constexpr
大小变得更加困难; you have to write something like this: 你必须写这样的东西:
template<int val>
struct int_
{
static const constexpr value = val;
};
template<size_t size>
auto getBitsetSizeIMPL(std::bitset<size>)
{
return int_<size>{};
}
template<typename BitsetType>
constexpr size_t getBitsetSize()
{
return decltype(getBitsetSizeIMPL(BitsetType{}))::value;
}
When if it were static all you would have to do would be 如果它是静态的,你所要做的就是
BitsetType::size()
and there would be no sacrifice of functionality. 并且不会牺牲功能。
Is there a historical reason that I am missing or is there a technical fact I am missing? 是否有历史原因导致我失踪或者是否存在我遗漏的技术事实?
The assumption of a not constexpr
std::bitset::size
is incorrect: 不是
constexpr
std::bitset::size
的假设是不正确的:
std::size_t size() const; // until C++11
constexpr std::size_t size(); // since C++11, until C++14
constexpr std::size_t size() const; // since C++14)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.