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