blob: 799d0e77f095b962189492f5a48e6b64c3a0b8e7 [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001
Jeff Thompson3d613fd2013-10-15 15:39:04 -07002#ifndef NDNBOOST_MPL_AUX_VECTOR_ITERATOR_HPP_INCLUDED
3#define NDNBOOST_MPL_AUX_VECTOR_ITERATOR_HPP_INCLUDED
Jeff Thompsona28eed82013-08-22 16:21:10 -07004
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// $Id: iterator.hpp 49267 2008-10-11 06:19:02Z agurtovoy $
14// $Date: 2008-10-10 23:19:02 -0700 (Fri, 10 Oct 2008) $
15// $Revision: 49267 $
16
17#include <ndnboost/mpl/vector/aux_/at.hpp>
18#include <ndnboost/mpl/iterator_tags.hpp>
19#include <ndnboost/mpl/plus.hpp>
20#include <ndnboost/mpl/minus.hpp>
21#include <ndnboost/mpl/advance_fwd.hpp>
22#include <ndnboost/mpl/distance_fwd.hpp>
23#include <ndnboost/mpl/next.hpp>
24#include <ndnboost/mpl/prior.hpp>
25#include <ndnboost/mpl/aux_/nttp_decl.hpp>
26#include <ndnboost/mpl/aux_/value_wknd.hpp>
27#include <ndnboost/mpl/aux_/config/ctps.hpp>
28#include <ndnboost/mpl/aux_/config/workaround.hpp>
29
30namespace ndnboost { namespace mpl {
31
32template<
33 typename Vector
Jeff Thompson3d613fd2013-10-15 15:39:04 -070034 , NDNBOOST_MPL_AUX_NTTP_DECL(long, n_)
Jeff Thompsona28eed82013-08-22 16:21:10 -070035 >
36struct v_iter
37{
38 typedef aux::v_iter_tag tag;
39 typedef random_access_iterator_tag category;
40 typedef typename v_at<Vector,n_>::type type;
41
42 typedef Vector vector_;
43 typedef mpl::long_<n_> pos;
44
Jeff Thompson3d613fd2013-10-15 15:39:04 -070045#if defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
Jeff Thompsona28eed82013-08-22 16:21:10 -070046 enum {
47 next_ = n_ + 1
48 , prior_ = n_ - 1
49 , pos_ = n_
50 };
51
52 typedef v_iter<Vector,next_> next;
53 typedef v_iter<Vector,prior_> prior;
54#endif
55
56};
57
58
Jeff Thompson3d613fd2013-10-15 15:39:04 -070059#if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
Jeff Thompsona28eed82013-08-22 16:21:10 -070060
61template<
62 typename Vector
Jeff Thompson3d613fd2013-10-15 15:39:04 -070063 , NDNBOOST_MPL_AUX_NTTP_DECL(long, n_)
Jeff Thompsona28eed82013-08-22 16:21:10 -070064 >
65struct next< v_iter<Vector,n_> >
66{
67 typedef v_iter<Vector,(n_ + 1)> type;
68};
69
70template<
71 typename Vector
Jeff Thompson3d613fd2013-10-15 15:39:04 -070072 , NDNBOOST_MPL_AUX_NTTP_DECL(long, n_)
Jeff Thompsona28eed82013-08-22 16:21:10 -070073 >
74struct prior< v_iter<Vector,n_> >
75{
76 typedef v_iter<Vector,(n_ - 1)> type;
77};
78
79template<
80 typename Vector
Jeff Thompson3d613fd2013-10-15 15:39:04 -070081 , NDNBOOST_MPL_AUX_NTTP_DECL(long, n_)
Jeff Thompsona28eed82013-08-22 16:21:10 -070082 , typename Distance
83 >
84struct advance< v_iter<Vector,n_>,Distance>
85{
86 typedef v_iter<
87 Vector
Jeff Thompson3d613fd2013-10-15 15:39:04 -070088 , (n_ + NDNBOOST_MPL_AUX_NESTED_VALUE_WKND(long, Distance))
Jeff Thompsona28eed82013-08-22 16:21:10 -070089 > type;
90};
91
92template<
93 typename Vector
Jeff Thompson3d613fd2013-10-15 15:39:04 -070094 , NDNBOOST_MPL_AUX_NTTP_DECL(long, n_)
95 , NDNBOOST_MPL_AUX_NTTP_DECL(long, m_)
Jeff Thompsona28eed82013-08-22 16:21:10 -070096 >
97struct distance< v_iter<Vector,n_>, v_iter<Vector,m_> >
98 : mpl::long_<(m_ - n_)>
99{
100};
101
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700102#else // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsona28eed82013-08-22 16:21:10 -0700103
104template<> struct advance_impl<aux::v_iter_tag>
105{
106 template< typename Iterator, typename N > struct apply
107 {
108 enum { pos_ = Iterator::pos_, n_ = N::value };
109 typedef v_iter<
110 typename Iterator::vector_
111 , (pos_ + n_)
112 > type;
113 };
114};
115
116template<> struct distance_impl<aux::v_iter_tag>
117{
118 template< typename Iter1, typename Iter2 > struct apply
119 {
120 enum { pos1_ = Iter1::pos_, pos2_ = Iter2::pos_ };
121 typedef long_<( pos2_ - pos1_ )> type;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700122 NDNBOOST_STATIC_CONSTANT(long, value = ( pos2_ - pos1_ ));
Jeff Thompsona28eed82013-08-22 16:21:10 -0700123 };
124};
125
126#endif
127
128}}
129
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700130#endif // NDNBOOST_MPL_AUX_VECTOR_ITERATOR_HPP_INCLUDED