Line data Source code
1 : // SPDX-FileCopyrightText: 2024 Daniel Abele <daniel.abele@dlr.de> 2 : // 3 : // SPDX-License-Identifier: BSD-3-Clause 4 : 5 : #pragma once 6 : 7 : namespace ipc 8 : { 9 : /** 10 : * Run a user-specified function when destroyed. 11 : */ 12 : template<class F> struct ScopeExit 13 : { 14 : F m_f; 15 1 : ScopeExit(F f) : m_f(f) { } 16 1 : ~ScopeExit() { m_f(); } 17 : }; 18 : } // namespace ipc