我无法想象为什么选择使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()
并且不会牺牲功能。
我是否缺少历史原因或者我是否缺少技术事实?
BitsetType{}.size()
。 - cpplearnerstd::array::size
也不是静态的。上周有人问到这个问题。 - Lightness Races in Orbit