MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Mcro::Construct Namespace Reference

Data Structures

struct  TInitializeOnCopy
 

Functions

template<CFunctorObject Initializer, typename... Args, typename ResultArg = TFunction_Arg<Initializer, 0>, typename Result = std::decay_t<ResultArg>>
requires std::is_lvalue_reference_v<ResultArg>
Result Construct (Initializer &&init, Args &&... args)
 
template<CFunctorObject Initializer, typename... Args, typename ResultArg = TFunction_Arg<Initializer, 0>, typename Result = std::decay_t<ResultArg>>
requires std::is_lvalue_reference_v<ResultArg>
Result * ConstructNew (Initializer &&init, Args &&... args)
 

Function Documentation

◆ Construct()

template<CFunctorObject Initializer, typename... Args, typename ResultArg = TFunction_Arg<Initializer, 0>, typename Result = std::decay_t<ResultArg>>
requires std::is_lvalue_reference_v<ResultArg>
Result Mcro::Construct::Construct ( Initializer && init,
Args &&... args )

Simply makes a new object and allows to initialize it in place with a lambda function. The object type is derived from the first argument of the initializer lambda function. Usage:

using namespace Mcro::Construct;
auto myObject = Construct([](MyObject& _)
{
_.Foo = 42;
_.Initialize();
// etc...
});
static_assert(std::is_same_v<decltype(myObject), MyObject>);
Result Construct(Initializer &&init, Args &&... args)
Definition Construct.h:50
Parameters
initA lambda function with a single l-value reference parameter of the object type to initialize.
args
Returns
A new instance of the object.
Remarks
The C++ 20 designated initializers with named arguments has annoying limitations, therefore this exists

Definition at line 50 of file Construct.h.

◆ ConstructNew()

template<CFunctorObject Initializer, typename... Args, typename ResultArg = TFunction_Arg<Initializer, 0>, typename Result = std::decay_t<ResultArg>>
requires std::is_lvalue_reference_v<ResultArg>
Result * Mcro::Construct::ConstructNew ( Initializer && init,
Args &&... args )

Simply makes a new object on the heap and allows to initialize it in place with a lambda function. The object type is derived from the first argument of the initializer lambda function. Usage:

using namespace Mcro::Construct;
auto myObject = ConstructNew([](MyObject& _)
{
_.Foo = 42;
_.Initialize();
// etc...
});
static_assert(std::is_same_v<decltype(myObject), MyObject*>);
Result * ConstructNew(Initializer &&init, Args &&... args)
Definition Construct.h:86
Parameters
initA lambda function with a single l-value reference parameter of the object type to initialize.
args
Returns
A pointer to the object instance on heap.
Remarks
The C++ 20 designated initializers with named arguments has annoying limitations, therefore this exists

Definition at line 86 of file Construct.h.