UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
OpenWrapper.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "AutoRTFM.h"
6#include <utility>
7
8namespace AutoRTFM
9{
10
11// An object wrapper that will ensure the copy constructor, move constructor,
12// copy assignment, move assignment and destructor are all called in the open.
13// This can be used to wrap a lambda capture if it is known that it safe and
14// more optimal to copy, move & destruct the object in the open.
15//
16// For example - it may be safe to wrap a shared pointer with a TOpenWrapper
17// when capturing for use by AutoRTFM::OnCommit() or AutoRTFM::OnAbort(), as
18// the AutoRTFM::TTask destructor will be called regardless of a transactional
19// failure or commit. This may be preferable to capturing the unwrapped shared
20// pointer as we can avoid costly closed transactional logic to ensure the
21// count is restored on failure:
22// AutoRTFM::OnCommit([WrappedSharedPtr = AutoRTFM::TOpenWrapper{MySharedPtr}]
23// {
24// WrappedSharedPtr.Object->DoSomething();
25// });
26template<typename ObjectType>
28{
29public:
30 ObjectType Object;
31
32 TOpenWrapper(const TOpenWrapper&) = default;
36 TOpenWrapper(const ObjectType& Value) : Object{Value} {}
37 TOpenWrapper(ObjectType&& Value) : Object{std::move(Value)} {}
38 ~TOpenWrapper() = default;
39};
40
41}
#define AUTORTFM_OPEN
Definition AutoRTFMDefines.h:122
Definition OpenWrapper.h:28
TOpenWrapper(TOpenWrapper &&)=default
TOpenWrapper(const TOpenWrapper &)=default
TOpenWrapper & operator=(const TOpenWrapper &)=default
TOpenWrapper & operator=(TOpenWrapper &&)=default
ObjectType Object
Definition OpenWrapper.h:30
TOpenWrapper(const ObjectType &Value)
Definition OpenWrapper.h:36
TOpenWrapper(ObjectType &&Value)
Definition OpenWrapper.h:37
Definition API.cpp:57