[英]`std::bitset::reference` assignment operator?
I was reading the documentation of std::bitset::reference
, and I am not sure to understand why, there are two assignment operators defined: 我正在阅读std::bitset::reference
的文档 ,我不确定为什么,定义了两个赋值运算符:
reference& operator=( bool x );
reference& operator=( const reference& x );
Are the two declarations for optimization reasons, or because the compiler-generated copy function would not have the expected result? 这两个声明是出于优化原因,还是因为编译器生成的复制函数没有预期的结果?
A typical proxy reference class stores a pointer (or reference) to the bitset
and the index of the bit referred to (or something equivalent to these). 一个典型的代理引用类存储的指针(或引用)的bitset
和所述位的索引称为(或东西等效于这些)。 A memberwise copy assignment, if it compiles, would in all likelihood simply reseat the "reference". 成员复制分配,如果编译,很可能只是重新设置“引用”。
But you want b[0] = b[1]
to assign the value of the second bit to the first bit, rather than reseat the proxy reference returned by b[0]
to refer to the second bit. 但是你希望b[0] = b[1]
将第二位的值赋给第一位,而不是重置b[0]
返回的代理引用来引用第二位。 Hence the need for the second overload. 因此需要第二次过载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.