Create & add TTuple to container in one step

Hi!
Creating a TTuple in the brackets of a container add method does not compile.
However storing the created tuple in a temporary variable does work.

auto cont = TArray<TTuple<float,int>>();

cont.Add(TTuple<float,int>(1.0f,0));//Does not compile

auto val = TTuple<float,int>(1.0f,0);//Does compile
cont.Add(val);//Does compile

So my question is:
Am I just stupid and there is a way to do that in a single step?
Or might this be a problem with the TTuple implementation?

Thank you very much!

Looks like a bug. It’s gonna be a beauty to try to debug, too!

Hi,

This is because the compiler is trying to instantiate TTuple’s variadic constructor as a move constructor. You’ll notice that the constructor of TFunction has a similar workaround.

I’ve got a local fix for this, which I shall commit after some testing, but I should say that TTuple isn’t quite yet a ‘first class citizen’ of UE4 because it is not supported on all of our compilers. It’s only currently intended as an implementation detail of delegate as implemented by variadic templates. When we no longer support compilers without variadics (which is basically Visual C++ 2012), TTuple will likely become a general utility class usable by anyone, and these kinds of bugs will get ironed out.

Steve

This has now been fixed and the patch is on GitHub here:

https://github.com/EpicGames/UnrealEngine/commit/c53639c36c108d93fd816ed8afdfaa437b400556

I should also add that you could use Emplace to add your tuple to an array, which is both shorter, more efficient and works on TArray today:

cont.Emplace(1.0f,0);

Steve

1 Like

Thank you!
Emplace is really nice! I still have some way to go before I find my way through the UE4 Libs.