forked from boostorg/iterator
updated tag mechanism for iterators using Dave's idea
[SVN r612]
This commit is contained in:
@@ -7,8 +7,9 @@
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int x[] = { 1, 2, 3, 4 };
|
int x[] = { 1, 2, 3, 4 };
|
||||||
boost::reverse_iterator<int*, int, int&, int*, std::random_access_iterator_tag, std::ptrdiff_t>
|
boost::reverse_iterator<int*, int, int&, int*,
|
||||||
first(x + 4), last(x);
|
boost::iterator_tag<boost::mutable_lvalue_iterator_tag, boost::random_access_traversal_tag>
|
||||||
|
, std::ptrdiff_t> first(x + 4), last(x);
|
||||||
std::copy(first, last, std::ostream_iterator<int>(std::cout, " "));
|
std::copy(first, last, std::ostream_iterator<int>(std::cout, " "));
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -7,14 +7,11 @@
|
|||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
|
|
||||||
template <class Final, class V, class R, class P, class RC, class TC, class D>
|
template <class Final, class V, class R, class P, class C, class D>
|
||||||
struct repository
|
struct repository : iterator<C, V, D, P, R>
|
||||||
: iterator<typename cvt_iterator_category<RC, TC>::type, V, D, P, R>
|
|
||||||
|
|
||||||
{
|
{
|
||||||
typedef Final final;
|
typedef Final final;
|
||||||
typedef RC return_category;
|
|
||||||
typedef TC traversal_category;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Base>
|
template <class Base>
|
||||||
@@ -105,17 +102,17 @@ typename Base1::difference_type operator-(
|
|||||||
|
|
||||||
|
|
||||||
template <class Final
|
template <class Final
|
||||||
, class V, class R, class P, class RC, class TC, class D
|
, class V, class R, class P, class C, class D
|
||||||
, class B = iterator_arith<
|
, class B = iterator_arith<
|
||||||
iterator_comparisons<
|
iterator_comparisons<
|
||||||
downcastable<repository<Final, V, R, P, RC, TC, D> > > >
|
downcastable<repository<Final, V, R, P, C, D> > > >
|
||||||
>
|
>
|
||||||
struct iterator_adaptor : B, new_iterator_base
|
struct iterator_adaptor : B, new_iterator_base
|
||||||
{
|
{
|
||||||
typedef V value_type;
|
typedef V value_type;
|
||||||
typedef R reference;
|
typedef R reference;
|
||||||
typedef P pointer;
|
typedef P pointer;
|
||||||
typedef typename B::iterator_category iterator_category;
|
typedef C iterator_category;
|
||||||
typedef D difference_type;
|
typedef D difference_type;
|
||||||
|
|
||||||
reference operator*() const
|
reference operator*() const
|
||||||
@@ -139,7 +136,7 @@ struct iterator_adaptor : B, new_iterator_base
|
|||||||
{ Final result(downcast()); return result -= x; }
|
{ Final result(downcast()); return result -= x; }
|
||||||
|
|
||||||
template <class Final2, class V2, class R2, class P2, class B2>
|
template <class Final2, class V2, class R2, class P2, class B2>
|
||||||
bool equal(iterator_adaptor<Final2,V2,R2,P2,RC,TC,D,B2> const& x) const
|
bool equal(iterator_adaptor<Final2,V2,R2,P2,C,D,B2> const& x) const
|
||||||
{
|
{
|
||||||
return this->downcast().base() == x.downcast().base();
|
return this->downcast().base() == x.downcast().base();
|
||||||
}
|
}
|
||||||
@@ -153,7 +150,7 @@ struct iterator_adaptor : B, new_iterator_base
|
|||||||
|
|
||||||
template <class Final2, class B2, class V2, class R2, class P2>
|
template <class Final2, class B2, class V2, class R2, class P2>
|
||||||
difference_type
|
difference_type
|
||||||
distance_from(const iterator_adaptor<Final2,V2,R2,P2,RC,TC,D,B2>& y) const
|
distance_from(const iterator_adaptor<Final2,V2,R2,P2,C,D,B2>& y) const
|
||||||
{
|
{
|
||||||
return y.downcast().base() - this->downcast().base();//?
|
return y.downcast().base() - this->downcast().base();//?
|
||||||
}
|
}
|
||||||
@@ -164,13 +161,13 @@ struct iterator_adaptor : B, new_iterator_base
|
|||||||
|
|
||||||
|
|
||||||
template <class Base,
|
template <class Base,
|
||||||
class V, class R, class P, class RC, class TC, class D>
|
class V, class R, class P, class C, class D>
|
||||||
struct reverse_iterator
|
struct reverse_iterator
|
||||||
: iterator_adaptor<
|
: iterator_adaptor<
|
||||||
reverse_iterator<Base, V, R, P, RC, TC, D>, V, R, P, RC, TC, D
|
reverse_iterator<Base, V, R, P, C, D>, V, R, P, C, D
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
typedef iterator_adaptor<reverse_iterator<Base, V, R, P, RC, TC, D>, V, R, P, RC, TC, D> super;
|
typedef iterator_adaptor<reverse_iterator<Base, V, R, P, C, D>, V, R, P, C, D> super;
|
||||||
|
|
||||||
// friend class super;
|
// friend class super;
|
||||||
// hmm, I don't like the next two lines
|
// hmm, I don't like the next two lines
|
||||||
@@ -185,7 +182,7 @@ struct reverse_iterator
|
|||||||
Base const& base() const { return m_base; }
|
Base const& base() const { return m_base; }
|
||||||
|
|
||||||
template <class B2, class V2, class R2, class P2>
|
template <class B2, class V2, class R2, class P2>
|
||||||
reverse_iterator(const reverse_iterator<B2,V2,R2,P2,RC,TC,D>& y)
|
reverse_iterator(const reverse_iterator<B2,V2,R2,P2,C,D>& y)
|
||||||
: m_base(y.m_base) { }
|
: m_base(y.m_base) { }
|
||||||
|
|
||||||
|
|
||||||
@@ -200,7 +197,7 @@ struct reverse_iterator
|
|||||||
|
|
||||||
template <class B2, class V2, class R2, class P2>
|
template <class B2, class V2, class R2, class P2>
|
||||||
typename super::difference_type
|
typename super::difference_type
|
||||||
distance_from(const reverse_iterator<B2,V2,R2,P2,RC,TC,D>& y) const
|
distance_from(const reverse_iterator<B2,V2,R2,P2,C,D>& y) const
|
||||||
{
|
{
|
||||||
return m_base - y.m_base;
|
return m_base - y.m_base;
|
||||||
}
|
}
|
||||||
|
@@ -220,6 +220,14 @@ namespace boost {
|
|||||||
>::type type;
|
>::type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class ReturnTag, class TraversalTag>
|
||||||
|
struct iterator_tag : cvt_iterator_category<ReturnTag, TraversalTag>::type
|
||||||
|
{
|
||||||
|
typedef ReturnTag returns;
|
||||||
|
typedef TraversalTag traversal;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif // BOOST_ITERATOR_CATEGORIES_HPP
|
#endif // BOOST_ITERATOR_CATEGORIES_HPP
|
||||||
|
@@ -26,7 +26,8 @@ namespace boost_concepts {
|
|||||||
public:
|
public:
|
||||||
typedef typename std::iterator_traits<Iterator>::value_type value_type;
|
typedef typename std::iterator_traits<Iterator>::value_type value_type;
|
||||||
typedef typename std::iterator_traits<Iterator>::reference reference;
|
typedef typename std::iterator_traits<Iterator>::reference reference;
|
||||||
typedef typename boost::return_category<Iterator>::type return_category;
|
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
|
||||||
|
typedef typename iterator_category::returns return_category;
|
||||||
|
|
||||||
void constraints() {
|
void constraints() {
|
||||||
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
|
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
|
||||||
@@ -47,7 +48,8 @@ namespace boost_concepts {
|
|||||||
template <typename Iterator, typename ValueType>
|
template <typename Iterator, typename ValueType>
|
||||||
class WritableIteratorConcept {
|
class WritableIteratorConcept {
|
||||||
public:
|
public:
|
||||||
typedef typename boost::return_category<Iterator>::type return_category;
|
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
|
||||||
|
typedef typename iterator_category::returns return_category;
|
||||||
|
|
||||||
void constraints() {
|
void constraints() {
|
||||||
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
|
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
|
||||||
@@ -69,7 +71,8 @@ namespace boost_concepts {
|
|||||||
public:
|
public:
|
||||||
typedef typename std::iterator_traits<Iterator>::value_type value_type;
|
typedef typename std::iterator_traits<Iterator>::value_type value_type;
|
||||||
typedef typename std::iterator_traits<Iterator>::reference reference;
|
typedef typename std::iterator_traits<Iterator>::reference reference;
|
||||||
typedef typename boost::return_category<Iterator>::type return_category;
|
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
|
||||||
|
typedef typename iterator_category::returns return_category;
|
||||||
|
|
||||||
void constraints() {
|
void constraints() {
|
||||||
boost::function_requires< ReadableIteratorConcept<Iterator> >();
|
boost::function_requires< ReadableIteratorConcept<Iterator> >();
|
||||||
@@ -91,7 +94,8 @@ namespace boost_concepts {
|
|||||||
public:
|
public:
|
||||||
typedef typename std::iterator_traits<Iterator>::value_type value_type;
|
typedef typename std::iterator_traits<Iterator>::value_type value_type;
|
||||||
typedef typename std::iterator_traits<Iterator>::reference reference;
|
typedef typename std::iterator_traits<Iterator>::reference reference;
|
||||||
typedef typename boost::return_category<Iterator>::type return_category;
|
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
|
||||||
|
typedef typename iterator_category::returns return_category;
|
||||||
|
|
||||||
void constraints() {
|
void constraints() {
|
||||||
boost::function_requires< ReadableIteratorConcept<Iterator> >();
|
boost::function_requires< ReadableIteratorConcept<Iterator> >();
|
||||||
@@ -115,8 +119,8 @@ namespace boost_concepts {
|
|||||||
template <typename Iterator>
|
template <typename Iterator>
|
||||||
class ForwardTraversalConcept {
|
class ForwardTraversalConcept {
|
||||||
public:
|
public:
|
||||||
typedef typename boost::traversal_category<Iterator>::type
|
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
|
||||||
traversal_category;
|
typedef typename iterator_category::traversal traversal_category;
|
||||||
|
|
||||||
void constraints() {
|
void constraints() {
|
||||||
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
|
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
|
||||||
@@ -135,8 +139,8 @@ namespace boost_concepts {
|
|||||||
template <typename Iterator>
|
template <typename Iterator>
|
||||||
class BidirectionalTraversalConcept {
|
class BidirectionalTraversalConcept {
|
||||||
public:
|
public:
|
||||||
typedef typename boost::traversal_category<Iterator>::type
|
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
|
||||||
traversal_category;
|
typedef typename iterator_category::traversal traversal_category;
|
||||||
|
|
||||||
void constraints() {
|
void constraints() {
|
||||||
boost::function_requires< ForwardTraversalConcept<Iterator> >();
|
boost::function_requires< ForwardTraversalConcept<Iterator> >();
|
||||||
@@ -153,8 +157,8 @@ namespace boost_concepts {
|
|||||||
template <typename Iterator>
|
template <typename Iterator>
|
||||||
class RandomAccessTraversalConcept {
|
class RandomAccessTraversalConcept {
|
||||||
public:
|
public:
|
||||||
typedef typename boost::traversal_category<Iterator>::type
|
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
|
||||||
traversal_category;
|
typedef typename iterator_category::traversal traversal_category;
|
||||||
typedef typename std::iterator_traits<Iterator>::difference_type
|
typedef typename std::iterator_traits<Iterator>::difference_type
|
||||||
difference_type;
|
difference_type;
|
||||||
|
|
||||||
|
@@ -8,14 +8,16 @@ int main()
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
typedef boost::reverse_iterator<int*, int, int&, int*,
|
typedef boost::reverse_iterator<int*, int, int&, int*,
|
||||||
boost::mutable_lvalue_iterator_tag, boost::random_access_traversal_tag, std::ptrdiff_t> rev_iter;
|
boost::iterator_tag<boost::mutable_lvalue_iterator_tag, boost::random_access_traversal_tag>,
|
||||||
|
std::ptrdiff_t> rev_iter;
|
||||||
boost::function_requires< boost_concepts::MutableLvalueIteratorConcept<rev_iter> >();
|
boost::function_requires< boost_concepts::MutableLvalueIteratorConcept<rev_iter> >();
|
||||||
boost::function_requires< boost_concepts::RandomAccessTraversalConcept<rev_iter> >();
|
boost::function_requires< boost_concepts::RandomAccessTraversalConcept<rev_iter> >();
|
||||||
boost::function_requires< boost::RandomAccessIteratorConcept<rev_iter> >();
|
boost::function_requires< boost::RandomAccessIteratorConcept<rev_iter> >();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
typedef boost::reverse_iterator<std::list<int>::const_iterator, int, const int&, const int*,
|
typedef boost::reverse_iterator<std::list<int>::const_iterator, int, const int&, const int*,
|
||||||
boost::constant_lvalue_iterator_tag, boost::bidirectional_traversal_tag, std::ptrdiff_t> rev_iter;
|
boost::iterator_tag<boost::constant_lvalue_iterator_tag, boost::bidirectional_traversal_tag>
|
||||||
|
, std::ptrdiff_t> rev_iter;
|
||||||
boost::function_requires< boost_concepts::ConstantLvalueIteratorConcept<rev_iter> >();
|
boost::function_requires< boost_concepts::ConstantLvalueIteratorConcept<rev_iter> >();
|
||||||
boost::function_requires< boost_concepts::BidirectionalTraversalConcept<rev_iter> >();
|
boost::function_requires< boost_concepts::BidirectionalTraversalConcept<rev_iter> >();
|
||||||
boost::function_requires< boost::BidirectionalIteratorConcept<rev_iter> >();
|
boost::function_requires< boost::BidirectionalIteratorConcept<rev_iter> >();
|
||||||
|
Reference in New Issue
Block a user