All Projects → ricab → Scope_guard

ricab / Scope_guard

Licence: unlicense
A modern C++ scope guard that is easy to use but hard to misuse.

Programming Languages

cpp
1120 projects
cpp11
221 projects
cpp17
186 projects
cpp14
131 projects

Projects that are alternatives of or similar to Scope guard

Metro Ui Css
Impressive component library for expressive web development! Build responsive projects on the web with the first front-end component library in Metro Style. And now there are even more opportunities every day!
Stars: ✭ 6,843 (+6236.11%)
Mutual labels:  no-dependencies
Expected Dark
Expected objects for C++11 and later (and later perhaps C++98 )
Stars: ✭ 55 (-49.07%)
Mutual labels:  no-dependencies
Modals
Simple modal dialogue windows
Stars: ✭ 85 (-21.3%)
Mutual labels:  no-dependencies
Humblelogging
HumbleLogging is a lightweight C++ logging framework. It aims to be extendible, easy to understand and as fast as possible.
Stars: ✭ 15 (-86.11%)
Mutual labels:  no-dependencies
Nameof
Nameof operator for modern C++, simply obtain the name of a variable, type, function, macro, and enum
Stars: ✭ 1,017 (+841.67%)
Mutual labels:  no-dependencies
Physunits Ct Cpp11
A small C++11, C++14 header-only library for compile-time dimensional analysis and unit/quantity manipulation and conversion
Stars: ✭ 67 (-37.96%)
Mutual labels:  no-dependencies
Simplog
A simple logger. No dependencies, no special features, just logging.
Stars: ✭ 17 (-84.26%)
Mutual labels:  no-dependencies
Influxdb Cpp
💜 C++ client for InfluxDB.
Stars: ✭ 100 (-7.41%)
Mutual labels:  no-dependencies
Nonstd Lite
Parent of *-lite repositories, a migration path to post-C++11 features for pre-C++11 environments
Stars: ✭ 46 (-57.41%)
Mutual labels:  no-dependencies
Colorjson
Fast Color JSON Marshaller + Pretty Printer for Golang
Stars: ✭ 71 (-34.26%)
Mutual labels:  no-dependencies
Vanilla Emoji Picker
Modern emoji picker. Super light 2kb gzipped, simple and no frameworks 😻
Stars: ✭ 20 (-81.48%)
Mutual labels:  no-dependencies
X Ray
X-Ray is a script that lets users toggle password visibility in forms.
Stars: ✭ 40 (-62.96%)
Mutual labels:  no-dependencies
Printf
Tiny, fast, non-dependent and fully loaded printf implementation for embedded systems. Extensive test suite passing.
Stars: ✭ 1,157 (+971.3%)
Mutual labels:  no-dependencies
Cpp redis
C++11 Lightweight Redis client: async, thread-safe, no dependency, pipelining, multi-platform - NO LONGER MAINTAINED - Please check https://github.com/cpp-redis/cpp_redis
Stars: ✭ 855 (+691.67%)
Mutual labels:  no-dependencies
Ring Span Lite
ring-span lite - A C++yy-like ring_span type for C++98, C++11 and later in a single-file header-only library
Stars: ✭ 90 (-16.67%)
Mutual labels:  no-dependencies
Hed
vim like hex editor
Stars: ✭ 23 (-78.7%)
Mutual labels:  no-dependencies
Alagarr
🦍 Alagarr is a request-response helper library that removes the boilerplate from your Node.js (AWS Lambda) serverless functions and helps make your code portable.
Stars: ✭ 58 (-46.3%)
Mutual labels:  no-dependencies
Minidyndns
A simple DynDNS server with an build in HTTP interface to update IPs
Stars: ✭ 101 (-6.48%)
Mutual labels:  no-dependencies
Right Height
Dynamically set content areas of different lengths to the same height.
Stars: ✭ 91 (-15.74%)
Mutual labels:  no-dependencies
Drop
A small CSS component that turns browser-native <details> elements into dropdown menus.
Stars: ✭ 69 (-36.11%)
Mutual labels:  no-dependencies

scope_guard

Build Status Build status codecov

GitHub release semver GitHub license

GitHub stars

A public, general, simple, and fast C++11 scope guard that defends against implicitly ignored returns and optionally enforces noexcept at compile time (in C++17), all in a SFINAE-friendly maner.

TLDR

Get it here. Usage is simple:

#include "scope_guard.hpp"
...
{
  ...
  auto guard = sg::make_scope_guard(my_callback);
  ...
} // my_callback is invoked at this point

Introduction

A scope guard is an object that employs RAII to execute a provided callback when leaving scope, be it through a fall-through, a return, or an exception. That callback can be a function, a function pointer, a functor, a lambda, a bind result, a std::function, a reference to any of these, or any other callable, as long as it respects a few preconditions – most of which are enforced during compilation, the rest being hopefully intuitive.

All necessary code is provided in a single header (the remaining files are only for testing and documentation).

Acknowledgments

The concept of "scope guard" was proposed by Andrei Alexandrescu and Petru Marginean and it is well known in the C++ community. It has been proposed for standardization (see N4189) but is still not part of the standard library, as of March 2018.

Why

While there are several implementations available, I did not find any with all the characteristics I aimed for here - safe, tested, documented, public domain, thin wrapping, general, standalone, simple interface... (see feature list below).

Features

Main features

  • [x] ≥ C++11
  • [x] Reduced interface
  • [x] Thin callback wrapping: no added std::function or virtual table penalties
  • [x] General: accepts any callable that respects a few preconditions
  • [x] No implicitly ignored return (details here)
  • [x] Option to enforce noexcept in C++17 (details here)
  • [x] Modern exception specifications (noexcept with conditions when necessary)
  • [x] SFINAE friendliness (see here)

Other characteristics

  • [x] No dependencies to use (besides ≥C++11 compiler and standard library)
  • [x] No macros to make guard – just write explicit lambda or bind or what have you
  • [x] Extensively tested, with both compile time tests and runtime-tests
  • [x] Carefully documented (adhering to RFC2119)
  • [x] Standalone header that can be directly dumped into any project
  • [x] Unlicense'd
  • [x] snake_case style

Notes

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

Issues

Bug reports and suggestions are welcome. If you find that something is incorrect or could be improved, feel free to open an issue.

Setup

Setup consists merely of making the header file available to the compiler. That can be achieved by any of the following options:

  • placing it directly in the client project's include path
  • placing it in a central include path that is known to the compiler
  • placing it in an arbitrary path and configuring the compiler to include that path

The preprocessor definition SG_REQUIRE_NOEXCEPT_IN_CPP17 MAY be provided to the compiler. The effect of this option is explained here.

Further documentation

Client interface

The client interface is documented in detail here.

Preconditions in detail

Callback preconditions are explained here.

Design choices and concepts

Design choices and concepts are discussed here.

Tests

Instructions on how to run the tests are here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].