File indexing completed on 2024-11-10 04:41:03

0001 /*
0002     SPDX-FileCopyrightText: 2019 Daniel Vrátil <dvratil@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <functional>
0010 #include <type_traits>
0011 
0012 namespace Akonadi
0013 {
0014 class AkScopeGuard
0015 {
0016 public:
0017     template<typename U>
0018     AkScopeGuard(U &&fun)
0019         : mFun(std::move(fun))
0020     {
0021     }
0022 
0023     AkScopeGuard(const AkScopeGuard &) = delete;
0024     AkScopeGuard(AkScopeGuard &&) = default;
0025     AkScopeGuard &operator=(const AkScopeGuard &) = delete;
0026     AkScopeGuard &operator=(AkScopeGuard &&) = delete;
0027 
0028     ~AkScopeGuard()
0029     {
0030         mFun();
0031     }
0032 
0033 private:
0034     std::function<void()> mFun;
0035 };
0036 
0037 } // namespace Akonadi