Boost logo

Boost :

From: Klemens Morgenstern (klemensdavidmorgenstern_at_[hidden])
Date: 2023-11-27 01:50:32


Here's my review of boost.scope.

The library should be ACCEPTED without conditions.

I have myself written a boost.ScopeExit replacement for a private
project quite similar to scope_exit.
The reason is not only avoiding the dynamic allocation, but also that
the unwind code can be inline, allowing optimizations.

The scope_fail and scope_success looked a bit odd to me at first,
until I realized that having different types here allows for C++17
deduction guides. So that's a good choice.

All details, like the handling of exceptions from the exit handlers,
are implemented correctly & the code is very readable.
Movable scope guards can also come in very handy with boost asio, when
writing composed operations.

The unique_resource is great. I've been abusing std::unique_ptr quite
often to emulate this.

One thing to point out: boost.ScopeExit has the BOOST_SCOPE_EXIT_ALL
macro, that works like this:

BOOST_SCOPE_EXIT_ALL(this) { do_things(); }

boost.scope could have the BOOST_SCOPE_FINAL be compatible with this,
so that adoption would be a super simple search & replace.

The BOOST_SCOPE_FINAL is limited to C++17 because the correct way is
to use deduction guides, and that would be perfectly fine for me.
However, it would be quite simple to add this functionality to C++11 like so:

struct no_one_likes_expression_templates
{
  template<typename Func>
  auto operator%(Func && func) ->
decltype(boost::scope::make_scope_exit(std::declval<Func>()))
  {
    return boost::scope::make_scope_exit(std::forward<Func>(func));
  }
};

#define BOOST_SCOPE_FINAL_11 \
  auto BOOST_JOIN(_boost_scope_final_,
BOOST_SCOPE_DETAIL_UNIQUE_VAR_TAG) =
no_one_likes_expression_templates{} %

I spent about an hour reading the docs, the code and writing a small
toy program.

On Sat, Nov 25, 2023 at 4:58 AM Дмитрий Архипов via Boost
<boost_at_[hidden]> wrote:
>
> Dear Boost community. The peer review of the proposed Boost.Scope will start on
> 26th of November and continue until December 5th. Boost.Scope is a small
> library implementing utilities defined in
> <experimental/scope> from C++ Extensions for Library Fundamentals v3
> with a few extensions. Namely, the library contains:
> * A number of scope guards for various use cases.
> * A unique resource wrapper that automatically frees the resource on
> destruction.
> * Utilities for wrapping POSIX-like file descriptors in the unique
> resource wrapper.
>
> You can find the source code of the library at
> https://github.com/Lastique/scope and read the documentation at
> https://lastique.github.io/scope/libs/scope/doc/html/index.html. The library
> is header-only and thus it is fairly easy to try it out. In addition, the
> library can be used with Conan and vcpkg (see its README for instructions on
> how to do that). Finally, there's a single header version suitable for Compiler
> Explorer (https://raw.githubusercontent.com/Lastique/scope/single-header/include/boost/scope.hpp).
>
> As the library is not domain-specific, everyone is very welcome to contribute a
> review either by sending it to the Boost mailing list, or me personally. In
> your review please state whether you recommend to reject or accept the library
> into Boost, and whether you suggest any conditions for acceptance.
>
> Thanks in advance for your time and effort!
>
> Dmitry Arkhipov, Staff Engineer at The C++ Alliance.
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


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