1

According to the Eigen website, using STL containers on fixed-size vectorizable Eigen types requires the use of an over-aligned allocator. See https://eigen.tuxfamily.org/dox/group__TopicStlContainers.html

Does this apply when creating a tuple of Eigen objects? I haven't seen any code examples that use an allocator with std::tuple.

Below is a concrete example of what I'm trying to do. Is this valid, or am I likely to run into issues with this code?

std::tuple<Eigen::Vector2d, Eigen::Vector2d> foo()
{
    Eigen::Vector2d vec1(1, 2);
    Eigen::Vector2d vec2(3, 4);
    return std::make_tuple(vec1, vec2);
};
supersolver
  • 426
  • 5
  • 14
  • A tuple is not a container, it is the generalization of `std::pair` – NathanOliver Nov 14 '22 at 20:55
  • Is the above code correct then in regards to alignment? – supersolver Nov 14 '22 at 21:04
  • AFAIK you should be fine but I don't use Eigen so I just left a comment instead of answering. – NathanOliver Nov 14 '22 at 21:06
  • [See also](https://stackoverflow.com/questions/10019228/the-future-of-c-alignment-passing-by-value) – Nelfeal Nov 14 '22 at 21:34
  • The easiest solution is to compile your code with C++17 (or later) -- as written in the page you linked to. – chtz Nov 14 '22 at 22:34
  • The culprit, as I understand it, was the loss of alignment in dynamic allocations. containers were simply the most common issues but since it affects every struct with an Eigen member, you could also encounter it in other cases such as ```make_shared``` (fixed with ```allocate_shared```). Since it affects structs, it also affects pairs etc. but only if you ```new```-allocate them – Homer512 Nov 14 '22 at 23:32

0 Answers0