Date: Thu, 18 Jul 2024 07:24:04 +0100
On 17/07/2024 21:47, Frederick Virchanza Gotham via Std-Proposals wrote:
>
> On Wednesday, July 17, 2024, Lénárd Szolnoki wrote:
>
>
> How do I achieve the same thing with P3357, especially with taking
> care of exception safety?
>
>
>
> Sebastian and I are now collaborating on P3357. The first revision will
> have too many alterations to list, so everyone will just have to read
> the entire thing from start to finish again.
>
> Firstly, 'factory' is renamed to 'construct_modify'.
>
> I haven't put a huge amount of thought into your example, but here's my
> first lash at it:
>
> Widget foo(int const i)
> {
> struct Exception {};
>
> try
> {
> return construct_modify<Widget>(i,
> [](Widget &w)
> {
> if ( ! w. some_observer() ) throw Exception();
> });
> }
> catch(Exception const&)
> {
> return Widget(0);
> }
> }
This is not ideal, as this pessimizes the codegen compared to what is
possible with P2025. In the P2025 version when `w.some_observer()` is
false, but otherwise no exception is thrown then there is no exception
being thrown and caught, other than potential exceptions thrown by
Widget member functions.
I would like to match this clang codegen here:
https://godbolt.org/z/nYsn1qG98
If refactoring this NRVO into guaranteed copy elision through
std::factory (or std::construct_modify) pessimizes this codegen then
that's not very compelling for the proposal.
>
> On Wednesday, July 17, 2024, Lénárd Szolnoki wrote:
>
>
> How do I achieve the same thing with P3357, especially with taking
> care of exception safety?
>
>
>
> Sebastian and I are now collaborating on P3357. The first revision will
> have too many alterations to list, so everyone will just have to read
> the entire thing from start to finish again.
>
> Firstly, 'factory' is renamed to 'construct_modify'.
>
> I haven't put a huge amount of thought into your example, but here's my
> first lash at it:
>
> Widget foo(int const i)
> {
> struct Exception {};
>
> try
> {
> return construct_modify<Widget>(i,
> [](Widget &w)
> {
> if ( ! w. some_observer() ) throw Exception();
> });
> }
> catch(Exception const&)
> {
> return Widget(0);
> }
> }
This is not ideal, as this pessimizes the codegen compared to what is
possible with P2025. In the P2025 version when `w.some_observer()` is
false, but otherwise no exception is thrown then there is no exception
being thrown and caught, other than potential exceptions thrown by
Widget member functions.
I would like to match this clang codegen here:
https://godbolt.org/z/nYsn1qG98
If refactoring this NRVO into guaranteed copy elision through
std::factory (or std::construct_modify) pessimizes this codegen then
that's not very compelling for the proposal.
Received on 2024-07-18 06:24:07