pinocchio  UNKNOWN
aligned-vector.hpp
1 //
2 // Copyright (c) 2016-2017 CNRS
3 //
4 // This file is part of Pinocchio
5 // Pinocchio is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // Pinocchio is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // Pinocchio If not, see
16 // <http://www.gnu.org/licenses/>.
17 
18 #ifndef __se3_container_aligned_vector_hpp__
19 #define __se3_container_aligned_vector_hpp__
20 
21 #include <vector>
22 #include <Eigen/StdVector>
23 
24 namespace se3
25 {
26  namespace container
27  {
33  template<typename T>
34  struct aligned_vector : public std::vector<T, Eigen::aligned_allocator<T> >
35  {
36  typedef ::std::vector<T, Eigen::aligned_allocator<T> > vector_base;
37  typedef T value_type;
38  typedef typename vector_base::allocator_type allocator_type;
39  typedef typename vector_base::size_type size_type;
40  typedef typename vector_base::iterator iterator;
41 
42  explicit aligned_vector(const allocator_type & a = allocator_type()) : vector_base(a) {}
43  template<typename InputIterator>
44  aligned_vector(InputIterator first, InputIterator last, const allocator_type& a = allocator_type())
45  : vector_base(first, last, a) {}
46  aligned_vector(const aligned_vector & c) : vector_base(c) {}
47  explicit aligned_vector(size_type num, const value_type & val = value_type())
48  : vector_base(num, val) {}
49  aligned_vector(iterator start, iterator end) : vector_base(start, end) {}
50  aligned_vector & operator=(const aligned_vector& x)
51  { vector_base::operator=(x); return *this; }
52 
53  vector_base & base() { return *static_cast<vector_base*>(this); }
54  const vector_base & base() const { return *static_cast<const vector_base*>(this); }
55 
56  }; // struct aligned_vector
57 
58  template<class T>
59  bool operator==(const aligned_vector<T>& lhs, const aligned_vector<T>& rhs)
60  {
61  typedef typename aligned_vector<T>::vector_base vector_base;
62  return *static_cast<const vector_base*>(&lhs) == *static_cast<const vector_base*>(&rhs);
63  }
64 
65  } // namespace container
66 
67 } // namespace se3
68 
69 #endif // ifndef __se3_container_aligned_vector_hpp__
Specialization of an std::vector with an aligned allocator. This specialization might be used when th...