|
|
|||
File indexing completed on 2026-11-25 09:02:36
0001 // This file is part of the ACTS project. 0002 // 0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project 0004 // 0005 // This Source Code Form is subject to the terms of the Mozilla Public 0006 // License, v. 2.0. If a copy of the MPL was not distributed with this 0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/. 0008 0009 #pragma once 0010 0011 #include <concepts> 0012 #include <utility> 0013 0014 namespace Acts::detail { 0015 0016 /// Call a function when the scope is left, by return or by exception. For 0017 /// restoring state that a function changes only temporarily. 0018 /// 0019 /// @tparam function_t A callable without arguments that does not throw 0020 template <std::invocable function_t> 0021 class ScopeExit { 0022 public: 0023 /// Constructor 0024 /// @param function Called on destruction 0025 explicit ScopeExit(function_t function) : m_function(std::move(function)) {} 0026 0027 ~ScopeExit() noexcept { m_function(); } 0028 0029 ScopeExit(const ScopeExit&) = delete; 0030 ScopeExit& operator=(const ScopeExit&) = delete; 0031 ScopeExit(ScopeExit&&) = delete; 0032 ScopeExit& operator=(ScopeExit&&) = delete; 0033 0034 private: 0035 function_t m_function; 0036 }; 0037 0038 } // namespace Acts::detail
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|