Is there any way of doing parallel assignment in C++? Currently, the below compiles (with warnings)
#include
int main() {
int a = 4;
Or Perl. But no, it's not possible (as far as I'm aware), you need to use a temporary variable, as in:
int a = 4;
int b = 5;
{
int tmp = a;
a = b;
b = tmp;
}
FYI, internally those languages (or Perl atleast) create a temporary list { a, b }
, then assign the list to the two variables. In other words, this is atleast as performant, if only a little more messy.