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
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>)
30 {
31 TInitializeOnCopy() : 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}
A type wrapper around a default initializeable object which may not be copyable but which needs to be...
TInitializeOnCopy(TInitializeOnCopy &&) noexcept
auto operator=(TInitializeOnCopy &&other) noexcept -> TInitializeOnCopy &
auto operator=(TInitializeOnCopy const &) -> TInitializeOnCopy &
TInitializeOnCopy(TInitializeOnCopy const &)