source: NonGTP/Boost/boost/mpl/aux_/single_element_iter.hpp @ 857

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