x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.21
Tags:
more ▼

asked Jan 05 '19 at 01:47 PM in C++ Programming

avatar image

zerophase
138 8 17 25

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Jan 06 '19 at 10:15 PM

avatar image

Jamie Dale STAFF
7.5k 177 67 305

avatar image zerophase Jan 07 '19 at 01:10 AM

Ended up using.

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

So far the engine seems to be running fine.

avatar image Jamie Dale STAFF Jan 07 '19 at 03:27 PM

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.

avatar image zerophase Jan 07 '19 at 07:27 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question