79118595

Date: 2024-10-23 15:26:53
Score: 1
Natty:
Report link

The &tmp { }; is used to work around a limitation in C++. I don't know about whether it's needed in C#

The Join function is accepting an arbitrary number of arguments of type T however the compiler cannot know the types of the arguments at compile time, so it needs to use some kind of hack to work around this. One way is by using a lambda function with an empty body and no parameters (that &tmp { }; line). Because the compiler can see that the lambda function has a side effect (it modifies oss by appending values to it), it won't optimize it away. By using this hack, the compiler can treat tmp as an array of values of type T, even though it's actually just a pack expansion (the ...) of the arguments. This allows use the << operator to append each value to the string, which is not possible otherwise. From your program point of view, yes it appears to have no effect.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: user2793489