1 /* Copyright 2003-2008 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * See http://www.boost.org/libs/multi_index for library home page.
9 #ifndef BOOST_MULTI_INDEX_DETAIL_RND_NODE_ITERATOR_HPP
10 #define BOOST_MULTI_INDEX_DETAIL_RND_NODE_ITERATOR_HPP
12 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
17 #include <boost/operators.hpp>
19 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
20 #include <boost/serialization/nvp.hpp>
21 #include <boost/serialization/split_member.hpp>
26 namespace multi_index
{
30 /* Iterator class for node-based indices with random access iterators. */
32 template<typename Node
>
33 class rnd_node_iterator
:
34 public random_access_iterator_helper
<
35 rnd_node_iterator
<Node
>,
36 typename
Node::value_type
,
38 const typename
Node::value_type
*,
39 const typename
Node::value_type
&>
43 explicit rnd_node_iterator(Node
* node_
):node(node_
){}
45 const typename
Node::value_type
& operator*()const
50 rnd_node_iterator
& operator++()
52 Node::increment(node
);
56 rnd_node_iterator
& operator--()
58 Node::decrement(node
);
62 rnd_node_iterator
& operator+=(std::ptrdiff_t n
)
64 Node::advance(node
,n
);
68 rnd_node_iterator
& operator-=(std::ptrdiff_t n
)
70 Node::advance(node
,-n
);
74 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
75 /* Serialization. As for why the following is public,
76 * see explanation in safe_mode_iterator notes in safe_mode.hpp.
79 BOOST_SERIALIZATION_SPLIT_MEMBER()
81 typedef typename
Node::base_type node_base_type
;
83 template<class Archive
>
84 void save(Archive
& ar
,const unsigned int)const
86 node_base_type
* bnode
=node
;
87 ar
<<serialization::make_nvp("pointer",bnode
);
90 template<class Archive
>
91 void load(Archive
& ar
,const unsigned int)
93 node_base_type
* bnode
;
94 ar
>>serialization::make_nvp("pointer",bnode
);
95 node
=static_cast<Node
*>(bnode
);
99 /* get_node is not to be used by the user */
101 typedef Node node_type
;
103 Node
* get_node()const{return node
;}
109 template<typename Node
>
111 const rnd_node_iterator
<Node
>& x
,
112 const rnd_node_iterator
<Node
>& y
)
114 return x
.get_node()==y
.get_node();
117 template<typename Node
>
119 const rnd_node_iterator
<Node
>& x
,
120 const rnd_node_iterator
<Node
>& y
)
122 return Node::distance(x
.get_node(),y
.get_node())>0;
125 template<typename Node
>
126 std::ptrdiff_t operator-(
127 const rnd_node_iterator
<Node
>& x
,
128 const rnd_node_iterator
<Node
>& y
)
130 return Node::distance(y
.get_node(),x
.get_node());
133 } /* namespace multi_index::detail */
135 } /* namespace multi_index */
137 } /* namespace boost */