Emilio7773
Emilio7773

Reputation: 197

Using a Vector-Container of Eigen::Matrices. Why?

I am pretty new to C++ and trying to contribute to an open source project to improve my skills. I have nerver worked with Containers before and noticed the following typedef in the code:

typedef Eigen::Matrix<float, Eigen::Dynamic, 1> sensorMatrix;
template <template <typename, typename> class Container, typename Type>
Container<std::vector, Eigen::aligned_allocator<sensorMatrix>> sensorContainer;

So now I am trying to understand what they are doing here and why?

  1. What is that second line doing? I dont really understand how all these templates define the container?
  2. So with Container<> I am saving a Vector of Eigen::Matrices right? So now I would get a value of the matrix like this: float val = sensorContainer[i](j,k), is that right?
  3. Why do they do that? I just dont understand what the advantages are? Why don they use a multi dimensional matrix. So just something like this: typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> sensorContainer;

Upvotes: 0

Views: 181

Answers (1)

Caleth
Caleth

Reputation: 63392

What is that second line doing?

It is defining a variable template. For each pair of "template of two type arguments" and "type" there is an object named sensorContainer. Note that Type is not used in that variable, so it probably exists to allow multiple sensorContainers that use the same template parameter.

On it's own it does nothing, it needs at least one instantiation of this template.

The snippet you have isn't valid C++, as it is passing a template in the place of a type.

What that does depends on the definition of the template passed as a parameter.

So with Container<> I am saving a Vector of Eigen::Matrices right? So now I would get a value of the matrix like this: float val = sensorContainer[i](j,k), is that right?

We can't tell. You'd have to look at the definitions of any of the templates used, to see what they are.

Why do they do that?

They have more than one way of combining std::vector (a template) with Eigen::aligned_allocator<sensorMatrix> (an allocator type). Notably one of the parameters of std::vector is an allocator for it's element type.

Upvotes: 0

Related Questions