Move semantics in Eigen

后端 未结 1 1632
有刺的猬
有刺的猬 2020-12-19 08:08

I have couple of question about Eigen:

  1. Does anyone know if there is any plan to support move semantics in Eigen anytime soon? Couldn\'t find anything on the

相关标签:
1条回答
  • 2020-12-19 08:43

    Copy elision will do the job just fine. Even a C++03 compiler will elide the temporary.
    In particular, NRVO (named return value optimization) will, for this code,

    MatrixXd foo()
    {
        MatrixXd huge_matrix(N,N);
        return huge_matrix; 
    }
    
    MatrixXd A = foo();
    

    construct huge_matrix right inside A. The C++03 standard specifies in [class.copy]/15:

    This elision of copy operations is permitted in the following circumstances (which may be combined to eliminate multiple copies):

    • in a return statement in a function with a class return type, when the expression is the name of a non-volatile automatic object with the same cv-unqualified type as the function return type, the copy operation can be omitted by constructing the automatic object directly into the function’s return value
    • when a temporary class object that has not been bound to a reference (12.2) would be copied to a class object with the same cv-unqualified type, the copy operation can be omitted by constructing the temporary object directly into the target of the omitted copy
    0 讨论(0)
提交回复
热议问题