![](/img/trans.png)
[英]How to obtain constexpr `.size()` of a non-static std::array member
[英]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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.