DGtal 1.3.0
Loading...
Searching...
No Matches
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
50namespace DGtal
51{
52
54// generic classes for operations in STL containers
55// that cannot be performed with a reverse_iterator type
56
58
76 //default (iterator type)
77 template <typename Container, typename Iterator>
79 {
80 static Iterator erase(Container& aContainer,Iterator& anIterator)
81 {
82 return aContainer.erase(anIterator);
83 }
84
85 static Iterator insert(Container& aContainer,Iterator& anIterator)
86 {
87 return aContainer.insert(anIterator);
88 }
89
90 };
91
92 //specialisation for reverse_iterator type
93 template <typename Container>
95 Container,
96 std::reverse_iterator<typename Container::iterator> >
97 {
98 typedef typename Container::iterator Iterator;
99 typedef std::reverse_iterator<typename Container::iterator> ReverseIterator;
100
102 Container& aContainer,
103 ReverseIterator& anIterator)
104 {
105 //base iterator pointing to the same element
106 Iterator base = (++anIterator).base();
107 //base iterator pointing to the element that
108 //followed the erased element
109 base = aContainer.erase(base);
110 //reverse iterator pointing to the element that
111 //preceded the erased element
112 return ReverseIterator(base);
113 }
114
116 Container& aContainer,
117 ReverseIterator& anIterator,
118 const typename Container::value_type& aValue)
119 {
120 Iterator base = aContainer.insert(anIterator.base(), aValue);
121 return ReverseIterator(base);
122 }
123 };
124
125} // namespace DGtal
126
127// //
129
130#endif // !defined OpInSTLContainers_h
131
132#undef OpInSTLContainers_RECURSES
133#endif // else defined(OpInSTLContainers_RECURSES)
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
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)