📄 iterator.qbk
字号:
[/============================================================================== Copyright (C) 2001-2007 Joel de Guzman, Dan Marsden, Tobias Schwinger Use, modification and distribution is subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)===============================================================================/][section Iterator]Like __mpl__ and __stl__, iterators are a fundamental concept in Fusion.As with __mpl__ and __stl__ iterators describe positions, andprovide access to data within an underlying __sequence__.[heading Header] #include <boost/fusion/iterator.hpp> #include <boost/fusion/include/iterator.hpp>[section Concepts]Fusion iterators are divided into different traversal categories.__forward_iterator__ is the most basic concept. __bidirectional_iterator__is a refinement of __forward_iterator__. __random_access_iterator__ is arefinement of __bidirectional_iterator__.[section Forward Iterator][heading Description]A Forward Iterator traverses a __sequence__ allowing movement in only one direction throughit's elements, one element at a time.[variablelist Notation [[`i`, `j`] [Forward Iterators]] [[`I`, `J`] [Forward Iterator types]] [[`M`] [An __mpl__ integral constant]] [[`N`] [An integral constant]]][heading Expression requirements]A type models Forward Iterator if, in addition to being CopyConstructable,the following expressions are valid:[table [[Expression] [Return type] [Runtime Complexity]] [[`__next__(i)`] [__forward_iterator__] [Constant]] [[`i == j`] [Convertible to bool] [Constant]] [[`i != j`] [Convertible to bool] [Constant]] [[`__advance_c__<N>(i)`] [__forward_iterator__] [Constant]] [[`__advance__<M>(i)`] [__forward_iterator__] [Constant]] [[`__distance__(i, j)`] [`__result_of_distance__<I, J>::type`][Constant]] [[`__deref__(i)`] [`__result_of_deref__<I>::type`] [Constant]] [[`*i`] [`__result_of_deref__<I>::type`] [Constant]]][heading Meta Expressions][table [[Expression] [Compile Time Complexity]] [[`__result_of_next__<I>::type`] [Amortized constant time]] [[`__result_of_equal_to__<I, J>::type`] [Amortized constant time]] [[`__result_of_advance_c__<I, N>::type`] [Linear]] [[`__result_of_advance__<I ,M>::type`] [Linear]] [[`__result_of_distance__<I ,J>::type`] [Linear]] [[`__result_of_deref__<I>::type`] [Amortized constant time]] [[`__result_of_value_of__<I>::type`] [Amortized constant time]]][heading Expression Semantics][table [[Expression] [Semantics]] [[`__next__(i)`] [An iterator to the element following `i`]] [[`i == j`] [Iterator equality comparison]] [[`i != j`] [Iterator inequality comparison]] [[`__advance_c__<N>(i)`] [An iterator n elements after `i` in the sequence]] [[`__advance__<M>(i)`] [Equivalent to `advance_c<M::value>(i)`]] [[`__distance__(i, j)`] [The number of elements between `i` and `j`]] [[`__deref__(i)`] [The element at position`i`]] [[`*i`] [Equivalent to `deref(i)`]]][heading Invariants]The following invariants always hold:* `!(i == j) == (i != j)`* `__next__(i) == __advance_c__<1>(i)`* `__distance__(i, __advance_c__<N>(i)) == N`* Using `__next__` to traverse the sequence will never return to a previously seen position* `__deref__(i)` is equivalent to `*i`* If `i == j` then `*i` is equivalent to `*j`[heading Models]* __std_pair__ iterator* __boost_array__ iterator* __vector__ iterator* __cons__ iterator* __list__ iterator* __set__ iterator* __map__ iterator* __single_view__ iterator* __filter_view__ iterator* __iterator_range__ iterator* __joint_view__ iterator* __transform_view__ iterator* __reverse_view__ iterator[endsect][section Bidirectional Iterator][heading Description]A Bidirectional Iterator traverses a __sequence__ allowing movement in either direction oneelement at a time.[variablelist Notation [[`i`] [A Bidirectional Iterator]] [[`I`] [A Bidirectional Iterator type]] [[`M`] [An __mpl__ integral constant]] [[`N`] [An integral constant]]][heading Refinement of]__forward_iterator__[heading Expression requirements]In addition to the requirements defined in __forward_iterator__,the following expressions must be valid:[table [[Expression] [Return type] [Runtime Complexity]] [[`__next__(i)`] [__bidirectional_iterator__] [Constant]] [[`__prior__(i)`] [__bidirectional_iterator__] [Constant]] [[`__advance_c__<N>(i)`] [__bidirectional_iterator__] [Constant]] [[`__advance__<M>(i)`] [__bidirectional_iterator__] [Constant]]][heading Meta Expressions][table [[Expression] [Compile Time Complexity]] [[`__result_of_prior__<I>::type`] [Amortized constant time]]][heading Expression Semantics]The semantics of an expression are defined only where they differ from, or are not definedin __forward_iterator__[table [[Expression] [Semantics]] [[`__prior__(i)`] [An iterator to the element preceding `i`]]][heading Invariants]In addition to the invariants of __forward_iterator__,the following invariants always hold:* `__prior__(__next__(i)) == i && __prior__(__next__(i)) == __next__(__prior__(i))`* `__prior__(i) == __advance_c__<-1>(i)`* Using `__prior__` to traverse a sequence will never return a previously seen position[heading Models]* __std_pair__ iterator* __boost_array__ iterator* __vector__ iterator* __iterator_range__ (where adapted sequence is a __bidirectional_sequence__)* __transform_view__ (where adapted sequence is a __bidirectional_sequence__)* __reverse_view__[endsect][section Random Access Iterator][heading Description]A Random Access Iterator traverses a __sequence__ moving in either direction,permitting efficient arbitrary distance movements back and forward through thesequence.[variablelist Notation [[`i`, `j`] [Random Access Iterators]] [[`I`, `J`] [Random Access Iterator types]] [[`M`] [An __mpl__ integral constant]] [[`N`] [An integral constant]]][heading Refinement of]__bidirectional_iterator__[heading Expression requirements]In addition to the requirements defined in __bidirectional_iterator__,the following expressions must be valid:[table [[Expression] [Return type] [Runtime Complexity]] [[`__next__(i)`] [__random_access_iterator__] [Constant]] [[`__prior__(i)`] [__random_access_iterator__] [Constant]] [[`__advance_c__<N>(i)`] [__random_access_iterator__] [Constant]] [[`__advance__<M>(i)`] [__random_access_iterator__] [Constant]]][heading Meta Expressions][table [[Expression] [Compile Time Complexity]] [[`__result_of_advance_c__<I, N>::type`] [Amortized constant time]] [[`__result_of_advance__<I, M>::type`] [Amortized constant time]] [[`__result_of_distance__<I ,J>::type`] [Amortized constant time]]][heading Models]* __vector__ iterator* __std_pair__ iterator* __boost_array__ iterator* __iterator_range__ iterator (where adapted sequence is a __random_access_sequence__)* __transform_view__ iterator (where adapted sequence is a __random_access_sequence__)* __reverse_view__ iterator (where adapted sequence is a __random_access_sequence__)[endsect][endsect][section Functions]Fusion provides functions for manipulating iterators, analogous to the similar functionsfrom the __mpl__ library.[section deref][heading Description]Deferences an iterator.[heading Synopsis] template< typename I > typename __result_of_deref__<I>::type deref(I const& i);[table Parameters [[Parameter] [Requirement] [Description]] [[`i`] [Model of __forward_iterator__] [Operation's argument]]][heading Expression Semantics] __deref__(i);[*Return type]: `__result_of_deref__<I>::type`[*Semantics]: Dereferences the iterator `i`.[heading Header] #include <boost/fusion/iterator/deref.hpp> #include <boost/fusion/include/deref.hpp>[heading Example] typedef __vector__<int,int&> vec; int i(0); vec v(1,i); assert(__deref__(__begin__(v)) == 1); assert(__deref__(__next__(__begin__(v))) == 0); assert(&(__deref__(__next__(__begin__(v)))) == &i);[endsect][section next][heading Description]Moves an iterator 1 position forwards.[heading Synopsis] template< typename I > typename __result_of_next__<I>::type next(I const& i);[table Parameters [[Parameter] [Requirement] [Description]] [[`i`] [Model of __forward_iterator__] [Operation's argument]]][heading Expression Semantics] next(i);[*Return type]: A model of the same iterator concept as `i`.[*Semantics]: Returns an iterator to the next element after `i`.[heading Header] #include <boost/fusion/iterator/next.hpp> #include <boost/fusion/include/next.hpp>[heading Example] typedef __vector__<int,int,int> vec; vec v(1,2,3); assert(__deref__(__begin__(v)) == 1); assert(__deref__(__next__(__begin__(v))) == 2); assert(__deref__(__next__(__next__(__begin__(v)))) == 3);[endsect][section prior][heading Description]Moves an iterator 1 position backwards.[heading Synopsis] template< typename I > typename __result_of_prior__<I>::type prior(I const& i);[table Parameters [[Parameter] [Requirement] [Description]] [[`i`] [Model of __bidirectional_iterator__] [Operation's argument]]][heading Expression Semantics] __prior__(i);[*Return type]: A model of the same iterator concept as `i`.[*Semantics]: Returns an iterator to the element prior to `i`.[heading Header] #include <boost/fusion/iterator/prior.hpp> #include <boost/fusion/include/prior.hpp>[heading Example] typedef __vector__<int,int> vec; vec v(1,2); assert(__deref__(__next__(__begin__(v))) == 2); assert(__deref__(__prior__(__next__(__begin__(v)))) == 1);[endsect][section distance][heading Description]Returns the distance between 2 iterators.[heading Synopsis] template< typename I, typename J > typename __result_of_distance__<I, J>::type distance(I const& i, J const& j);[table Parameters [[Parameter] [Requirement] [Description]] [[`i`, `j`] [Models of __forward_iterator__ into the same sequence] [The start and end points of the distance to be measured]]][heading Expression Semantics] __distance__(i,j);[*Return type]: `int`[*Semantics]: Returns the distance between iterators `i` and `j`.[heading Header] #include <boost/fusion/iterator/distance.hpp> #include <boost/fusion/include/distance.hpp>[heading Example] typedef __vector__<int,int,int> vec; vec v(1,2,3); assert(__distance__(__begin__(v), __next__(__next__(__begin__(v)))) == 2);[endsect][section advance][heading Description]Moves an iterator by a specified distance.[heading Synopsis] template< typename I, typename M > typename __result_of_advance__<I, M>::type advance(I const& i);[table Parameters [[Parameter] [Requirement] [Description]] [[`i`] [Model of __forward_iterator__] [Iterator to move relative to]] [[`N`] [An __mpl_integral_constant__] [Number of positions to move]]][heading Expression Semantics] __advance__<M>(i);[*Return type]: A model of the same iterator concept as `i`.[*Semantics]: Returns an iterator to the element `M` positions from `i`. If `i` is a __bidirectional_iterator__ then `M` may be negative.[heading Header] #include <boost/fusion/iterator/advance.hpp> #include <boost/fusion/include/advance.hpp>[heading Example] typedef __vector__<int,int,int> vec; vec v(1,2,3); assert(__deref__(__advance__<mpl::int_<2> >(__begin__(v))) == 3);[endsect][section advance_c][heading Description]Moves an iterator by a specified distance.[heading Synopsis] template< typename I, int N > typename __result_of_advance_c__<I, N>::type advance_c(I const& i);[table Parameters [[Parameter] [Requirement] [Description]] [[`i`] [Model of __forward_iterator__] [Iterator to move relative to]] [[`N`] [Integer constant] [Number of positions to move]]][heading Expression Semantics] __advance_c__<N>(i);[*Return type]: A model of the same iterator concept as `i`.[*Semantics]: Returns an iterator to the element `N` positions from `i`. If `i` is a __bidirectional_iterator__ then `N` may be negative.[heading Header] #include <boost/fusion/iterator/advance.hpp> #include <boost/fusion/include/advance.hpp>[heading Example] typedef __vector__<int,int,int> vec; vec v(1,2,3); assert(__deref__(__advance_c__<2>(__begin__(v))) == 3);[endsect][endsect][section Operator]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -