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

46 Commits

Author SHA1 Message Date
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
Andrey Semashev
f7bb6e2fb1 Workaround for clang < 5.0 that can't pass class template as a TTP from within the class definition. 2023-02-18 14:33:21 +03:00
Andrey Semashev
accb6984a7 Attempt to work around gcc 5-8 ICE. 2023-02-18 14:16:45 +03:00
Andrey Semashev
45b1e47b44 Expanded noexcept specification for make_unique_resource_checked.
This avoids applying std::is_nothrow_constructible to unique_resource,
which at that point is incomplete. Presumably, this causes ICE in
gcc-5 through 8 and compile errors with MSVC.
2023-02-13 03:04:23 +03:00
Andrey Semashev
00df65b1bd Revert "Explicitly specify template parameters in is_not_like specializations."
This reverts commit 7c5aef0bb5.
2023-02-13 02:21:05 +03:00
Andrey Semashev
7c5aef0bb5 Explicitly specify template parameters in is_not_like specializations. 2023-02-13 02:08:23 +03:00
Andrey Semashev
894e32bb66 Removed redefinition of template param default. 2023-02-13 01:59:31 +03:00
Andrey Semashev
8bc955abe5 Removed explicit qualification of func_base. 2023-02-13 01:58:12 +03:00
Andrey Semashev
9b798f52d7 Only enable implicit default construction of the deleter if it doesn't throw.
This is to prevent leaking the resource if default construction of the deleter
throws.
2023-02-13 00:55:36 +03:00
Andrey Semashev
928160b613 Added unique_posix_fd. Fixed unique_resource traits support. Added tests. 2023-02-12 20:13:53 +03:00
Andrey Semashev
166d6a178b Fixes and tests for unique_resource. 2023-01-24 02:22:16 +03:00
Andrey Semashev
9f55473af2 Initial commit. 2023-01-10 02:18:35 +03:00