将默认Eigen :: aligned_allocator用于包含固定大小Eigen类型的结构是否危险?

时间:2018-07-28 19:26:35

标签: eigen eigen3

我在网站上发现了一些解决该问题的问题,但似乎没有一个直接做到这一点。一个示例是this,但是答案并不令人满意(未经测试,也无法解释为什么这样正确)。

考虑以下简单示例:

class some_class
{
   public:
     Eigen::Matrix<double,3,4> M;
     std::vector<Eigen::Matrix<double,4,2>,
       Eigen::aligned_allocator<Eigen::Matrix<double,4,2>>> M2;

   //other stuff
};

现在假设我需要声明std::vector个对象中的一个some_class。然后,是声明

std::vector<some_class,Eigen::aligned_allocator<some_class>>>
//Note that it compiles and doesn't seem to cause noticeable run-time problems either

这样做的正确方法,还是我必须为该类重新实现aligned_allocator?我发现documentation有点简短和混乱,因为它仅说明

  

在固定大小的矢量化本征类型上使用STL容器,或具有此类类型成员的类需要...

但没有明确说明在这种情况下是否应该写aligned_allocator

上面的声明是否安全,为什么?

0 个答案:

没有答案
相关问题