为什么C++标准要为std::bitset::reference指定一个析构函数?

Why does the C++ standard specifies a destructor for std::bitset::reference?

我想知道为什么std::bitset::reference and std::vector<bool>::reference specifies an explicit destructor (not compiler generated one). Because, for example, boost::dynamic_bitset::reference似乎没有指定这样的析构函数。

仅仅因为标准提到 ~reference() 作为析构函数,并不意味着它必须 user-provided 作为 no-op {}libstdc++ and SGI/STL do it). It could also be user-declared as =default, or even left defined implicitly (which is how libc++ 做到了)。无论如何,可以更新标准以删除对析构函数的明确提及。您可以提交编辑更改(我认为这不值得提出真正的建议)。

正如@BoPersson 在评论中指出的那样,std::bitset 是标准库中非常古老的组件。它的许多特性(无符号整数的隐式构造函数,成员而不是 non-member operator==) pre-date 1998 年的语言标准化。无耻的插件:参见例如this Q&A for more discussion how this might have arisen, and this Q&A 为什么在修复此问题时可能会破坏代码。

<rant mode>

摆脱 std::bitset 遗留问题的最佳方法是彻底打破 namespace experimental。最好,这也将解决 std::bitset 的混合抽象,它同时试图成为 array<bool> 的 space 优化版本以及 set<int>。理想情况下,会有一个 bool_array<N>bounded_int_set<N> 的提案来提供这些抽象。同样,可以定义 bool_vector<Alloc>(目前称为 vector<bool, Alloc>)和 int_set<Alloc>(目前是 boost::dynamic_bitsetboost::container::flat_set<int, Alloc> 的混合)。

</rant mode>