File indexing completed on 2025-01-18 09:42:06
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_MULTI_INDEX_DETAIL_DUPLICATES_ITERATOR_HPP
0010 #define BOOST_MULTI_INDEX_DETAIL_DUPLICATES_ITERATOR_HPP
0011
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015
0016 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
0017 #include <iterator>
0018
0019 namespace boost{
0020
0021 namespace multi_index{
0022
0023 namespace detail{
0024
0025
0026
0027
0028
0029 template<typename Node,typename Predicate>
0030 class duplicates_iterator
0031 {
0032 public:
0033 typedef typename Node::value_type value_type;
0034 typedef typename Node::difference_type difference_type;
0035 typedef const typename Node::value_type* pointer;
0036 typedef const typename Node::value_type& reference;
0037 typedef std::forward_iterator_tag iterator_category;
0038
0039 duplicates_iterator(Node* node_,Node* end_,Predicate pred_):
0040 node(node_),begin_chunk(0),end(end_),pred(pred_)
0041 {
0042 advance();
0043 }
0044
0045 duplicates_iterator(Node* end_,Predicate pred_):
0046 node(end_),begin_chunk(end_),end(end_),pred(pred_)
0047 {
0048 }
0049
0050 reference operator*()const
0051 {
0052 return node->value();
0053 }
0054
0055 pointer operator->()const
0056 {
0057 return &node->value();
0058 }
0059
0060 duplicates_iterator& operator++()
0061 {
0062 Node::increment(node);
0063 sync();
0064 return *this;
0065 }
0066
0067 duplicates_iterator operator++(int)
0068 {
0069 duplicates_iterator tmp(*this);
0070 ++(*this);
0071 return tmp;
0072 }
0073
0074 Node* get_node()const{return node;}
0075
0076 private:
0077 void sync()
0078 {
0079 if(node!=end&&pred(begin_chunk->value(),node->value()))advance();
0080 }
0081
0082 void advance()
0083 {
0084 for(Node* node2=node;node!=end;node=node2){
0085 Node::increment(node2);
0086 if(node2!=end&&!pred(node->value(),node2->value()))break;
0087 }
0088 begin_chunk=node;
0089 }
0090
0091 Node* node;
0092 Node* begin_chunk;
0093 Node* end;
0094 Predicate pred;
0095 };
0096
0097 template<typename Node,typename Predicate>
0098 bool operator==(
0099 const duplicates_iterator<Node,Predicate>& x,
0100 const duplicates_iterator<Node,Predicate>& y)
0101 {
0102 return x.get_node()==y.get_node();
0103 }
0104
0105 template<typename Node,typename Predicate>
0106 bool operator!=(
0107 const duplicates_iterator<Node,Predicate>& x,
0108 const duplicates_iterator<Node,Predicate>& y)
0109 {
0110 return !(x==y);
0111 }
0112
0113 }
0114
0115 }
0116
0117 }
0118
0119 #endif