2
0
mirror of https://github.com/boostorg/scope.git synced 2026-01-19 04:42:10 +00:00

60 Commits

Author SHA1 Message Date
Andrey Semashev
90646c6d67 Added a note about support for interruptible close in fd_deleter. 2025-08-08 20:21:24 +03:00
Andrey Semashev
b4099179dc Fixed links to fd_deleter.hpp and fd_resource_traits.hpp in docs. 2025-05-13 02:02:47 +03:00
Andrey Semashev
c1a41db7a6 Wording improvement in the docs. 2025-05-13 01:18:07 +03:00
René Ferdinand Rivera Morell
bc85d865f2 Add support for modular build structure. (#21)
* Make the library modular usable.

* Switch to library requirements instead of source. As source puts extra source in install targets.

* Add missing import-search for cconfig/predef checks.

* Add requires-b2 check to top-level build file.

* Update dependencies.

* Bump B2 require to 5.2

* Remove repeated import-search.

* Move inter-lib dependencies to a project variable and into the build targets.

* Adjust doc build to avoid boost-root references.

* Update build deps.
2024-08-19 02:10:27 +03:00
Andrey Semashev
db963eab9c Fixed an example of using scope_exit with std::function in the docs.
Closes https://github.com/boostorg/scope/issues/20.
2024-07-03 23:17:20 +03:00
Andrey Semashev
8321450aca Improved docs for unallocated_resource.
Expanded on the requirements for resource types and values supported by
unallocated_resource.

Added a note in the INVALID_HANDLE_VALUE example that says it relies on
MSVC extension and other compilers may not accept it.
2024-03-12 15:12:10 +03:00
Andrey Semashev
d18cc5fde7 Mention _read for reading from fds on Windows. 2024-03-08 02:33:49 +03:00
Andrey Semashev
0da459f549 Updated changelog. 2024-02-07 14:02:57 +03:00
Andrey Semashev
db29667f84 Improved scope guard docs. 2024-02-07 13:52:25 +03:00
Andrey Semashev
c8a05799c3 Corrected make_default return type in fd_resource_traits example.
Closes https://github.com/Lastique/scope/issues/18.
2024-02-06 20:50:25 +03:00
Andrey Semashev
052f3ad41f Added missing return in get_random_bytes example in the docs. 2024-02-06 15:36:52 +03:00
Andrey Semashev
75ac159ab6 Fixed operator-> example for unique_resource. 2024-02-04 23:23:24 +03:00
Andrey Semashev
9ea2a7264a Added a missing comma. 2024-02-04 21:17:14 +03:00
Andrey Semashev
16bbac4980 Improved unique_resource docs. 2024-02-04 21:15:23 +03:00
Andrey Semashev
45317772d1 Removed support for "reduced" resource traits in unique_resource.
The support required to be permissive wrt. is_allocated being callable
with a resource argument. This could lead to unexpected behavior, where
the user provided a seemingly conforming resource traits but
unique_resource would still reject them for some reason (e.g. if
is_allocated is not callable with the const resource value, as tested
by unique_resource) and work in "reduced" resource traits mode. This
would change the behavior of the APIs that accept resource values as
an argument (e.g. constructing unique_resource with a resource value
would always produce an object in the allocated state, while the user
would expect it to depend on the resource value).

Removing the support for "reduced" resource traits makes the behavior
more predictable. If the user specified resource traits, it either
compiles and works according to the resource traits, or fails to compile
if the resource traits are somehow not conforming.

The support for customizing default-constructed resource value is not
important enough. It can be worked around by either implementing proper
resource traits, or by specifying the default value in
make_unique_resource_checked.

Additionally, modified unallocated_resource to relax the argument type
of is_allocated and the types of the unallocated values. This can be
useful when the types of the unallocated resource values don't match
the actual resource type (e.g. std::nullptr_t vs. typed pointers).
2024-02-04 19:32:24 +03:00
Andrey Semashev
adf827b190 Docs improvements.
Removed Boost.ScopeExit from the table on the front page. Comparison with
Boost.ScopeExit is in a separate section, so this table duplicated it
to some degree and detracted focus from introducing Boost.Scope.

Added an example with unique_resource to the front page.

Other wording and example improvements.
2024-02-03 21:08:05 +03:00
Andrey Semashev
18ac09b864 Add a link to an article re. different values for unallocated Windows handles. 2024-02-02 06:08:09 +03:00
Andrey Semashev
05bf32daa5 Added an example of using set_active with a runtime value. 2024-02-02 02:42:17 +03:00
Andrey Semashev
f781fd71c7 Improved scope guard examples in docs. 2024-02-01 02:52:09 +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
080e8100f1 Made formatting more consistent in examples. 2024-01-30 11:43:59 +03:00
Andrey Semashev
989676edc1 Write strings in CSV format in the examples in the docs.
This makes the final flush of the file stream actually necessary.
2024-01-30 11:40:30 +03:00
Andrey Semashev
7616f0b944 Added a new set of examples on the front page.
The new row of examples illustrate explicit deactivation of the scope
guards, as opposed to automatic failure detection via scope_fail.

Also improved the other examples to look more realistic.

Closes https://github.com/Lastique/scope/issues/13.
2024-01-30 03:32:54 +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
eca047bf40 Updated discussion re. swap implementation on unique_resource. 2024-01-28 15:50:32 +03:00
Andrey Semashev
10d22551b2 Moved caveats of capturing by reference to a separate section. 2024-01-28 04:36:52 +03:00
Andrey Semashev
56afb11dbd Added an example showing scope_exit/scope_success/scope_fail usage. 2024-01-28 04:11:45 +03:00
Andrey Semashev
a9bb776763 Added a note about resource traits being preferred over make_unique_resource_checked. 2024-01-28 01:47:26 +03:00
Andrey Semashev
84be26e1a2 Use boost::core::functor for simplified CloseHandle deleter in the docs. 2024-01-27 20:36:13 +03:00
Andrey Semashev
ecb7d7c9cd Added comparison with Library Fundamentals TS components in the docs.
Closes https://github.com/Lastique/scope/issues/5.
2024-01-27 20:35:54 +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
ad4005f87e Added an assert to make it obvious that ptr is not null. 2023-12-03 01:16:37 +03:00
Andrey Semashev
7ee1b44711 Added a note about potential issues of capturing by reference in scope guards. 2023-12-03 01:11:01 +03:00
Andrey Semashev
5719cd4966 Changed the wording to discourage using std::function with scope guards. 2023-12-02 23:39:39 +03:00
Andrey Semashev
bc8665d398 Changed the example of unique_resource usage.
Use an `equal_files` function as an example to demonstrate `unique_resource`
usage. This is less controversial than the previously used `write_string`
function, as it should not raise concerns about general correctness of the
function in case of failure (i.e. whether it is correct to leave the file
partially written in case of failure).

Additionally, after code refactoring, the actual interesting part of the
example became smaller, which allowed to remove most of the `equal_files`
implementation from the second and third code samples.

Closes https://github.com/Lastique/scope/issues/9.
2023-12-02 23:21:22 +03:00
Andrey Semashev
958af1cd59 Use a using type alieas instead of a typedef in the docs. 2023-12-02 20:46:25 +03:00
Andrey Semashev
f081d0f850 Improved wording leading to function object type requirements.
Closes https://github.com/Lastique/scope/issues/12.
2023-12-02 19:50:33 +03:00
Andrey Semashev
75e353281a Minor update to a scope_fail example. 2023-11-30 18:56:39 +03:00
Andrey Semashev
d9700c5d96 Added a link to P0052R10 in the docs. 2023-11-28 20:43:01 +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
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
e964176389 Improved table formaitting. 2023-10-15 03:26:21 +03:00
Andrey Semashev
9778a1d3ea Added a separate section with comparison with Boost.ScopeExit 2023-10-15 00:44:27 +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
ee3af04981 Renamed user's object method in the docs.
This avoids a potential confusion that the object in the examples
is a scope guard, as scope guards have the set_active method.

Closes https://github.com/Lastique/scope/issues/1.
2023-04-15 19:47:45 +03:00
Andrey Semashev
45fe19acf4 Added discussion of scope_fail vs. scope_exit in the docs. 2023-04-15 00:22:56 +03:00
Andrey Semashev
0dd24702fa Fixed missing default args in Doxygen docs. 2023-04-09 00:57:35 +03:00