UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ScopeExit.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6{
12 template <typename FuncType>
14 {
15 TScopeGuard(TScopeGuard&&) = delete;
16 TScopeGuard(const TScopeGuard&) = delete;
17 TScopeGuard& operator=(TScopeGuard&&) = delete;
18 TScopeGuard& operator=(const TScopeGuard&) = delete;
19
20 public:
21 // Given a lambda, constructs an RAII scope guard.
22 explicit TScopeGuard(FuncType&& InFunc)
23 : Func((FuncType&&)InFunc)
24 {
25 }
26
27 // Causes the lambda to be executed.
29 {
30 Func();
31 }
32
33 private:
34 // The lambda to be executed when this guard goes out of scope.
35 FuncType Func;
36 };
37
39 {
40 template <typename FuncType>
42 {
43 return TScopeGuard<FuncType>((FuncType&&)InFunc);
44 }
45 };
46}
47
48#define UE_PRIVATE_SCOPE_EXIT_JOIN(A, B) UE_PRIVATE_SCOPE_EXIT_JOIN_INNER(A, B)
49#define UE_PRIVATE_SCOPE_EXIT_JOIN_INNER(A, B) A##B
50
51
52
73#define ON_SCOPE_EXIT const auto UE_PRIVATE_SCOPE_EXIT_JOIN(ScopeGuard_, __LINE__) = ::ScopeExitSupport::FScopeGuardSyntaxSupport() + [&]()
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition ScopeExit.h:14
~TScopeGuard()
Definition ScopeExit.h:28
TScopeGuard(FuncType &&InFunc)
Definition ScopeExit.h:22
Definition ScopeExit.h:6
TScopeGuard< FuncType > operator+(FuncType &&InFunc)
Definition ScopeExit.h:41