How to use Move(T& A, typename TMoveSupport::Move B)?

I’m getting a warning in clang 7 about a value being copied when a move could be used to avoid a copy constructor call. I managed to get the code to compile using C style casting, but believe using the Move template provided would be ideal.

C Style implementation:

typedef FStringOutputDevice &FStringOutputDeviceRef;
FStringOutputDeviceRef &&Output_ref = Output;
return (FStringOutputDevice&&)Output_ref;

Current attempt at setting up the Move template properly:

TMoveSupportTraits<FStringOutputDevice> OutRef;
OutRef.Move = nullptr; // know this is incorrect
Move<FStringOutputDevice>(Out, OutRef.Move);
return OutRef;

I’ve been getting errors with every way I’ve tried fiddling with OutRef. At this time, OutRef.Move throws an error of .move being inaccessible by way of ..

How am I supposed to setup TMoveSupportTraits to properly use the Move constructor?

I’m pretty sure you just want MoveTemp, which is our version of std::move.

FStringOutputDevice OutRef;
return MoveTemp(OutRef);

I’m guessing that function is returning a different type than FStringOutputDevice? As usually you don’t need to move a return value since the copy should be elided by RVO, but we have seen that warning in cases where a FStringOutputDevice is being returned as an FString.

1 Like

Ended up using.

TMoveSupportTraits<FStringOutputDevice>::Copy OutRef = *Out;
Move<FStringOutputDevice>(Out, OutRef);
return OutRef;

So far the engine seems to be running fine.

It feels like you found a path that you were determined to go down, despite it being in the wrong direction. You should just use MoveTemp.

Yeah, I’ll be switching to MoveTemp. I ended up getting it to compile on clang 7 before I had received your answer. I will be switching all of my changes to MoveTemp.