libosmscout 1.1.1
Loading...
Searching...
No Matches
ScopeGuard.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_SCOPEGUARD_H
2#define OSMSCOUT_SCOPEGUARD_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2021 Lukas Karas
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
23namespace osmscout {
24
38template <typename CB>
40{
41private:
42 CB cb;
43 static_assert(std::is_nothrow_invocable_v<CB>, "Callback must be a nothrow (noexcept) callable");
44public:
45 explicit ScopeGuard(CB cb) noexcept(noexcept(std::move(cb))): cb{std::move(cb)}
46 {}
47
48 ScopeGuard(const ScopeGuard &) = delete;
49 ScopeGuard(ScopeGuard && other) = delete;
50 ScopeGuard& operator=(const ScopeGuard&) = delete;
52
53 ~ScopeGuard() noexcept {
54 cb();
55 }
56};
57}
58
59#endif // OSMSCOUT_SCOPEGUARD_H
ScopeGuard & operator=(const ScopeGuard &)=delete
ScopeGuard & operator=(ScopeGuard &&)=delete
ScopeGuard(CB cb) noexcept(noexcept(std::move(cb)))
Definition ScopeGuard.h:45
ScopeGuard(ScopeGuard &&other)=delete
ScopeGuard(const ScopeGuard &)=delete
~ScopeGuard() noexcept
Definition ScopeGuard.h:53
Definition Area.h:39
STL namespace.