为什么 std::bitset::size 是非静态的
Why is std::bitset::size non-static
我无法想象为什么选择 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)
我无法想象为什么选择 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)