[eigen] RE: C++11 Style Initialisation

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi,

just as a note: we currently use a class that derives from Eigen::Matrix<T, N, 1> and we've added such a constructor (for N values) there (using variadic templates + recursion).

One slight snag is the N=1 case, where one needs to take care to distinguish between the (also templated) constructor from an Eigen-_expression_ vs. the single-value case. Easiest for us was to use tag-dispatching for the value constructor, so something like

MyVector foo(ValueConstruct, 1.0);

Maybe one could also go for initializer_lists, but I haven't looked at that...


Best regards

Daniel Vollmer

--------------------------
Deutsches Zentrum für Luft- und Raumfahrt e.V. (DLR)
German Aerospace Center
Institute of Aerodynamics and Flow Technology | Lilienthalplatz 7 | 38108 Braunschweig | Germany

Daniel Vollmer | AS C²A²S²E
www.DLR.de

Von: Wood, Tobias [tobias.wood@xxxxxxxxx]
Gesendet: Dienstag, 15. Januar 2019 12:50
An: eigen@xxxxxxxxxxxxxxxxxxx
Betreff: [eigen] C++11 Style Initialisation

Hello,

 

I would very much like to write expressions like:

 

Eigen::Matrix3f example{1, 2, 3, 4, 5, 6, 7, 8, 9};

 

I have tried searching, but I cannot see a current Bugzilla entry for functionality like this. I found http://eigen.tuxfamily.org/bz/show_bug.cgi?id=954, but that’s slightly different. I can think of several use cases for this, and there are similar StackOverflow questions (https://stackoverflow.com/questions/21280476/uniform-initialization-with-eigen-dynamic-types and https://stackoverflow.com/questions/25159349/is-it-possible-to-initialize-a-const-eigen-matrix)

 

I know that Eigen is committed to supporting C++03. Is it possible to add support for this in unsupported/cxx11? I would be tempted to try adding this myself, but I would need some pointers on where to start.

 

Interestingly,

 

Eigen::Vector3f example2{1, 2, 3};

 

does work, similarly Vector2f and Vector4f, because they have specific constructors that allow you to write

 

Eigen::Vector3f example(1, 2, 3);

 

however, these do not extend to the general case.

 

Best wishes,

Toby



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/