Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/icl/iterator.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 /*-----------------------------------------------------------------------------+ | |
2 Copyright (c) 2009-2009: Joachim Faulhaber | |
3 +------------------------------------------------------------------------------+ | |
4 Distributed under the Boost Software License, Version 1.0. | |
5 (See accompanying file LICENCE.txt or copy at | |
6 http://www.boost.org/LICENSE_1_0.txt) | |
7 +-----------------------------------------------------------------------------*/ | |
8 #ifndef BOOST_ICL_ITERATOR_HPP_JOFA_091003 | |
9 #define BOOST_ICL_ITERATOR_HPP_JOFA_091003 | |
10 | |
11 #include <iterator> | |
12 #include <boost/config/warning_disable.hpp> | |
13 | |
14 namespace boost{namespace icl | |
15 { | |
16 | |
17 /** \brief Performes an addition using a container's memberfunction add, when operator= is called. */ | |
18 template<class ContainerT> class add_iterator | |
19 : public std::iterator<std::output_iterator_tag, void, void, void, void> | |
20 { | |
21 public: | |
22 /// The container's type. | |
23 typedef ContainerT container_type; | |
24 typedef std::output_iterator_tag iterator_category; | |
25 | |
26 /** An add_iterator is constructed with a container and a position | |
27 that has to be maintained. */ | |
28 add_iterator(ContainerT& cont, typename ContainerT::iterator iter) | |
29 : _cont(&cont), _iter(iter) {} | |
30 | |
31 /** This assignment operator adds the \c value before the current position. | |
32 It maintains it's position by incrementing after addition. */ | |
33 add_iterator& operator=(typename ContainerT::const_reference value) | |
34 { | |
35 _iter = icl::add(*_cont, _iter, value); | |
36 if(_iter != _cont->end()) | |
37 ++_iter; | |
38 return *this; | |
39 } | |
40 | |
41 add_iterator& operator*() { return *this; } | |
42 add_iterator& operator++() { return *this; } | |
43 add_iterator& operator++(int){ return *this; } | |
44 | |
45 private: | |
46 ContainerT* _cont; | |
47 typename ContainerT::iterator _iter; | |
48 }; | |
49 | |
50 | |
51 /** Function adder creates and initializes an add_iterator */ | |
52 template<class ContainerT, typename IteratorT> | |
53 inline add_iterator<ContainerT> adder(ContainerT& cont, IteratorT iter_) | |
54 { | |
55 return add_iterator<ContainerT>(cont, typename ContainerT::iterator(iter_)); | |
56 } | |
57 | |
58 /** \brief Performes an insertion using a container's memberfunction add, when operator= is called. */ | |
59 template<class ContainerT> class insert_iterator | |
60 : public std::iterator<std::output_iterator_tag, void, void, void, void> | |
61 { | |
62 public: | |
63 /// The container's type. | |
64 typedef ContainerT container_type; | |
65 typedef std::output_iterator_tag iterator_category; | |
66 | |
67 /** An insert_iterator is constructed with a container and a position | |
68 that has to be maintained. */ | |
69 insert_iterator(ContainerT& cont, typename ContainerT::iterator iter) | |
70 : _cont(&cont), _iter(iter) {} | |
71 | |
72 /** This assignment operator adds the \c value before the current position. | |
73 It maintains it's position by incrementing after addition. */ | |
74 insert_iterator& operator=(typename ContainerT::const_reference value) | |
75 { | |
76 _iter = _cont->insert(_iter, value); | |
77 if(_iter != _cont->end()) | |
78 ++_iter; | |
79 return *this; | |
80 } | |
81 | |
82 insert_iterator& operator*() { return *this; } | |
83 insert_iterator& operator++() { return *this; } | |
84 insert_iterator& operator++(int){ return *this; } | |
85 | |
86 private: | |
87 ContainerT* _cont; | |
88 typename ContainerT::iterator _iter; | |
89 }; | |
90 | |
91 | |
92 /** Function inserter creates and initializes an insert_iterator */ | |
93 template<class ContainerT, typename IteratorT> | |
94 inline insert_iterator<ContainerT> inserter(ContainerT& cont, IteratorT iter_) | |
95 { | |
96 return insert_iterator<ContainerT>(cont, typename ContainerT::iterator(iter_)); | |
97 } | |
98 | |
99 }} // namespace icl boost | |
100 | |
101 #endif // BOOST_ICL_ITERATOR_HPP_JOFA_091003 | |
102 | |
103 |