Chris@16
|
1
|
Chris@16
|
2 #ifndef BOOST_MPL_AUX_SINGLE_ELEMENT_ITER_HPP_INCLUDED
|
Chris@16
|
3 #define BOOST_MPL_AUX_SINGLE_ELEMENT_ITER_HPP_INCLUDED
|
Chris@16
|
4
|
Chris@16
|
5 // Copyright Aleksey Gurtovoy 2000-2004
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
8 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
9 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
10 //
|
Chris@16
|
11 // See http://www.boost.org/libs/mpl for documentation.
|
Chris@16
|
12
|
Chris@101
|
13 // $Id$
|
Chris@101
|
14 // $Date$
|
Chris@101
|
15 // $Revision$
|
Chris@16
|
16
|
Chris@16
|
17 #include <boost/mpl/iterator_tags.hpp>
|
Chris@16
|
18 #include <boost/mpl/advance_fwd.hpp>
|
Chris@16
|
19 #include <boost/mpl/distance_fwd.hpp>
|
Chris@16
|
20 #include <boost/mpl/next_prior.hpp>
|
Chris@16
|
21 #include <boost/mpl/deref.hpp>
|
Chris@16
|
22 #include <boost/mpl/int.hpp>
|
Chris@16
|
23 #include <boost/mpl/aux_/nttp_decl.hpp>
|
Chris@16
|
24 #include <boost/mpl/aux_/value_wknd.hpp>
|
Chris@16
|
25 #include <boost/mpl/aux_/config/ctps.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 namespace boost { namespace mpl {
|
Chris@16
|
28
|
Chris@16
|
29 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
Chris@16
|
30
|
Chris@16
|
31 namespace aux {
|
Chris@16
|
32
|
Chris@16
|
33 template< typename T, BOOST_MPL_AUX_NTTP_DECL(int, is_last_) >
|
Chris@16
|
34 struct sel_iter;
|
Chris@16
|
35
|
Chris@16
|
36 template< typename T >
|
Chris@16
|
37 struct sel_iter<T,0>
|
Chris@16
|
38 {
|
Chris@16
|
39 typedef random_access_iterator_tag category;
|
Chris@16
|
40 typedef sel_iter<T,1> next;
|
Chris@16
|
41 typedef T type;
|
Chris@16
|
42 };
|
Chris@16
|
43
|
Chris@16
|
44 template< typename T >
|
Chris@16
|
45 struct sel_iter<T,1>
|
Chris@16
|
46 {
|
Chris@16
|
47 typedef random_access_iterator_tag category;
|
Chris@16
|
48 typedef sel_iter<T,0> prior;
|
Chris@16
|
49 };
|
Chris@16
|
50
|
Chris@16
|
51 } // namespace aux
|
Chris@16
|
52
|
Chris@16
|
53 template< typename T, BOOST_MPL_AUX_NTTP_DECL(int, is_last_), typename Distance >
|
Chris@16
|
54 struct advance< aux::sel_iter<T,is_last_>,Distance>
|
Chris@16
|
55 {
|
Chris@16
|
56 typedef aux::sel_iter<
|
Chris@16
|
57 T
|
Chris@16
|
58 , ( is_last_ + BOOST_MPL_AUX_NESTED_VALUE_WKND(int, Distance) )
|
Chris@16
|
59 > type;
|
Chris@16
|
60 };
|
Chris@16
|
61
|
Chris@16
|
62 template<
|
Chris@16
|
63 typename T
|
Chris@16
|
64 , BOOST_MPL_AUX_NTTP_DECL(int, l1)
|
Chris@16
|
65 , BOOST_MPL_AUX_NTTP_DECL(int, l2)
|
Chris@16
|
66 >
|
Chris@16
|
67 struct distance< aux::sel_iter<T,l1>, aux::sel_iter<T,l2> >
|
Chris@16
|
68 : int_<( l2 - l1 )>
|
Chris@16
|
69 {
|
Chris@16
|
70 };
|
Chris@16
|
71
|
Chris@16
|
72 #else
|
Chris@16
|
73
|
Chris@16
|
74 namespace aux {
|
Chris@16
|
75
|
Chris@16
|
76 struct sel_iter_tag;
|
Chris@16
|
77
|
Chris@16
|
78 template< typename T, BOOST_MPL_AUX_NTTP_DECL(int, is_last_) >
|
Chris@16
|
79 struct sel_iter
|
Chris@16
|
80 {
|
Chris@16
|
81 enum { pos_ = is_last_ };
|
Chris@16
|
82 typedef aux::sel_iter_tag tag;
|
Chris@16
|
83 typedef random_access_iterator_tag category;
|
Chris@16
|
84
|
Chris@16
|
85 typedef sel_iter<T,(is_last_ + 1)> next;
|
Chris@16
|
86 typedef sel_iter<T,(is_last_ - 1)> prior;
|
Chris@16
|
87 typedef T type;
|
Chris@16
|
88 };
|
Chris@16
|
89
|
Chris@16
|
90 } // namespace aux
|
Chris@16
|
91
|
Chris@16
|
92 template<> struct advance_impl<aux::sel_iter_tag>
|
Chris@16
|
93 {
|
Chris@16
|
94 template< typename Iterator, typename N > struct apply
|
Chris@16
|
95 {
|
Chris@16
|
96 enum { pos_ = Iterator::pos_, n_ = N::value };
|
Chris@16
|
97 typedef aux::sel_iter<
|
Chris@16
|
98 typename Iterator::type
|
Chris@16
|
99 , (pos_ + n_)
|
Chris@16
|
100 > type;
|
Chris@16
|
101 };
|
Chris@16
|
102 };
|
Chris@16
|
103
|
Chris@16
|
104 template<> struct distance_impl<aux::sel_iter_tag>
|
Chris@16
|
105 {
|
Chris@16
|
106 template< typename Iter1, typename Iter2 > struct apply
|
Chris@16
|
107 {
|
Chris@16
|
108 enum { pos1_ = Iter1::pos_, pos2_ = Iter2::pos_ };
|
Chris@16
|
109 typedef int_<( pos2_ - pos1_ )> type;
|
Chris@16
|
110 BOOST_STATIC_CONSTANT(int, value = ( pos2_ - pos1_ ));
|
Chris@16
|
111 };
|
Chris@16
|
112 };
|
Chris@16
|
113
|
Chris@16
|
114 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
Chris@16
|
115
|
Chris@16
|
116 }}
|
Chris@16
|
117
|
Chris@16
|
118 #endif // BOOST_MPL_AUX_SINGLE_ELEMENT_ITER_HPP_INCLUDED
|