{"id":18736855,"url":"https://github.com/bitwizeshift/scope","last_synced_at":"2025-04-12T19:32:01.684Z","repository":{"id":81485495,"uuid":"199231785","full_name":"bitwizeshift/Scope","owner":"bitwizeshift","description":"A modern C++-RAII utility library, based on the C++20 proposal","archived":false,"fork":false,"pushed_at":"2020-03-28T16:30:09.000Z","size":266,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T14:01:44.490Z","etag":null,"topics":["callback","cpp11","cpp14","cpp17","good-practices","guards","header-only","modern","modern-cpp","no-dependencies","raii","scope","scope-guard","single-file","unique-resource"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitwizeshift.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-28T02:04:15.000Z","updated_at":"2024-10-03T20:45:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"e327c88d-6962-42fc-8323-86e949e6304d","html_url":"https://github.com/bitwizeshift/Scope","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitwizeshift%2FScope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitwizeshift%2FScope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitwizeshift%2FScope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitwizeshift%2FScope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitwizeshift","download_url":"https://codeload.github.com/bitwizeshift/Scope/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248621202,"owners_count":21134773,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["callback","cpp11","cpp14","cpp17","good-practices","guards","header-only","modern","modern-cpp","no-dependencies","raii","scope","scope-guard","single-file","unique-resource"],"created_at":"2024-11-07T15:22:44.626Z","updated_at":"2025-04-12T19:32:01.674Z","avatar_url":"https://github.com/bitwizeshift.png","language":"C++","readme":"\n[![Release](https://img.shields.io/github/release/bitwizeshift/Scope.svg)](https://github.com/bitwizeshift/Scope/releases/latest)\n[![License](https://img.shields.io/badge/License-BSL--1.0-blue.svg)](https://raw.githubusercontent.com/bitwizeshift/Scope/master/LICENSE)\n[![Github Issues](https://img.shields.io/github/issues/bitwizeshift/Scope.svg)](https://github.com/bitwizeshift/Scope/issues)\n\n# {Scope}\n\n**{Scope}** is a modern utility library for managing resources using RAII.\nThis library features a permissive license ([Boost Software License](#license)),\nand is only a single header -- making it simple to drop into any project.\nThis is compatible with any modern version of C++ provided it supports\nC++11 or greater.\n\n**Note:** This library is an implementation of the\n[p0052r6 proposal paper][1] that introduces the `\u003cscope\u003e` header and utilities\nto the C++ standard, but is written in C++11 with support for C++17\ntype-deduced constructors -- rather than only supporting C++17 features.\n\n## Table of Contents\n\n* [Features](#features) \\\n  A summary of all existing features in **{Scope}**\n* [API Reference](https://bitwizeshift.github.io/Scope/api/latest/) \\\n  For doxygen-generated API information\n* [Tutorials](doc/tutorial.md) \\\n  For tutorials on how to use **{Scope}**\n* [How to install](doc/installing.md) \\\n  For a quick guide on how to install/use this in other projects\n* [Legal](doc/legal.md) \\\n  Information about how to attribute this project\n* [Contributing Guidelines](.github/CONTRIBUTING.md) \\\n  Guidelines for how to contribute to this project\n\n## Features\n\n- [x] Easily manage any C-style resources in an idiomatic way with\n      `unique_resource`\n- [x] Handle writing clean-up code exactly once with the various scope guards;\n      keep that code `DRY`!\n- [x] Works with C++11, and is fully functional in C++17\n- [x] Written with portable C++ code, and tested on various compilers and\n      operating systems\n- [x] Only a single-header -- drop it in anywhere!\n- [x] Super permissive license with the [Boost License](#license)\n\n[1]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0052r6.pdf\n\n### Scope Guards\n\nScope guards allow for deferring an action until the end of a given scope.\nThis can be useful for various things:\n\n* Logging\n* Cleaning up resources in a function with multiple exit cases\n* Creating transactional support by 'rolling-back' changes on failure\n* etc\n\nThree different scope guards exist for handling different exit strategies:\n\n* **`scope_exit`**: Executes the callback every time\n* **`scope_success`**: Executes the callback only on successful scope exit\n  (no exceptions thrown)\n* **`scope_fail`**: Executes the callback only on exceptional cases, when\n  a scope is terminating due to a thrown exception.\n\n### `unique_resource`\n\nThe `unique_resource` type is a more general version of the C++ standard's\n`unique_ptr`, allowing for any underlying resource type to be managed with\nunique ownership. This utility is extremely helpful for managing resources\ndistributed by old C-style interfaces.\n\nFor example, this could be done to manage a POSIX file:\n\n```c++\n{\n  auto file = ::scope::make_unique_resource(\n    ::open(...),\n    \u0026::close\n  );\n  // decltyp(file) is ::scope::unique_resource\u003cint,void(*)(int)\u003c\n\n  ...\n\n} // calls ::close on scope\n```\n\nIn general, this can be used for any type of resource that has a dedicated\ncleanup function. The deleters can be functors, lambdas, or any function\npointer.\n\n## Tested Compilers\n\nThe following compilers are currently being tested through\n[continuous integration](#continuous-integration) with\n[Travis](https://travis-ci.com/bitwizeshift/Scope) and\n[AppVeyor](https://ci.appveyor.com/project/bitwizeshift/scope)\n\n| Compiler              | Operating System                   |\n|-----------------------|------------------------------------|\n| `g++4.9`              | Ubuntu 14.04.5 LTS                 |\n| `g++5`                | Ubuntu 14.04.5 LTS                 |\n| `g++6`                | Ubuntu 14.04.5 LTS                 |\n| `g++7`                | Ubuntu 14.04.5 LTS                 |\n| `g++8`                | Ubuntu 14.04.5 LTS                 |\n| `clang++-3.5`         | Ubuntu 14.04.5 LTS                 |\n| `clang++-3.6`         | Ubuntu 14.04.5 LTS                 |\n| `clang++-8.0`         | Ubuntu 14.04.5 LTS                 |\n| Xcode-9 clang++       | Mac OSX 10.12.6 (Darwin 16.7.0)    |\n| Xcode 9.1 clang++     | Mac OSX 10.12.6 (Darwin 16.7.0)    |\n| Xcode 9.2 clang++     | Mac OSX 10.12.6 (Darwin 16.7.0)    |\n| Xcode 9.3 clang++     | Mac OSX 10.13.3 (Darwin 17.4.0)    |\n| Xcode 9.44 clang++    | Mac OSX 10.13.3 (Darwin 17.4.0)    |\n| Xcode 10 clang++      | Mac OSX 10.13.6 (Darwin 17.7.0)    |\n| Visual Studio 2015    | Windows Server 2012 R2             |\n| Visual Studio 2017    | Windows Server 2016                |\n\n## Continuous Integration\n\n| **Build**     | **Status**      |\n|---------------|-----------------|\n| Ubuntu, macOS | [![Build Status](https://travis-ci.com/bitwizeshift/Scope.svg?branch=master)](https://travis-ci.com/bitwizeshift/Scope) |\n| MSVC          | [![Build status](https://ci.appveyor.com/api/projects/status/wj0frj0ld1xh0ltk/branch/master?svg=true)](https://ci.appveyor.com/project/bitwizeshift/scope/branch/master) |\n\n## Current Releases\n\n| **Host**            | **Release**      |\n|---------------------|------------------|\n| Github              | [![Release](https://img.shields.io/github/release/bitwizeshift/Scope.svg)](https://github.com/bitwizeshift/Scope/releases/latest) |\n| Conan               | [ ![Release](https://api.bintray.com/packages/bitwizeshift/Scope/Scope%3Ascope/images/download.svg) ](https://bintray.com/bitwizeshift/Scope/Scope%3Ascope/_latestVersion) |\n\n## License\n\n\u003cimg align=\"right\" src=\"http://opensource.org/trademarks/opensource/OSI-Approved-License-100x137.png\"\u003e\n\n**{Scope}** is licensed under the\n[Boost Software License 1.0](https://www.boost.org/users/license.html):\n\n\u003e Boost Software License - Version 1.0 - August 17th, 2003\n\u003e\n\u003e Permission is hereby granted, free of charge, to any person or organization\n\u003e obtaining a copy of the software and accompanying documentation covered by\n\u003e this license (the \"Software\") to use, reproduce, display, distribute,\n\u003e execute, and transmit the Software, and to prepare derivative works of the\n\u003e Software, and to permit third-parties to whom the Software is furnished to\n\u003e do so, all subject to the following:\n\u003e\n\u003e The copyright notices in the Software and this entire statement, including\n\u003e the above license grant, this restriction and the following disclaimer,\n\u003e must be included in all copies of the Software, in whole or in part, and\n\u003e all derivative works of the Software, unless such copies or derivative\n\u003e works are solely in the form of machine-executable object code generated by\n\u003e a source language processor.\n\u003e\n\u003e THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n\u003e IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n\u003e FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT\n\u003e SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE\n\u003e FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,\n\u003e ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n\u003e DEALINGS IN THE SOFTWARE.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitwizeshift%2Fscope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitwizeshift%2Fscope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitwizeshift%2Fscope/lists"}