1#ifndef HALCHECK_LIB_SCOPE_HPP
2#define HALCHECK_LIB_SCOPE_HPP
10#include <halcheck/lib/functional.hpp>
11#include <halcheck/lib/optional.hpp>
12#include <halcheck/lib/type_traits.hpp>
13#include <halcheck/lib/utility.hpp>
18namespace halcheck {
namespace lib {
25template<
typename F = lib::move_only_function<
void() &&>>
67 template<typename G, HALCHECK_REQUIRE(std::is_convertible<G, F>())>
69 : _func(
std::move(other._func)) {
112 finally_t<combine<G>> make_combined(finally_t<G> &&other) && {
113 if (!_func && !other._func)
114 return finally_t<combine<G>>();
116 combine<G> func{std::move(_func), std::move(other._func)};
119 return finally_t<combine<G>>(std::move(func));
134 return std::move(lhs).make_combined(std::move(rhs));
156template<typename F, HALCHECK_REQUIRE(lib::is_invocable<F>())>
constexpr finally_t(F func) noexcept(std::is_nothrow_move_constructible< F >())
Construct an object that calls the given function upon destruction.
Definition scope.hpp:47
finally_t(finally_t &&other) noexcept(std::is_nothrow_move_constructible< F >())
Delays the invocation of a finally_t's underlying function by transfering the responsibility of calli...
Definition scope.hpp:58
friend finally_t< combine< G > > operator+(finally_t &&lhs, finally_t< G > &&rhs)
Combines two finally_t values into one, such that both underlying functions are called upon destructi...
Definition scope.hpp:133
finally_t(finally_t< G > &&other) noexcept(std::is_constructible< F, G >())
Delays the invocation of a finally_t's underlying function by transfering the responsibility of calli...
Definition scope.hpp:68
Calls a function upon destruction.
Definition scope.hpp:26
constexpr finally_t()=default
A default-constructed finally_t does nothing upon scope exit.
~finally_t() noexcept
Invokes the underlying function.
Definition scope.hpp:92
An implementation of std::optional.
Definition optional.hpp:338
HALCHECK_INLINE_CONSTEXPR struct halcheck::lib::@20 invoke
An implementation of std::invoke.
#define HALCHECK_REQUIRE(...)
Expands to a template argument that is only valid if the given argument evaluates to true.
Definition type_traits.hpp:24
static constexpr in_place_t in_place
An implementation of std::in_place.
Definition utility.hpp:33
An implementation of std::is_invocable.
Definition invoke.hpp:66