This bugzilla service is closed. All entries have been migrated to
Bug 988 - Support conversion to/from std::array, std::vector
Summary: Support conversion to/from std::array, std::vector
Alias: None
Product: Eigen
Classification: Unclassified
Component: Interoperability (show other bugs)
Version: 3.4 (development)
Hardware: All All
: Low Feature Request
Assignee: Nobody
Depends on:
Reported: 2015-04-01 20:45 UTC by Ilja Honkonen
Modified: 2019-12-04 14:27 UTC (History)
5 users (show)


Description Ilja Honkonen 2015-04-01 20:45:02 UTC
Would be nice if as many as possible of the following lines worked:

Eigen::Array3d a = std::array<double, 3>{1, 2, 3};

Eigen::Vector3d v = std::array<double, 3>{1, 2, 3};

std::array<double, 3> A1 = Eigen::Array3d{1, 2, 3};

std::array<double, 3> A2 = Eigen::Vector3d{1, 2, 3};

and similarly for (1d) types with run time size and std::vector. I don't mean Eigen::Map but conversion.
Comment 1 Ilja Honkonen 2015-04-01 20:48:42 UTC
And similarly for construction, not sure if constructing an std::array can/should be supported:

Eigen::Array3d a{std::array<double, 3>{1, 2, 3}};

Eigen::Vector3d v{std::array<double, 3>{1, 2, 3}};

//std::array<double, 3> A1{Eigen::Array3d{1, 2, 3}};

//std::array<double, 3> A2{Eigen::Vector3d{1, 2, 3}};
Comment 2 Christoph Hertzberg 2015-04-01 21:15:11 UTC
That's worth considering.
One possible drawback is that this might silently introduce overhead (in contrast to Map).
Also, if we allow implicit conversions, it might hide programming errors.
And we definitely can't support expressions such as (Array3d() + std::array<double,3>()).

Overall, I'd be ok with allowing explicit conversions, but I'd consider the current conversion and Map possibilities good enough.
If you have lots of these conversions, you may want to reconsider how you store data. If you are sure you need these conversions, you can also inherit from Vector3d and provide the corresponding constructors and cast operators.

> [...] not sure if constructing an std::array can/should be supported:
If we allowed automatic conversion to std::array (via implementing operator std::array<Scalar, SizeAtCompileTime>()), constructing a std::array would automatically be possible.
This line is also tries to call a constructor of std::array:
  std::array<double,3> A1 = Array3d{1,2,3};

Also note that we haven't implemented initializer lists yet. So Array3d{1,2,3} only works because Array3d(double, double, double) is implemented.
Comment 3 Gael Guennebaud 2015-04-04 16:52:58 UTC
I'm also rather reluctant in adding implicit conversion, but I would be ok with explicit ctor from std::array to Eigen::Array/Vector.

We could also think about adding implicit conversion to Ref<>?
Comment 4 Nobody 2019-12-04 14:27:14 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance:

Note You need to log in before you can comment on or make changes to this bug.