Re: [eigen] Value-initializing a Matring |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
Am 19.04.2015 um 00:44 schrieb Matan Nassau:
To be clear, my question stands still whether the code is
struct foo {
foo() : v{} {} // braces
private:
Eigen::Vector2d v();
That would declare (but not implement) a member function named v which
takes no parameters and returns an Eigen::Vector2d. Of course, you can't
initialize a funtion in the constructor.
Assuming this was just a typo, to initialize v by zeros, you currently
need to write:
struct foo {
foo() : v(Eigen::Vector2d::Zero()) {}
private:
Eigen::Vector2d v;
};
or (shorter, but probably slightly harder to optimize for a compiler):
struct foo {
foo() : v(0,0) {}
private:
Eigen::Vector2d v;
};
The latter only works for sizes up to 4. (And for 1d vectors only with
the devel-branch, IIRC).
Both v() and v{} will lead to v not getting initalized.
About your comparisons with std::string and std::vector:
For dynamic vectors (VectorXd), you will already get a vector of
dimension 0 by default (nothing else would make sense here), however
VectorXd a{2};
will call VectorXd a(2) and allocate two (uninitialized) doubles.
VectorXd b{3,1}; // calls VectorXd(Index, Index)
will accidentially work and allocate a 3x1-matrix, i.e. a 3d vector.
VectorXd c{1,2,3};
and more parameters won't compile at the moment.
A better comparision would have been with std::array<double, 2>, but
please check out the bugzilla entry Gael already referred to:
http://eigen.tuxfamily.org/bz/show_bug.cgi?id=954
As Gael already said, we plan to support initializor-list constructors
and -- to put Billy's mind at ease -- there are no plans to give up
C++03-compatibility, so all C++11 features will be activated only if the
compiler supports them.
Christoph
--
----------------------------------------------
Dipl.-Inf., Dipl.-Math. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen
Tel: +49 (421) 218-64252
----------------------------------------------