Date: Thu, 18 Jul 2024 11:47:57 +0100
On Thu, Jul 18, 2024 at 10:55 AM Lénárd Szolnoki wrote:
>
> Widget foo(int x) {
> for (int i = 0; i < x; ++i) {
> auto w = Widget(i);
> if (w.some_observer()) {
> return w;
> }
> }
> return Widget(-1);
> }
enum Status { Success, Retry, Failure };
Widget foo(int const x)
{
int i = 0;
return construct_modify<Widget>(
i, // passed by reference
[&](auto &a) -> Status
{
if ( i++ >= x ) return Failure;
if ( a.some_observer() ) return Success;
return Retry;
},
[](void) -> Widget { return Widget(-1); }
);
}
>
> Widget foo(int x) {
> for (int i = 0; i < x; ++i) {
> auto w = Widget(i);
> if (w.some_observer()) {
> return w;
> }
> }
> return Widget(-1);
> }
enum Status { Success, Retry, Failure };
Widget foo(int const x)
{
int i = 0;
return construct_modify<Widget>(
i, // passed by reference
[&](auto &a) -> Status
{
if ( i++ >= x ) return Failure;
if ( a.some_observer() ) return Success;
return Retry;
},
[](void) -> Widget { return Widget(-1); }
);
}
Received on 2024-07-18 10:48:10