我无法想象为什么选择std :: bitset :: size是非静态的.这使得获得constexpr大小变得更加困难;你必须写这样的东西:
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;
}
如果它是静态的,你所要做的就是
BitsetType::size()
并且不会牺牲功能.
是否有一个我遗失的历史原因或者我缺少一个技术事实?
最佳答案
假设不是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)
相关文章
- c - 这是std :: bitset :: operator ^ =和std :: bitset :: count的正常行为吗?如果是这样,为什么?
- c - 为什么std :: bitset :: reference :: operator~?
- c - 为什么std :: bitset {} [0]不是constexpr?
- 为什么C标准为std :: bitset :: reference指定了析构函数?
- c - 为什么std :: bitset的位是相反的顺序?
- c - std :: string :: max_size()作为静态成员
- c# - 为什么非静态类中的静态方法不能是扩展方法?
- c# - 如果函数声明是静态的还是非静态的,如果它中的字段是静态的,它会有什么不同吗?
转载注明原文:c – 为什么std :: bitset :: size是非静态的 - 代码日志