DGtal  1.2.0
OpInSTLContainers.h
1 
17 #pragma once
18 
35 #if defined(OpInSTLContainers_RECURSES)
36 #error Recursive header files inclusion detected in OpInSTLContainers.h
37 #else // defined(OpInSTLContainers_RECURSES)
39 #define OpInSTLContainers_RECURSES
40 
41 #if !defined OpInSTLContainers_h
43 #define OpInSTLContainers_h
44 
46 // Inclusions
47 #include <list>
49 
50 namespace DGtal
51 {
52 
54 // generic classes for operations in STL containers
55 // that cannot be performed with a reverse_iterator type
56 
58 
74  //default (iterator type)
75  template <typename Container, typename Iterator>
77  {
78  static Iterator erase(Container& aContainer,Iterator& anIterator)
79  {
80  return aContainer.erase(anIterator);
81  }
82 
83  static Iterator insert(Container& aContainer,Iterator& anIterator)
84  {
85  return aContainer.insert(anIterator);
86  }
87 
88  };
89 
90  //specialisation for reverse_iterator type
91  template <typename Container>
93  Container,
94  std::reverse_iterator<typename Container::iterator> >
95  {
96  typedef typename Container::iterator Iterator;
97  typedef std::reverse_iterator<typename Container::iterator> ReverseIterator;
98 
100  Container& aContainer,
101  ReverseIterator& anIterator)
102  {
103  //base iterator pointing to the same element
104  Iterator base = (++anIterator).base();
105  //base iterator pointing to the element that
106  //followed the erased element
107  base = aContainer.erase(base);
108  //reverse iterator pointing to the element that
109  //preceded the erased element
110  return ReverseIterator(base);
111  }
112 
114  Container& aContainer,
115  ReverseIterator& anIterator,
116  const typename Container::value_type& aValue)
117  {
118  Iterator base = aContainer.insert(anIterator.base(), aValue);
119  return ReverseIterator(base);
120  }
121  };
122 
123 } // namespace DGtal
124 
125 // //
127 
128 #endif // !defined OpInSTLContainers_h
129 
130 #undef OpInSTLContainers_RECURSES
131 #endif // else defined(OpInSTLContainers_RECURSES)
DGtal is the top-level namespace which contains all DGtal functions and types.
static ReverseIterator erase(Container &aContainer, ReverseIterator &anIterator)
static ReverseIterator insert(Container &aContainer, ReverseIterator &anIterator, const typename Container::value_type &aValue)
static Iterator insert(Container &aContainer, Iterator &anIterator)
static Iterator erase(Container &aContainer, Iterator &anIterator)