Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
scope_exit.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
6#ifndef INKSCAPE_UTIL_SCOPE_EXIT_H
7#define INKSCAPE_UTIL_SCOPE_EXIT_H
8
9#include <type_traits>
10#include <utility>
11
12// Todo: (C++23?) Replace with now-standardised version.
13template <typename F>
15{
16public:
17 scope_exit(F &&f) : f(std::forward<F>(f)) {}
18 scope_exit(scope_exit const &) = delete;
19 scope_exit &operator=(scope_exit const &) = delete;
20 ~scope_exit() { f(); }
21
22private:
23 std::decay_t<F> f;
24};
25
26#endif // INKSCAPE_UTIL_SCOPE_EXIT_H
std::decay_t< F > f
Definition scope_exit.h:23
scope_exit(F &&f)
Definition scope_exit.h:17
scope_exit & operator=(scope_exit const &)=delete
scope_exit(scope_exit const &)=delete
STL namespace.