2
0
mirror of https://github.com/boostorg/scope.git synced 2026-01-25 18:52:09 +00:00
Commit Graph

61 Commits

Author SHA1 Message Date
Andrey Semashev
7167bce99a Don't call reset() in unique_resource destructor, call the deleter directly.
This avoids potentially assigning the default to the resource value, which
may be expensive and is pointless, as the resource is about to be destroyed
anyway.
2024-02-04 01:46:07 +03:00
Andrey Semashev
d53d4f43af Enforced correctness checks for resource traits, improved docs.
Instead of silently switching to the unique_resource implementation
based on the "allocated" flag if the resource traits don't conform
to the requirements, issue hard compilation errors. This should better
protect against mistakes, where the user assumes unique_resource
behaves as if it is using the resource traits while it actually doesn't.

Improved documentation of requirements for resource traits and documented
the "reduced" form of resource traits, where the traits only provide
the default resource value but otherwise don't change unique_resource
behavior.
2024-01-31 04:52:12 +03:00
Andrey Semashev
bb295bcd77 Consistently use "unallocated" term to refer to a unique_resource in an unallocated state. 2024-01-31 01:39:32 +03:00
Andrey Semashev
e595286ad3 Converted typedefs to using type aliases.
One person during review complained that the library implementation
used typedefs instead of C++11 using type aliases. Not an essential
difference, but if it helps code readability, let it be.
2024-01-31 01:11:01 +03:00
Andrey Semashev
012104819f Improved comment. 2024-01-28 23:43:22 +03:00
Andrey Semashev
8c985b565c Changed behavior of unique_resource constructor to be non-destructive.
If the resource type is nothrow move-constructible and the deleter type
is not, and the deleter's copy constructor throws during unique_resource
move constructor, then move the move-constructed resource back to the
original object instead of invoking the deleter on it. This leaves the
move source in its original state rather than in unallocated state,
which means unique_resource move constructor now provides strong
exception guarantee.
2024-01-28 23:27:53 +03:00
Andrey Semashev
6f2adf3988 Made unique_resource::reset() implementation slightly more efficient. 2024-01-28 18:50:54 +03:00
Andrey Semashev
7be5037875 Simplified unique_resource swap implementation. 2024-01-28 18:50:54 +03:00
Andrey Semashev
3d228f7294 Switched to BOOST_NO_CXX17_AUTO_NONTYPE_TEMPLATE_PARAMS from Boost.Config. 2024-01-26 22:57:25 +03:00
Andrey Semashev
518557da18 Switch to Boost.Config macro for C++17 fold expressions.
Turns out, Boost.Config's macro is not excessively restrictive.
2024-01-24 03:12:32 +03:00
Andrey Semashev
d45a6255aa Added unallocated_resource for simplified declaration of resource traits.
A new unallocated_resource class template allows to automatically generate
resource traits from one or more unallocated resource values.

The idea for a more compact unique_resource declaration was given
by Janko Dedic in his review.
2024-01-24 02:59:54 +03:00
Andrey Semashev
fa650d558d Added explicit operator bool to unique_resource.
The operator tests if the resource wrapper is in an allocate state.
2024-01-21 19:52:29 +03:00
Andrey Semashev
a53bdaad49 Removed release() member of scope guards.
Although it was there to make the scope guards intergace-compatible with
the TS, the review conclusion indicated that strict conformance with
the TS is not a desired goal. So remove the release() method and keep
set_active() as the way to (de)activate the scope guard.
2024-01-21 19:47:46 +03:00
Andrey Semashev
b0117a4b2e Renamed scope_final to defer_guard and BOOST_SCOPE_FINAL to BOOST_SCOPE_DEFER.
This follows the suggestion by Peter Dimov during the review.
2024-01-19 01:13:26 +03:00
Andrey Semashev
80d26d6909 Prevent default-construction of function pointers.
Default- and value-constructed pointers to functions are not callable,
and therefore are not accepted as default-constructible condition
function objects and deleters.

Closes https://github.com/Lastique/scope/issues/14.
2023-12-17 19:16:08 +03:00
Andrey Semashev
2cd37e97c9 Remove forwarding res to is_allocated on unique_resource_data construction.
It is possible that the resource source will become moved-from after the
call to is_allocated, and that moved-from state will then be used to
initialize the resource in the resource_holder. To avoid this, don't
forward the resource source to is_allocated.

Fixes https://github.com/Lastique/scope/issues/10.
2023-12-01 19:33:21 +03:00
Andrey Semashev
a43830544a Removed forwarding resource and deleter when constructor may throw.
When resource_holder and deleter_holder are constructed, and resource/deleter
constructor may throw, remove forwarding the source resource/deleter to
the constructor. Forwarding there has no effect anyway, as the unique_resource
constructor already ensures the corresponding argument is passed as
an lvalue reference by using move_or_copy_construct_ref.
2023-12-01 19:32:27 +03:00
Andrey Semashev
969584e578 Use invoke_swap to swap m_allocated flags. 2023-12-01 18:49:07 +03:00
Andrey Semashev
ecb01f0f1c Added a comment describing is_not_like. 2023-12-01 17:46:05 +03:00
Andrey Semashev
28969ef48a Improved wording of scope_success/fail description. 2023-11-30 19:58:01 +03:00
Andrey Semashev
46cd547bb4 Switched noexcept conditions checking the deleter to use is_nothrow_invocable.
Also hidden these conditions from docs since they now involve symbols
from namespace detail.

Added test for noexcept(reset()).

Closes https://github.com/Lastique/scope/issues/7.
2023-11-28 15:08:02 +03:00
Andrey Semashev
016a3a3820 Decay references to functions to pointers in scope guards CTAD.
Apparently, the Library Fundamentals TS does permit pointers to functions
in scope guards (via the "function object type" definition in the standard),
so instead of taking the effort to preserve the function references decay
those to pointers to functions.

