]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/fusion/adapted/boost_array/array_iterator.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / fusion / adapted / boost_array / array_iterator.hpp
1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2005-2006 Dan Marsden
4
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #if !defined(BOOST_FUSION_ARRAY_ITERATOR_26122005_2250)
9 #define BOOST_FUSION_ARRAY_ITERATOR_26122005_2250
10
11 #include <boost/fusion/support/config.hpp>
12 #include <cstddef>
13 #include <boost/config.hpp>
14 #include <boost/mpl/int.hpp>
15 #include <boost/mpl/assert.hpp>
16 #include <boost/mpl/if.hpp>
17 #include <boost/mpl/minus.hpp>
18 #include <boost/type_traits/is_const.hpp>
19 #include <boost/fusion/iterator/iterator_facade.hpp>
20
21 namespace boost { namespace fusion
22 {
23 struct random_access_traversal_tag;
24
25 template <typename Array, int Pos>
26 struct array_iterator
27 : iterator_facade<array_iterator<Array, Pos>, random_access_traversal_tag>
28 {
29 BOOST_MPL_ASSERT_RELATION(Pos, >=, 0);
30 BOOST_MPL_ASSERT_RELATION(Pos, <=, static_cast<int>(Array::static_size));
31
32 typedef mpl::int_<Pos> index;
33 typedef Array array_type;
34
35 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
36 array_iterator(Array& a)
37 : array(a) {}
38
39 Array& array;
40
41 template <typename Iterator>
42 struct value_of
43 {
44 typedef typename Iterator::array_type array_type;
45 typedef typename array_type::value_type type;
46 };
47
48 template <typename Iterator>
49 struct deref
50 {
51 typedef typename Iterator::array_type array_type;
52 typedef typename
53 mpl::if_<
54 is_const<array_type>
55 , typename array_type::const_reference
56 , typename array_type::reference
57 >::type
58 type;
59
60 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
61 static type
62 call(Iterator const & it)
63 {
64 return it.array[Iterator::index::value];
65 }
66 };
67
68 template <typename Iterator, typename N>
69 struct advance
70 {
71 typedef typename Iterator::index index;
72 typedef typename Iterator::array_type array_type;
73 typedef array_iterator<array_type, index::value + N::value> type;
74
75 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
76 static type
77 call(Iterator const& i)
78 {
79 return type(i.array);
80 }
81 };
82
83 template <typename Iterator>
84 struct next : advance<Iterator, mpl::int_<1> > {};
85
86 template <typename Iterator>
87 struct prior : advance<Iterator, mpl::int_<-1> > {};
88
89 template <typename I1, typename I2>
90 struct distance : mpl::minus<typename I2::index, typename I1::index>
91 {
92 typedef typename
93 mpl::minus<
94 typename I2::index, typename I1::index
95 >::type
96 type;
97
98 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
99 static type
100 call(I1 const&, I2 const&)
101 {
102 return type();
103 }
104 };
105
106 private:
107
108 array_iterator<Array, Pos>& operator=(array_iterator<Array, Pos> const&);
109 };
110 }}
111
112 #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
113 namespace std
114 {
115 template <typename Array, int Pos>
116 struct iterator_traits< ::boost::fusion::array_iterator<Array, Pos> >
117 { };
118 }
119 #endif
120
121 #endif