Question

It appears that Eigen::Ref<>, introduced in Eigen 3.2, and std::reference_wrapper<> introduced in C++11 accomplish very similar goals.

Obviously, the Eigen::Ref<> does not introduce a C++11 dependency, as std::reference_wrapper<> does, but what else should be considered? (For me, C++11 dependency is not a concern.)

Here are the references: (so meta, LOL):

Was it helpful?

Solution

They do not cover same usage. std::reference_wrapper is typically used to store references to objects of type T into containers (instead of using pointers). Eigen::Ref can wrap any Eigen's dense object that are similar to T or allocate its own memory to evaluate expressions that cannot be referenced. It is typically used as the argument types of non template functions or to unify Map, Matrix, and sub-matrices.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top