Date: Tue, 26 Oct 2021 09:05:19 +0100
On Mon, 11 Oct 2021 at 07:54, Anubhav Guleria via Std-Discussion <
std-discussion_at_[hidden]> wrote:
> Thanks for clarifying.
>
> Any specific reason why container's pop_back method can't check for
> current size and if it is 0 then make the pop operation a no-op?
>
It would be a very poor design indeed to identify a bug at run-time and
then to hide it from the user.
However, there's no reason why container's pop_back method can't check for
this bug and trap the error. In your example, simply define
`_GLIBCXX_ASSERTIONS` and you will get that behaviour (
https://godbolt.org/z/WT3Y8qddz). There are more bug-checking options
available. I've listed some of them here
<https://github.com/johnmcfarlane/papers/blob/master/cpp/contractual-disappointment.md#appendix-a---toolchain-specific-recommendations>
.
HTH,
John
std-discussion_at_[hidden]> wrote:
> Thanks for clarifying.
>
> Any specific reason why container's pop_back method can't check for
> current size and if it is 0 then make the pop operation a no-op?
>
It would be a very poor design indeed to identify a bug at run-time and
then to hide it from the user.
However, there's no reason why container's pop_back method can't check for
this bug and trap the error. In your example, simply define
`_GLIBCXX_ASSERTIONS` and you will get that behaviour (
https://godbolt.org/z/WT3Y8qddz). There are more bug-checking options
available. I've listed some of them here
<https://github.com/johnmcfarlane/papers/blob/master/cpp/contractual-disappointment.md#appendix-a---toolchain-specific-recommendations>
.
HTH,
John
Received on 2021-10-26 03:05:32