# \<scope\> library

**URL:** <https://discourse.bemanproject.org/t/scope-library/315>\
**Category:** Library::scope\
**Created:** [January 22, 2025, 1:16pm UTC](https://discourse.bemanproject.org/t/scope-library/315 "2025-01-22T13:16:52Z")\
**Posts on this page:** 2\
**Page:** 3

<div class="post-metadata">

**Author:** ![Jeff-Garland](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.bemanproject.org/jeff-garland/32/23_2.png) [@Jeff-Garland](https://discourse.bemanproject.org/u/Jeff-Garland)\
**Post date:** [October 2, 2026, 9:34pm UTC](https://discourse.bemanproject.org/t/scope-library/315/42 "2026-10-02T21:34:55Z")

</div>

Hi Ville – welcome! I’m sure we’ve met somewhere ;). I appreciate the thoughts. Scope is my side project that’s been sitting untouched for awhile, but I’d like to get it into the conversation for Brazil.

You’re in line with pretty much what I’ve been thinking. If we looked at core guidelines they really only have `scope_guard`. success and fail, with coroutines is for sure a potential problem and I agree that just removing them makes sense.

I’m also not a fan of the _release_ function on the guard for the 95% case. It inhibits code readability for one thing – if I see a guard that doesn’t support release – then I can jump to the end of block immediately knowing where things will be released. That also means you don’t need a bool in the guard to handle that check. Instead of this I’m thinking of something more like this

```c++
template<class F, class Condition = ...>
class scope_guard;
...
    ~scope_guard() noexcept {
        if (Condition::execute())
            std::invoke(fn_);
    }

```

Then an advanced user can customise the condition if they so choose, but otherwise the default case is to always executed the function. boost.scope does something like this.

Noted on the CTAD instead of make factory – also we need to concept constrain the callable I’d say.

But am I understanding that you’re suggesting just having for `unique_resource`?

---

<div class="post-metadata">

**Author:** ![Jeff-Garland](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.bemanproject.org/jeff-garland/32/23_2.png) [@Jeff-Garland](https://discourse.bemanproject.org/u/Jeff-Garland)\
**Post date:** [October 3, 2026, 12:57am UTC](https://discourse.bemanproject.org/t/scope-library/315/43 "2026-10-03T00:57:17Z")

</div>

Here’s a better example of what I’m thinking with the condition being a callable. You can trivially get back the success/fail if you want to

> **[Compiler Explorer - C++ (x86-64 gcc 16.2)](https://godbolt.org/z/aMTMf6es5)**
>
> struct always {
> consteval bool operator()() const noexcept {
> return true;
> }
> };
> 
> struct on\_fail {
> int count = std::uncaught\_exceptions();
> 
> constexpr bool operator()() const noexcept {
> return std::uncaught\_exceptions() \>...

[Previous page](https://discourse.bemanproject.org/t/scope-library/315.md?page=2)
