File indexing completed on 2025-01-18 09:38:22
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_ICL_ITERATOR_HPP_JOFA_091003
0009 #define BOOST_ICL_ITERATOR_HPP_JOFA_091003
0010
0011 #include <iterator>
0012
0013 namespace boost{namespace icl
0014 {
0015
0016
0017 template<class ContainerT> class add_iterator
0018 {
0019 public:
0020
0021 typedef ContainerT container_type;
0022 typedef std::output_iterator_tag iterator_category;
0023 typedef void value_type;
0024 typedef void difference_type;
0025 typedef void pointer;
0026 typedef void reference;
0027
0028
0029
0030 add_iterator(ContainerT& cont, typename ContainerT::iterator iter)
0031 : _cont(&cont), _iter(iter) {}
0032
0033
0034
0035 add_iterator& operator=(typename ContainerT::const_reference value)
0036 {
0037 _iter = icl::add(*_cont, _iter, value);
0038 if(_iter != _cont->end())
0039 ++_iter;
0040 return *this;
0041 }
0042
0043 add_iterator& operator*() { return *this; }
0044 add_iterator& operator++() { return *this; }
0045 add_iterator& operator++(int){ return *this; }
0046
0047 private:
0048 ContainerT* _cont;
0049 typename ContainerT::iterator _iter;
0050 };
0051
0052
0053
0054 template<class ContainerT, typename IteratorT>
0055 inline add_iterator<ContainerT> adder(ContainerT& cont, IteratorT iter_)
0056 {
0057 return add_iterator<ContainerT>(cont, typename ContainerT::iterator(iter_));
0058 }
0059
0060
0061 template<class ContainerT> class insert_iterator
0062 {
0063 public:
0064
0065 typedef ContainerT container_type;
0066 typedef std::output_iterator_tag iterator_category;
0067 typedef void value_type;
0068 typedef void difference_type;
0069 typedef void pointer;
0070 typedef void reference;
0071
0072
0073
0074 insert_iterator(ContainerT& cont, typename ContainerT::iterator iter)
0075 : _cont(&cont), _iter(iter) {}
0076
0077
0078
0079 insert_iterator& operator=(typename ContainerT::const_reference value)
0080 {
0081 _iter = _cont->insert(_iter, value);
0082 if(_iter != _cont->end())
0083 ++_iter;
0084 return *this;
0085 }
0086
0087 insert_iterator& operator*() { return *this; }
0088 insert_iterator& operator++() { return *this; }
0089 insert_iterator& operator++(int){ return *this; }
0090
0091 private:
0092 ContainerT* _cont;
0093 typename ContainerT::iterator _iter;
0094 };
0095
0096
0097
0098 template<class ContainerT, typename IteratorT>
0099 inline insert_iterator<ContainerT> inserter(ContainerT& cont, IteratorT iter_)
0100 {
0101 return insert_iterator<ContainerT>(cont, typename ContainerT::iterator(iter_));
0102 }
0103
0104 }}
0105
0106 #endif
0107
0108