Parallel assignment in C++

前端 未结 6 856
醉酒成梦
醉酒成梦 2021-01-18 13:53

Is there any way of doing parallel assignment in C++? Currently, the below compiles (with warnings)

#include  

int main() { 
  int a = 4;
           


        
6条回答
  •  被撕碎了的回忆
    2021-01-18 14:02

    There is no such function in the Standard Library. You could write a set of template functions :

    template  void ParAssign(T1& Lhs_1, T1 const& Rhs1);
    template  void ParAssign(T1& Lhs1, T2& Lhs2, T1 const& Rhs1, T2 const& Rhs2);
    // etc.
    ParAssign(a,b,
              b,a);
    

    That's non-trivial if there is aliasing, as in your swap example.

提交回复
热议问题