Updated docs and tests.
2023-11-28 14:50:12 +03:00
Andrey Semashev
c9725c4577 Changed unique resource deduction guide to use decay semantics.
This reflects the decay type trait that is used in make_unique_resource_checked
and is needed to support references to functions for deleters.

Added tests for unique_resource type deductions involving references
to functions.
2023-11-28 14:18:09 +03:00
Andrey Semashev
579d953712 Removed scope guard deduction guides for move constructors.
The implicitly added copy deduction guide works in their stead.
2023-11-28 13:51:25 +03:00
Andrey Semashev
052b3b156a Fixed scope guard function type deduction for function references.
Scope guard factory functions used to generate scope guards with incorrect
action and condition types if the factory was called with function
references. The scope guard template arguments used to be function types
instead of references to functions.

Also, deduction guides used to decay the arguments, which would produce
scope guards with pointers to functions in template arguments. Although
this worked, formally only references to functions are supported. So
changed the deduction guides to produce references to functions.

Updated docs and tests.

Fixes https://github.com/Lastique/scope/issues/6.
2023-11-28 01:38:35 +03:00
Andrey Semashev
660ae7245f Corrected a comment. 2023-11-26 19:30:36 +03:00
Andrey Semashev
6c14f5ccbd Simplified compact_storage implementation. 2023-10-16 02:34:18 +03:00
Andrey Semashev
600ba564cb Nonessential code formatting. 2023-10-16 02:24:00 +03:00
Andrey Semashev
fa83932e51 Separated fd_deleter and fd_resource_traits into different headers. 2023-10-14 19:33:53 +03:00
Andrey Semashev
fbfdb8a494 Merged scope_check into scope_exit.
As suggested by Peter Dimov on boost-dev ML, scope_check functionality
is merged into scope_exit. Thus scope_exit now has an optional condition
function object, which by default always returns true. If a custom
function object is specified, scope_exit works equivalently to the
previous scope_check, i.e. calls the condition function object to check
whether the action function object needs to be called.
2023-10-14 19:23:32 +03:00
Andrey Semashev
f44ada4ab8 Switch to boost::core::invoke_swap.
boost::swap is deprecated and will be removed. Use boost::core::invoke_swap
as a replacement.
2023-09-03 04:08:35 +03:00
Andrey Semashev
f3ea39eeb7 Assert the expected uncaught_exceptions() result in exception_checker.
This may help detect unsupported uses of exception_checker with coroutines
and non-scoped scope guards.

Closes https://github.com/Lastique/scope/issues/2.
2023-04-24 00:38:47 +03:00
Andrey Semashev
a4a5a8443a Added docs for template parameters. 2023-04-09 01:03:23 +03:00
Andrey Semashev
0dd24702fa Fixed missing default args in Doxygen docs. 2023-04-09 00:57:35 +03:00
Andrey Semashev
c9434eaee8 Updated docs to discuss issues with checking for a thrown exception.
Based on the boost-dev ML discussion, added a note regarding exception_checker
limitation with coroutines. Also, rearranged docs and improved wording in
a few places to make exception_checker and condition functions in general
documentation more distinct. Added rationale for using conditional scope guards
as opposed to using scope_exit universally.
2023-04-09 00:30:36 +03:00
Andrey Semashev
c5635f21cc Implemented scope_check and added support for arbitrary fail conditions.
The new scope_check scope guard is a generalization of scope_success and
scope_fail and allows specifying arbitrary conditions for executing the
scope exit action. The scope_success and scope_fail have been
reimplemented in terms of scope_check and now also support arbitrary
fail conditions.

Added exception_checker and error_code_checker conditions for testing
for an exception being thrown and for an error code, respectively.
scope_success and scope_fail use exception_checker by default.

Added tests for the new components.
2023-03-26 21:02:11 +03:00
Andrey Semashev
5a8148562f Removed name imports into boost namespace. 2023-03-22 03:57:17 +03:00
Andrey Semashev
bb538c366c Working on unique_resource docs. 2023-03-22 03:23:56 +03:00
Andrey Semashev
0e83fcbde7 Added support for file descriptors on Windows. 2023-03-20 00:21:06 +03:00
Andrey Semashev
04fec628ef Updating docs for unique_resource. 2023-03-12 20:56:55 +03:00
Andrey Semashev
b0b11e3d55 Converted HTML markup to Markdown in Doxygen comments. 2023-03-11 15:05:01 +03:00
Andrey Semashev
4f551c185c Fixed a typo in a comment. 2023-03-07 00:57:47 +03:00
Andrey Semashev
2da0db4f58 Reuse is_swappable from Boost.TypeTraits. 2023-03-06 04:43:38 +03:00
Andrey Semashev
39dc0b1cd7 Added Doxygen documentation. 2023-03-06 04:42:15 +03:00
Andrey Semashev
f3cfd937f6 Updated license headers. 2023-02-24 19:30:55 +03:00
Andrey Semashev
18b135804a Added support for default_resource keyword. 2023-02-22 01:38:35 +03:00
Andrey Semashev
678253f727 Added more tests for exception handling, fixed bugs. 2023-02-21 02:27:42 +03:00
Andrey Semashev
288d1bfb83 Added header/footer.hpp to disable common warnings. 2023-02-20 02:28:04 +03:00
Andrey Semashev
1e9787d4e8 Avoid using try/catch in non-throwing ctors to silence MSVC warnings. 2023-02-19 20:31:13 +03:00
Andrey Semashev
dbfe34ae36 Workaround MSVC-14.0 lack of support for SFINAE expressions. 2023-02-18 15:54:30 +03:00