$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2023-03-22 10:17:47
On 3/22/23 12:38, Dominique Devienne wrote:
> On Wed, Mar 22, 2023 at 10:04â¯AM Andrey Semashev via Boost
> <boost_at_[hidden] <mailto:boost_at_[hidden]>> 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.