mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-12-08 11:08:23 +00:00
30 lines
832 B
C++
30 lines
832 B
C++
//========= Copyright Valve Corporation, All rights reserved. ============//
|
|
//
|
|
// Miscellaneous generic helper templates & macros
|
|
//=============================================================================//
|
|
|
|
#ifndef TIER1_UTIL_MISC_H
|
|
#define TIER1_UTIL_MISC_H
|
|
|
|
#ifdef _WIN32
|
|
#pragma once
|
|
#endif
|
|
|
|
#include <functional>
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// ScopeExitRunner - Generic helper to run a function upon destruction
|
|
//-----------------------------------------------------------------------------
|
|
class ScopeExitRunner
|
|
{
|
|
public:
|
|
ScopeExitRunner( std::function<void()> && func ) : m_func( std::move(func) ) {}
|
|
~ScopeExitRunner() { if ( m_func ) { m_func(); } }
|
|
|
|
void Inhibit() { m_func = nullptr; }
|
|
private:
|
|
std::function<void()> m_func;
|
|
};
|
|
|
|
#endif // TIER1_UTIL_MISC_H
|