C++ Logo


Advanced search

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

From: blacktea hamburger <greenteahamburger_at_[hidden]>
Date: Sun, 25 Sep 2022 20:43:10 +0800
Is conditional noexcept only for swap function, move-constructor, or
move-assignment operator?

However, according to cppreference
<https://en.cppreference.com/w/cpp/language/noexcept_spec#Notes>, it is
useful for any function templates.

On Sun, Sep 11, 2022 at 10:28 PM blacktea hamburger <
greenteahamburger_at_[hidden]> wrote:

> I also wonder why they hate to use conditional noexcept, what's so bad
> about it?
> On Tue, Aug 30, 2022 at 1:26 PM blacktea hamburger
> wrote:
>> 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]> 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]:
>> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0884r0.pdf
>> 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,
>> https://en.cppreference.com/w/cpp/iterator/begin
>> 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.
>> –Arthur

Received on 2022-09-25 12:43:39