{"id":20968222,"url":"https://github.com/ricab/scope_guard","last_synced_at":"2026-03-04T07:02:17.122Z","repository":{"id":29387009,"uuid":"121540561","full_name":"ricab/scope_guard","owner":"ricab","description":"A modern C++ scope guard that is easy to use but hard to misuse.","archived":false,"fork":false,"pushed_at":"2023-03-23T19:13:56.000Z","size":311,"stargazers_count":189,"open_issues_count":8,"forks_count":31,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-06-01T11:21:53.734Z","etag":null,"topics":["c-plus-plus","cpp","cpp11","cpp14","cpp17","guard","header-only","idioms","no-dependencies","raii","scope-exit","scope-guard","single-file"],"latest_commit_sha":null,"homepage":"https://ricab.github.io/scope_guard/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ricab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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,"zenodo":null}},"created_at":"2018-02-14T17:37:14.000Z","updated_at":"2025-05-27T20:36:32.000Z","dependencies_parsed_at":"2025-05-14T09:43:26.537Z","dependency_job_id":"07452d44-298d-4b12-be35-13c07fb39ce6","html_url":"https://github.com/ricab/scope_guard","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/ricab/scope_guard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricab%2Fscope_guard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricab%2Fscope_guard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricab%2Fscope_guard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricab%2Fscope_guard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ricab","download_url":"https://codeload.github.com/ricab/scope_guard/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricab%2Fscope_guard/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30075425,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T05:31:57.858Z","status":"ssl_error","status_checked_at":"2026-03-04T05:31:38.462Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["c-plus-plus","cpp","cpp11","cpp14","cpp17","guard","header-only","idioms","no-dependencies","raii","scope-exit","scope-guard","single-file"],"created_at":"2024-11-19T03:07:35.265Z","updated_at":"2026-03-04T07:02:17.105Z","avatar_url":"https://github.com/ricab.png","language":"C++","readme":"# scope_guard\n\n[![Build Status](https://github.com/ricab/scope_guard/actions/workflows/test.yml/badge.svg)](https://github.com/ricab/scope_guard/actions/workflows/test.yml)\n[![Build status](https://img.shields.io/appveyor/ci/ricab/scope-guard.svg)](https://ci.appveyor.com/project/ricab/scope-guard/branch/main)\n[![codecov](https://img.shields.io/codecov/c/github/ricab/scope_guard.svg)](https://codecov.io/gh/ricab/scope_guard)\n\n[![GitHub release](https://img.shields.io/github/v/release/ricab/scope_guard?include_prereleases)](https://github.com/ricab/scope_guard/releases)\n[![Vcpkg](https://img.shields.io/vcpkg/v/scope-guard)](https://vcpkg.link/ports/scope-guard)\n[![semver](https://img.shields.io/badge/semver-2.0.0-blue.svg)](https://semver.org/spec/v2.0.0.html)\n[![GitHub license](https://img.shields.io/github/license/ricab/scope_guard.svg)](https://github.com/ricab/scope_guard/blob/main/LICENSE)\n\n[![GitHub stars](https://img.shields.io/github/stars/ricab/scope_guard.svg?style=social\u0026label=Stars)](https://github.com/ricab/scope_guard)\n\nA public, general, simple, and fast C++11 scope guard that\ndefends against implicitly ignored returns and optionally enforces `noexcept`\nat compile time (in C++17), all in a SFINAE-friendly maner.\n\n##### TLDR\n\nGet it [here](scope_guard.hpp).\nUsage is simple:\n\n```c++\n#include \"scope_guard.hpp\"\n...\n{\n  ...\n  auto guard = sg::make_scope_guard(my_callback);\n  ...\n} // my_callback is invoked at this point\n```\n\n## Introduction\n\nA scope guard is an object that employs RAII to execute a\nprovided callback when leaving scope, be it through a _fall-through_, a return,\nor an exception. That callback can be a function, a function pointer, a functor,\na lambda, a bind result, a std::function, a reference to any of these, or any\nother callable, as long as it respects a few [preconditions](docs/precond.md)\n\u0026ndash; most of which are enforced during compilation, the rest being hopefully\nintuitive.\n\nAll necessary code is provided in a [single header](scope_guard.hpp) (the\nremaining files are only for testing and documentation).\n\n#### Acknowledgments\n\nThe concept of \"scope guard\" was [proposed](http://drdobbs.com/184403758)\nby Andrei Alexandrescu and Petru Marginean and it is well known in the\nC++ community. It has been proposed for standardization (see\n[N4189](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4189.pdf))\nbut is still not part of the standard library, as of March 2018.\n\n#### Why\n\nWhile there are several implementations available, I did not find any with all\nthe characteristics I aimed for here - safe, tested, documented, public domain, thin wrapping, general, standalone, simple interface... (see feature list below).\n\n## Features\n\n#### Main features\n- [x] \u0026ge; C++11\n- [x] Reduced interface\n- [x] Thin callback wrapping: no added `std::function` or virtual table\npenalties\n- [x] General: accepts any callable that respects a few\n[preconditions](docs/precond.md)\n- [x] No implicitly ignored return (details [here](docs/precond.md#void-return))\n- [x] Option to enforce `noexcept` in C++17\n(details [here](docs/interface.md#compilation-option-sg_require_noexcept_in_cpp17))\n- [x] Modern exception specifications (`noexcept` with conditions when\nnecessary)\n- [x] SFINAE friendliness (see [here](docs/design.md#sfinae-friendliness))\n\n#### Other characteristics\n- [x] No dependencies to use (besides \u0026ge;C++11 compiler and standard library)\n- [x] No macros to make guard \u0026ndash; just write explicit lambda or bind or\nwhat have you\n- [x] Extensively tested, with both\n[compile time tests](compile_time_tests.cpp) and\n[runtime-tests](catch_tests.cpp)\n- [x] Carefully documented (adhering to\n[RFC2119](https://tools.ietf.org/html/rfc2119))\n- [x] Standalone header that can be directly dumped into any project\n- [x] Unlicense'd\n- [x] `snake_case` style\n\n#### Notes\n\n\u003csup\u003e_The key words \"MUST\", \"MUST NOT\", \"REQUIRED\", \"SHALL\", \"SHALL\nNOT\", \"SHOULD\", \"SHOULD NOT\", \"RECOMMENDED\",  \"MAY\", and \"OPTIONAL\" in this\ndocument are to be interpreted as described in RFC 2119._\u003c/sup\u003e\n\n#### Issues\n\nBug reports and suggestions are welcome. If you find that something is incorrect\nor could be improved, feel free to open an issue.\n\n## Setup\n\nSetup consists merely of making the [header file](scope_guard.hpp) available to\nthe compiler. That can be achieved by any of the following options:\n\n- placing it directly in the client project's include path\n- placing it in a central include path that is known to the compiler\n- placing it in an arbitrary path and configuring the compiler to include that\npath\n\nThe preprocessor definition `SG_REQUIRE_NOEXCEPT_IN_CPP17` MAY be provided\nto the compiler. The effect of this option is explained\n[here](docs/interface.md#compilation-option-sg_require_noexcept_in_cpp17).\n\n## Further documentation\n\n#### Client interface\n\nThe client interface is documented in detail [here](docs/interface.md).\n\n#### Preconditions in detail\n\nCallback preconditions are explained [here](docs/precond.md).\n\n#### Design choices and concepts\n\nDesign choices and concepts are discussed [here](docs/design.md).\n\n#### Tests\n\nInstructions on how to run the tests are [here](docs/tests.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fricab%2Fscope_guard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fricab%2Fscope_guard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fricab%2Fscope_guard/lists"}