C++ Logo

std-proposals

Advanced search

Re: [std-proposals] int Func(void) noreentry(-1)

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sun, 12 Feb 2023 22:58:03 +0000
On Sun, Feb 12, 2023 at 9:33 PM Arthur O'Dwyer
<arthur.j.odwyer_at_[hidden]> wrote:
>
> Right. And if instead of being a local variable, `str` were a member variable, then you would have to do this instead:
>
> struct Widget {
> std::once_flag f_;
> std::string str_;
> };
> void Widget::func(int arg) {
> std::call_once(f_, [&]() { str_ = std::to_string(arg); });
> // the rest of the function goes here
> }
>
> That is, we have precedent for "simple case gets core-language support, member-variable case gets a library solution."
> So, I again encourage you to write up exactly what your library solution would do. Once we know what it does, we can
> start worrying about whether it ought to have a core-language syntax for the simple cases or not.


My examples were pretty verbose in my original post which you can see here:

           https://lists.isocpp.org/std-proposals/2023/02/5629.php

Basically it works as follows:
1) If you want to stop a normal function from being re-entered, then
write "noreentry" after its name.
2) If you want to stop a member function from being re-entered for
*this, then write "noreentry_this_object" after its name.
3) If you want to stop a member function from being re-entered for all
objects, then write "noreentry_all_objects" after its name.

My original post which I've linked above gives examples of all three.

Received on 2023-02-12 22:58:12