Boost logo

Boost :

From: Daniela Engert (dani_at_[hidden])
Date: 2023-03-22 11:23:03


Am 22.03.2023 um 11:24 schrieb Andrey Semashev via Boost:
> On 3/22/23 12:38, Dominique Devienne wrote:
>
>> Like [[nodiscard]] with an alternate form like `auto guard =
>> scope_fail(...);` ?
>> I guess that requires move'ability, which might not be desirable?
> `auto guard = scope_fail(...);` would work, as scope_fail is moveable.
> With C++17, I think, you are even guaranteed to elide the move constructor.
With C++17 and guaranteed copy elision you can return non-copyable,
non-movable objects.
> [[nodiscard]] is not usable here as there's nothing to apply it to, as
> we're talking about the scope guard constructor.

[[nodiscard]] is highly desirable here. You can apply the attribute to
class types (and thus their constructors) and avoid the (typically
unwanted) immediate destruction of pr-values. Manager classes should be
marked [[nodiscard]] by habit.

Ciao
 Â  Dani


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk