“This exists to avoid a Visual Studio bug where using a cast to forward an rvalue reference array argument to a pointer parameter will cause bad code generation. Wrapping the cast in a function causes the correct code to be generated.”
The part which I don’t understand is “cast to forward an rvalue reference array argument to a pointer parameter”.
In C++, both StaticCast and static_cast are used to perform a static cast, which is a type of casting that allows you to convert a variable from one type to another at compile time. However, they are used in slightly different contexts.
static_cast is a C++ keyword that is used to perform a static cast. It can be used to convert between built-in data types (such as int to float), pointer types, and class-based types (such as a base class pointer to a derived class pointer). It is a standard C++ operator and is recognized by most C++ compilers.
On the other hand, StaticCast is a function template defined by the Unreal Engine that is used to perform a static cast. It is a wrapper around the C++ static_cast keyword and is used in Unreal Engine code to ensure that the static cast is being performed on the correct types. It also provides some additional error checking to ensure that the cast is safe and that the types being cast are compatible.
But what I want to know is not the uses of StaticCast.
I want to know why use it and the reason is written in comment by Unreal.
“This exists to avoid a Visual Studio bug where using a cast to forward an rvalue reference array argument to a pointer parameter will cause bad code generation. Wrapping the cast in a function causes the correct code to be generated.”
Hard to say, beacuse we don’t know bug-id or if it still exists.
At first glance, if you don’t operate on C-style arrays (especially by passing it to template functions), you can safely use the built-in static_cast.