https://github.com/bemanproject/scope

P3610 Generic Scope Guard for C++29

https://github.com/bemanproject/scope

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.7%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

P3610 Generic Scope Guard for C++29

Basic Info
  • Host: GitHub
  • Owner: bemanproject
  • License: other
  • Language: C++
  • Default Branch: main
  • Size: 308 KB
Statistics
  • Stars: 2
  • Watchers: 10
  • Forks: 5
  • Open Issues: 15
  • Releases: 1
Created over 1 year ago · Last pushed 10 months ago
Metadata Files
Readme License Codeowners

README.md

beman.scope: Generic Scope Guard

Library Status Continuous Integration Tests Lint Check (pre-commit) Coverage Standard Target Compiler Explorer Example

beman.scope is a C++ library that provides scope_guard facilities. The library conforms to The Beman Standard.

Implements: D3610R0 Scope Guard targeted at C++29.

Status: Under development and not yet ready for production use.

Overview

During the C++20 cycle P0052 Generic Scope Guard and RAII Wrapper for the Standard Library added 4 types: scope_exit, scope_fail, scope_success and unique_resource to LTFSv3.

In the intervening time, two standard libraries have implemented support as well as Boost. With the imperative for safety and security in C++ developers need every tool in the toolbox. The authors believe it is time to move this facility into the standard. The paper will re-examine the five year old design and any learning from deployment of the LTFSv3.

For discussions of this library and related work see:

Usage

  • Compiler Explorer Example

The following is an example of using scope_fail to trigger and action when the scope is exited with an exception. scope_success and scope_exit provide similar capability but with different checked conditions on exiting the scope.

```c++

include

bool triggered = false;
{
    scope_fail guard([&]() { triggered = true; });
    // no exception thrown
}
// triggered == false
try {
    scope_fail guard([&]() { triggered = true; });

    throw std::runtime_error( "trigger failure" );

} catch (...) { // expected }

// triggered == true

```

unique_resource is a cutomizeable RAII type similar to unique_ptr.

```c++

include

{ auto file = beman::scope::unique_resource( fopen("example.txt", "w"), // function to acquire the FILE* { // function to cleanup on destruction if (f) { fclose(f); // Release (cleanup) the resource } } );

// use file via f->

}

// Resource is automatically released when file goes out of scope std::cout << "File has been closed \n"; ```

Full runnable examples can be found in examples/.

Integrate beman.scope into your project

Beman.scope is a header-only library that currently relies on TS implementations and is thus currently available only on g++-13 and up, or clang 19 and up -- in C++20 mode.

Note that modules support is currently tested only on clang++-19 and above and g++-15.

As a header only library no building is required to use in a project -- simply make the include directory available add add the following to your source.

```cpp

include

//modular version

import beman.scope; ``` With modules import needs to be after any includes to avoid compilation errors.

Building beman.scope

Building is only required to run tests and examples. All compilers build and run include based tests. Compilers known to support modules are automatically detected added to tests.

Build Dependencies

The library itself has no build dependencies other than Catch2 for testing. And for building cmake and ninja. Makefiles are supported in non-modular builds.

Build-time dependencies:

  • cmake
  • ninja, make, or another CMake-supported build system
    • CMake defaults to "Unix Makefiles" on POSIX systems
  • catch2 for building tests

How to build beman.scope tests and examples

from root of repo:

shell mkdir build; cd build; cmake .. -DCMAKE_CXX_COMPILER=g++-15 -DCMAKE_CXX_STANDARD=26 -G=Ninja ninja -j 5 -v; ctest

or using cmake presets shell cmake --workflow --preset gcc-release cmake --install build/gcc-release --prefix /opt/beman.scope

License

Source is licensed with the Apache License v2.0 with LLVM Exceptions.

// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

Documentation and associated papers are licensed with the Creative Commons Attribution 4.0 International license.

// SPDX-License-Identifier: CC-BY-4.0

The intent is that the source and documentation are available for use by people how they wish.

The README itself is licensed with CC0 1.0 Universal. Copy the contents and incorporate in your own work as you see fit.

// SPDX-License-Identifier: CC0-1.0

Contributing

Please do! Issues and pull requests are appreciated.

Owner

  • Name: The Beman Project
  • Login: bemanproject
  • Kind: organization

Supporting the efficient design and adoption of the highest quality C++ standard libraries

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 20
  • Total pull requests: 19
  • Average time to close issues: 22 days
  • Average time to close pull requests: 5 days
  • Total issue authors: 6
  • Total pull request authors: 7
  • Average comments per issue: 0.9
  • Average comments per pull request: 0.84
  • Merged pull requests: 13
  • Bot issues: 2
  • Bot pull requests: 0
Past Year
  • Issues: 20
  • Pull requests: 19
  • Average time to close issues: 22 days
  • Average time to close pull requests: 5 days
  • Issue authors: 6
  • Pull request authors: 7
  • Average comments per issue: 0.9
  • Average comments per pull request: 0.84
  • Merged pull requests: 13
  • Bot issues: 2
  • Bot pull requests: 0
Top Authors
Issue Authors
  • JeffGarland (12)
  • robert-andrzejuk (3)
  • github-actions[bot] (2)
  • nickelpro (1)
  • neatudarius (1)
  • ClausKlein (1)
Pull Request Authors
  • JeffGarland (4)
  • wusatosi (3)
  • robert-andrzejuk (3)
  • neatudarius (3)
  • ClausKlein (2)
  • ednolan (1)
  • nickelpro (1)
Top Labels
Issue Labels
enhancement (1)
Pull Request Labels