本文介绍了为什么std :: bitset :: size是非静态的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不能想象为什么选择 std :: bitset :: size
是非静态的。这使得很难得到 constexpr
size;你必须这样写:
I can't possibly imagine why it was chose that std::bitset::size
is non-static. It makes it much harder to get a constexpr
size; 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()
b $ b
并且不会牺牲功能。
and there would be no sacrifice of functionality.
有没有历史原因,我缺少或有一个技术事实,我失踪? / p>
Is there a historical reason that I am missing or is there a technical fact I am missing?
推荐答案
假设不是 constexpr
不正确:
The assumption of a not constexpr
std::bitset::size
is incorrect:
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)
这篇关于为什么std :: bitset :: size是非静态的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!