Date: Mon, 20 May 2024 09:11:03 +0000
Or just do this instead:
int main(void)
{
mutex m;
m.lock();
}
Does exactly the same thing, saves on functions calls, don't have to write a function, don't need to add a language feature, don't have to abuse the language, it actually makes sense from what a mutex is, its shorter, concise, transparent, clear.
Some problems don't need solving because they were never problems to begin with.
-----Original Message-----
From: Std-Proposals <std-proposals-bounces_at_lists.isocpp.org> On Behalf Of Frederick Virchanza Gotham via Std-Proposals
Sent: Monday, May 20, 2024 10:25
To: std-proposals_at_[hidden]ocpp.org
Cc: Frederick Virchanza Gotham <cauldwell.thomas_at_gmail.com>
Subject: Re: [std-proposals] std::elide
On Mon, May 20, 2024 at 7:59 AM Frederick Virchanza Gotham wrote:
>
> Or here's another way of doing it:
> If an exception is thrown and propagates outside of the function,
> then all destructors are invoked in the regular order -- except for
> the destructor of the return object, which is invoked last.
Actually I just had another idea.
------ Step 1: Start off by writing the function you want
mutex Func(void)
{
mutex m;
m.lock();
return m;
}
------ Step 2: Re-write the function to manipulate an std::optional, we'll call this function an "optifunc":
void Func(optional<mutex> &arg)
{
arg.emplace();
arg->lock();
}
------ Step 3: Tell the compiler to take your optifunc and convert it into a NRVO function
using Func2 = std::nrvo_from_optifunc(Func);
------ Step 4: Now just invoke Func2
int main(void)
{
mutex m = Func2();
}
--
Std-Proposals mailing list
Std-Proposals_at_lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
int main(void)
{
mutex m;
m.lock();
}
Does exactly the same thing, saves on functions calls, don't have to write a function, don't need to add a language feature, don't have to abuse the language, it actually makes sense from what a mutex is, its shorter, concise, transparent, clear.
Some problems don't need solving because they were never problems to begin with.
-----Original Message-----
From: Std-Proposals <std-proposals-bounces_at_lists.isocpp.org> On Behalf Of Frederick Virchanza Gotham via Std-Proposals
Sent: Monday, May 20, 2024 10:25
To: std-proposals_at_[hidden]ocpp.org
Cc: Frederick Virchanza Gotham <cauldwell.thomas_at_gmail.com>
Subject: Re: [std-proposals] std::elide
On Mon, May 20, 2024 at 7:59 AM Frederick Virchanza Gotham wrote:
>
> Or here's another way of doing it:
> If an exception is thrown and propagates outside of the function,
> then all destructors are invoked in the regular order -- except for
> the destructor of the return object, which is invoked last.
Actually I just had another idea.
------ Step 1: Start off by writing the function you want
mutex Func(void)
{
mutex m;
m.lock();
return m;
}
------ Step 2: Re-write the function to manipulate an std::optional, we'll call this function an "optifunc":
void Func(optional<mutex> &arg)
{
arg.emplace();
arg->lock();
}
------ Step 3: Tell the compiler to take your optifunc and convert it into a NRVO function
using Func2 = std::nrvo_from_optifunc(Func);
------ Step 4: Now just invoke Func2
int main(void)
{
mutex m = Func2();
}
--
Std-Proposals mailing list
Std-Proposals_at_lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2024-05-20 09:11:11