The only reason I could see that this might not be supported is the fact initializer lists are from C++11 and there may be issues with some of the compilers UE supports, not having full '11 support yet (MSVC definitely has some issues with C++14 from what I’ve seen, wouldn’t surprise me that they don’t fully do everything from '11 yet either).
That aside though, this would be pretty handy.
Is there somewhere a forum for feature requests akin to the debug forum?
I’d be convenient if the UE4 supplied containers supported initializer lists. In the same way one can initailize an std::vector (or for that mater any other std:: container, such as an unordered_map) as:
std::vector<int> myints = {1, 2, 3};
It would be nice to initialize a TArray as:
TArray<int> myints = {1, 2, 3};
However, it doesn’t support this. Among other things, that tends to drag what should ideally be const data to be non-const as the first apparent alternative is a series of .Add()s into the container. Also, much of the API accepts such containers, and it’s a lot nicer to supply an inline { } list than go through the gyrations of manual construction. It makes for less code.
Good point Twiddle, it is new with C++11, so they might have to wait for some older compilers to age off into obsolescence. I think newer MSVC’s support it (probably >= 2013), but VS2012 still had some major holes in their C++11 support, so it might not, and there are still folks using that version.
I have noticed UE4 uses some c++11 features in the code base, like the override keyword, so they’re at least not avoiding 11 entirely.
I might take a crack at adding this on my local source base, just to TArrays, to see how that goes.
(aside: I fixed my second example above which was meant to say TArray rather than std::vector)