为什么std :: bitset :: size是非静态的

时间:2015-10-30 04:01:10

标签: c++ c++11 std bitset

我无法想象为什么选择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()

并且不会牺牲功能。

是否有一个历史原因导致我失踪或是否存在我遗漏的技术事实?

1 个答案:

答案 0 :(得分:1)

strtotime() std::bitset::size的假设不正确:

constexpr