Pack required boost code together.
[xy_vsfilter.git] / src / thirdparty / boost_1_47_0 / boost / multi_index / detail / rnd_node_iterator.hpp
blob4334f653d982160211fb903a843cdd16e1366ea7
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.
7 */
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)
13 #pragma once
14 #endif
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>
22 #endif
24 namespace boost{
26 namespace multi_index{
28 namespace detail{
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,
37 std::ptrdiff_t,
38 const typename Node::value_type*,
39 const typename Node::value_type&>
41 public:
42 rnd_node_iterator(){}
43 explicit rnd_node_iterator(Node* node_):node(node_){}
45 const typename Node::value_type& operator*()const
47 return node->value();
50 rnd_node_iterator& operator++()
52 Node::increment(node);
53 return *this;
56 rnd_node_iterator& operator--()
58 Node::decrement(node);
59 return *this;
62 rnd_node_iterator& operator+=(std::ptrdiff_t n)
64 Node::advance(node,n);
65 return *this;
68 rnd_node_iterator& operator-=(std::ptrdiff_t n)
70 Node::advance(node,-n);
71 return *this;
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);
97 #endif
99 /* get_node is not to be used by the user */
101 typedef Node node_type;
103 Node* get_node()const{return node;}
105 private:
106 Node* node;
109 template<typename Node>
110 bool operator==(
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>
118 bool operator<(
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 */
139 #endif