Re: [boost] [scope] Proposing Boost.Scope
On Wed, Mar 22, 2023 at 10:04 AM Andrey Semashev via Boost < boost@lists.boost.org> wrote:
error_code ec; scope_fail guard( [&] { std::cout << "Failure" << std::endl; }, [&ec] { return !!ec; });
Having made the dumb mistake of writing once or twice `scope_fail(...);` instead of `scope_fail guard(...);`, is there a way to prevent that? Like [[nodiscard]] with an alternate form like `auto guard = scope_fail(...);` ? I guess that requires move'ability, which might not be desirable?
On 3/22/23 12:38, Dominique Devienne wrote:
On Wed, Mar 22, 2023 at 10:04 AM Andrey Semashev via Boost
mailto:boost@lists.boost.org> wrote: error_code ec; scope_fail guard( [&] { std::cout << "Failure" << std::endl; }, [&ec] { return !!ec; });
Having made the dumb mistake of writing once or twice `scope_fail(...);` instead of `scope_fail guard(...);`, is there a way to prevent that?
One way would be to use BOOST_SCOPE_FINAL. :)
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. [[nodiscard]] is not usable here as there's nothing to apply it to, as we're talking about the scope guard constructor.
participants (2)
-
Andrey Semashev
-
Dominique Devienne