C++ Logo


Advanced search

Re: [std-proposals] Why some standard functions having a wide contract are not marked as conditionally noexcept?

From: blacktea hamburger <blackteahamburger_at_[hidden]>
Date: Tue, 30 Aug 2022 05:26:13 +0000
Well...but nothing in the paper says that functions having a narrow contract can be marked as conditional noexcept.

And std::begin is similar to std::cbegin, it simply delegates to c.begin(), which is allowed to throw, but std::begin is not marked as conditional noexcept. Similar examples are std::end, std::size, etc.

On Mon, Aug 29, 2022 at 10:22 AM blacktea hamburger via Std-Proposals <std-proposals_at_[hidden]<mailto:std-proposals_at_[hidden]>> wrote:
I have noticed that some standard functions having a wide contract such as functions in [iterator.range]<https://eel.is/c++draft/iterator.range> conditionally do not throw exceptions, but they are not marked as conditionally noexcept.

It is described in N3279<https://wg21.link/N3279>: [2011]

Note that there's also a later paper by Nico Josuttis [2018]:
I don't think any differences are relevant to your question, but just FYI.

But there are some functions that do not obey this guideline such as std::cbegin. And I did not find a reason in this paper.

Can you clarify what you mean? Looking at cppreference,
I see that
(1) std::cbegin in fact has a narrow contract; it simply delegates to std::begin(x), which is allowed to throw.
(2) std::cbegin is marked conditionally noexcept.

So, I'm not sure what you're asking.


Received on 2022-08-30 05:26:18