Reputation: 197
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?
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?typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> sensorContainer;
Upvotes: 0
Views: 181
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 sensorContainer
s 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