This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Win32, std::vector::insert throws a bunch of errors

Tags: None
(comma "," separated)
budric
Registered Member
Posts
2
Karma
0
Hi,
I'm having trouble using std::vector::insert with Eigen. Here's the code that's giving me trouble:

Code: Select all
#include <vector>
#include <Eigen/Dense>
#include <Eigen/StdVector>

int main(int argc, char * argv[])
{
   Eigen::Vector3d temp(0,0,0);
   typedef std::vector<Eigen::Vector3d ,Eigen::aligned_allocator<Eigen::Vector3d> > Vector;
   Vector myVec;
   myVec.insert(myVec.begin(), temp);
}


The error is:
Code: Select all
1>win_main.cpp(46) : error C2666: 'std::vector<_Ty,_Ax>::insert' : 2 overloads have similar conversions
1>        with
1>        [
1>            _Ty=Eigen::internal::workaround_msvc_stl_support<Eigen::Vector3d>,
1>            _Ax=Eigen::aligned_allocator_indirection<Eigen::internal::workaround_msvc_stl_support<Eigen::Vector3d>>
1>        ]
1>        stdvector.h(115): could be 'std::_Vector_iterator<_Ty,_Alloc> std::vector<Eigen::Vector3d,_Ax>::insert(std::_Vector_const_iterator<_Ty,_Alloc>,const Eigen::Matrix<_Scalar,_Rows,_Cols> &)'
1>        with
1>        [
1>            _Ty=Eigen::internal::workaround_msvc_stl_support<Eigen::Vector3d>,
1>            _Alloc=Eigen::aligned_allocator_indirection<Eigen::internal::workaround_msvc_stl_support<Eigen::Vector3d>>,
1>            _Ax=Eigen::aligned_allocator<Eigen::Vector3d>,
1>            _Scalar=double,
1>            _Rows=3,
1>            _Cols=1
1>        ]
1>        c:\program files (x86)\microsoft visual studio 8\vc\include\vector(851): or 'std::_Vector_iterator<_Ty,_Alloc> std::vector<_Ty,_Ax>::insert(std::_Vector_iterator<_Ty,_Alloc>,const _Ty &)'
1>        with
1>        [
1>            _Ty=Eigen::internal::workaround_msvc_stl_support<Eigen::Vector3d>,
1>            _Alloc=Eigen::aligned_allocator_indirection<Eigen::internal::workaround_msvc_stl_support<Eigen::Vector3d>>,
1>            _Ax=Eigen::aligned_allocator_indirection<Eigen::internal::workaround_msvc_stl_support<Eigen::Vector3d>>
1>        ]
1>        while trying to match the argument list '(std::_Vector_iterator<_Ty,_Alloc>, Eigen::Vector3d)'
1>        with
1>        [
1>            _Ty=Eigen::internal::workaround_msvc_stl_support<Eigen::Vector3d>,
1>            _Alloc=Eigen::aligned_allocator_indirection<Eigen::internal::workaround_msvc_stl_support<Eigen::Vector3d>>
1>        ]


So, I don't know is Eigen\StdVector defining its own version insert? I've tried using const_iterator to match that template. No luck.

Any help?
Thanks.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
indeed, in Eigen/src/StlSupport/StdVector.h we have:
Code: Select all
  using vector_base::insert; 
  iterator insert(const_iterator position, const value_type& x)
  { return vector_base::insert(position,x); }
  void insert(const_iterator position, size_type new_size, const value_type& x)
  { vector_base::insert(position, new_size, x); }


and I don't really understand why we had to add these overloads of insert().
Could you try to comment them, and see how it works for you?
budric
Registered Member
Posts
2
Karma
0
I've commented out the insert code, as well as push_back() (just one line above insert code) in Eigen/src/StlSupport/StdVector.h. It appears to work. Here's a little test code:

Code: Select all
   typedef std::vector<Eigen::Vector3d ,Eigen::aligned_allocator<Eigen::Vector3d> > Vector;
   Vector myVec;
   //insert test
   for (int i = 0; i < 10; i++)
   {
      Eigen::Vector3d temp(i,0,0);
      myVec.insert(myVec.begin() + i, temp);      //end
   }
   assert(myVec.size() == 10);
   assert(myVec.front()[0] == 0);
   assert(myVec.back()[0] == 9);

   myVec.insert(myVec.begin(), Eigen::Vector3d(11,0,0));
   assert(myVec.front()[0] == 11);

   myVec.erase(myVec.begin(), myVec.end());
   assert( myVec.empty() );

   //push_back test
   for (int i = 0; i < 10; i++)
   {
      Eigen::Vector3d temp(i,0,0);
      myVec.push_back(temp);      //end
   }
   assert(myVec.size() == 10);
   assert(myVec.front()[0] == 0);
   assert(myVec.back()[0] == 9);


By the way, the original problem only occurs in Win32 builds, Visual Studio. X64 build was just fine for some reason.

I'll let you know if this causes any problems, but I hope this change can make it into the trunk, because I really don't like keeping patches of libraries.

Thanks.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar