C++ Logo

std-proposals

Advanced search

Re: [std-proposals] The member functions of std::vector<bool>::reference and std::bitset::reference (except for ctors and dtors) should all be const

From: Oleksandr Koval <oleksandr.koval.dev_at_[hidden]>
Date: Fri, 7 Oct 2022 15:57:20 +0300
Wow, that's super weird:

std::vector<bool> v;
const auto b = v[0];
b = true; // o_0

On Fri, Oct 7, 2022 at 3:40 PM blacktea hamburger via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> But their name is "reference". Also, std::vector<bool>::reference has a
> const assignment operator:
>
> constexpr const reference& operator=(bool x) const noexcept;
>
>
> On Fri, Oct 7, 2022 at 8:34 PM Oleksandr Koval <
> oleksandr.koval.dev_at_[hidden]> wrote:
>
>> I think the intent here is to mimic value semantics since assignment
>> actually changes referenced value. Making those functions `const` would be
>> confusing.
>>
>> On Fri, Oct 7, 2022 at 2:42 PM blacktea hamburger via Std-Proposals <
>> std-proposals_at_[hidden]> wrote:
>>
>>> std::vector<bool>::reference and std::bitset::reference are both
>>> proxies, so even if they themselves are const, they can still be used
>>> to change the bit they reference.
>>>
>>> Are there any issues?
>>> --
>>> Std-Proposals mailing list
>>> Std-Proposals_at_[hidden]
>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>>
>>
>>
>> --
>> Regards,
>> Oleksandr Koval.
>>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>


-- 
Regards,
Oleksandr Koval.

Received on 2022-10-07 12:57:33