MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
InitializeOnCopy.h
Go to the documentation of this file.
1
/** @noop License Comment
2
* @file
3
* @copyright
4
* This Source Code is subject to the terms of the Mozilla Public License, v2.0.
5
* If a copy of the MPL was not distributed with this file You can obtain one at
6
* https://mozilla.org/MPL/2.0/
7
*
8
* @author David Mórász
9
* @date 2025
10
*/
11
12
#pragma once
13
14
#include "CoreMinimal.h"
15
#include "
Mcro/FunctionTraits.h
"
16
17
namespace
Mcro::InitializeOnCopy
18
{
19
using namespace
Mcro::FunctionTraits
;
20
21
/**
22
* @brief
23
* A type wrapper around a default initializeable object which may not be copyable but which needs to be a member
24
* of a copyable class. On each instance of such class the wrapped value may not need to be copied and default
25
* constructing it is enough. Useful for mutexes for example.
26
*/
27
template
<CDefaultInitializable T>
28
requires
(!CCopyable<T>)
29
struct
TInitializeOnCopy
30
{
31
TInitializeOnCopy
() : Value() {}
32
TInitializeOnCopy
(
TInitializeOnCopy
const
&) : Value() {}
33
TInitializeOnCopy
(
TInitializeOnCopy
&&) noexcept : Value() {}
34
auto
operator=
(
TInitializeOnCopy
const
&) ->
TInitializeOnCopy
& {
return
*
this
; }
35
auto
operator=
(
TInitializeOnCopy
&& other)
noexcept
->
TInitializeOnCopy
& {
return
*
this
; }
36
37
TUniqueObj<T>
Value
;
38
39
T* operator -> () {
return
&Value.Get(); }
40
const
T* operator -> ()
const
{
return
&Value.Get(); }
41
42
T&
Get
() {
return
Value.Get(); }
43
const
T&
Get
()
const
{
return
Value.Get(); }
44
45
template
<
typename
Self>
46
operator
typename
TCopyQualifiersFromTo<Self, T&>::Type (
this
Self&& self) {
return
self.Get(); }
47
};
48
}
FunctionTraits.h
Mcro::FunctionTraits
Definition
FunctionTraits.h:22
Mcro::InitializeOnCopy
Definition
InitializeOnCopy.h:18
Mcro::InitializeOnCopy::TInitializeOnCopy
A type wrapper around a default initializeable object which may not be copyable but which needs to be...
Definition
InitializeOnCopy.h:30
Mcro::InitializeOnCopy::TInitializeOnCopy::Get
const T & Get() const
Definition
InitializeOnCopy.h:43
Mcro::InitializeOnCopy::TInitializeOnCopy::TInitializeOnCopy
TInitializeOnCopy(TInitializeOnCopy &&) noexcept
Definition
InitializeOnCopy.h:33
Mcro::InitializeOnCopy::TInitializeOnCopy::operator=
auto operator=(TInitializeOnCopy &&other) noexcept -> TInitializeOnCopy &
Definition
InitializeOnCopy.h:35
Mcro::InitializeOnCopy::TInitializeOnCopy::Get
T & Get()
Definition
InitializeOnCopy.h:42
Mcro::InitializeOnCopy::TInitializeOnCopy::TInitializeOnCopy
TInitializeOnCopy()
Definition
InitializeOnCopy.h:31
Mcro::InitializeOnCopy::TInitializeOnCopy::Value
TUniqueObj< T > Value
Definition
InitializeOnCopy.h:37
Mcro::InitializeOnCopy::TInitializeOnCopy::operator=
auto operator=(TInitializeOnCopy const &) -> TInitializeOnCopy &
Definition
InitializeOnCopy.h:34
Mcro::InitializeOnCopy::TInitializeOnCopy::TInitializeOnCopy
TInitializeOnCopy(TInitializeOnCopy const &)
Definition
InitializeOnCopy.h:32
Mcro_Origin
Public
Mcro
InitializeOnCopy.h
Generated by
1.12.0