Open hwelzel opened 7 months ago
I'm not familiar with Eigen.
to()
was standardized from C++23, you can find the mechanism for how it works here. In short, if C
is the destination type and r
is the source range, it'll try to do (in order):
C(r)
C(from_range, r)
C(ranges::begin(r), ranges::end(r))
C c; /* try to reserve */; ranges::copy(r, /* inserter into c */);
It looks like option (4) there might work for Eigen::VectorXd, does it? If so we could try to extend the implementation here to do something similar.
range-v3 right now tries to do
C c; r.reserve(ranges::size(r)); c.assign(ranges::begin(r), ranges::end(r));
C(ranges::begin(r), ranges::end(r))
Thanks for all the info! Indeed option 4 should work with Eigen. Its pretty much what I do in my custom function in the original comment as you noted.
I tried with c++23 std::ranges::to (should've done before) but unfortunately it doesn't compile. https://godbolt.org/z/rsd8bdEKc So I am not sure that in the end it would work with ranges-v3 either. Maybe Eigen would need to do something as well.
Is there a way to collect to an Eigen::VectorXd? If I do...
...I get among other things...
...which is understandable because eigen doesn't have that ctor. Nor does it have an assign(begin, end) for the other overload. I am not even sure Eigen::VectorXd complies to the range concept.
Still, I was wondering if there is a way to hook in a custom container to struct/function overload which would be called to initialise custom containers like eigen. I would need to do something more or less like: