Add SCOPE_EXIT macro and use it in prefab tests to cleanup assets on test fail

This commit is contained in:
Wojtek Figat
2025-05-30 11:16:17 +02:00
parent b065e6c989
commit 08ed5ae483
3 changed files with 52 additions and 15 deletions

View File

@@ -0,0 +1,36 @@
// Copyright (c) Wojciech Figat. All rights reserved.
#pragma once
#include "Core.h"
template<typename FuncType>
struct ScopeExit
{
explicit ScopeExit(FuncType&& func)
: _func((FuncType&&)func)
{
}
~ScopeExit()
{
_func();
}
private:
FuncType _func;
};
namespace THelpers
{
struct ScopeExitInternal
{
template<typename FuncType>
ScopeExit<FuncType> operator*(FuncType&& func)
{
return ScopeExit<FuncType>((FuncType&&)func);
}
};
}
#define SCOPE_EXIT const auto CONCAT_MACROS(__scopeExit, __LINE__) = THelpers::ScopeExitInternal() * [&]()