3

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):

Daniel Frey
  • 55,810
  • 13
  • 122
  • 180
arr_sea
  • 841
  • 10
  • 16

1 Answers1

4

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.

ggael
  • 28,425
  • 2
  • 65
  • 71
  • I found some more detail on this in the section titled: "How to write generic, but non-templated function?" here: http://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html – arr_sea Oct 29 '13 at 01:40