2004-07-26 00:32:12 +00:00
|
|
|
// (C) Copyright Jeremy Siek 2002.
|
|
|
|
// Distributed under 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)
|
2003-07-07 14:14:36 +00:00
|
|
|
|
|
|
|
#ifndef BOOST_ITERATOR_CONCEPTS_HPP
|
|
|
|
#define BOOST_ITERATOR_CONCEPTS_HPP
|
|
|
|
|
|
|
|
// Revision History
|
|
|
|
// 26 Apr 2003 thw
|
|
|
|
// Adapted to new iterator concepts
|
|
|
|
// 22 Nov 2002 Thomas Witt
|
|
|
|
// Added interoperable concept.
|
|
|
|
|
|
|
|
#include <boost/concept_check.hpp>
|
|
|
|
#include <boost/iterator/iterator_categories.hpp>
|
2003-11-22 01:18:37 +00:00
|
|
|
|
|
|
|
// Use boost::detail::iterator_traits to work around some MSVC/Dinkumware problems.
|
|
|
|
#include <boost/detail/iterator.hpp>
|
|
|
|
|
2003-07-07 14:14:36 +00:00
|
|
|
#include <boost/type_traits/is_same.hpp>
|
|
|
|
#include <boost/type_traits/is_integral.hpp>
|
2003-11-22 01:18:37 +00:00
|
|
|
|
2003-07-07 14:14:36 +00:00
|
|
|
#include <boost/mpl/bool.hpp>
|
|
|
|
#include <boost/mpl/if.hpp>
|
|
|
|
#include <boost/mpl/and.hpp>
|
2003-11-22 01:18:37 +00:00
|
|
|
#include <boost/mpl/or.hpp>
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2003-11-22 01:18:37 +00:00
|
|
|
#include <boost/static_assert.hpp>
|
2003-07-07 14:14:36 +00:00
|
|
|
|
|
|
|
// Use boost/limits to work around missing limits headers on some compilers
|
|
|
|
#include <boost/limits.hpp>
|
2004-09-02 15:41:37 +00:00
|
|
|
#include <boost/config.hpp>
|
2003-07-07 14:14:36 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
#include <boost/concept/detail/concept_def.hpp>
|
|
|
|
|
2006-04-29 20:27:14 +00:00
|
|
|
namespace boost_concepts
|
|
|
|
{
|
2003-07-07 14:14:36 +00:00
|
|
|
// Used a different namespace here (instead of "boost") so that the
|
|
|
|
// concept descriptions do not take for granted the names in
|
|
|
|
// namespace boost.
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
// Iterator Access Concepts
|
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
BOOST_concept(ReadableIterator,(Iterator))
|
|
|
|
: boost::Assignable<Iterator>
|
|
|
|
, boost::CopyConstructible<Iterator>
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
|
|
|
typedef BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::value_type value_type;
|
|
|
|
typedef BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::reference reference;
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
~ReadableIterator()
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
value_type v = *i;
|
|
|
|
boost::ignore_unused_variable_warning(v);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
Iterator i;
|
2003-07-07 14:14:36 +00:00
|
|
|
};
|
|
|
|
|
2003-11-22 01:18:37 +00:00
|
|
|
template <
|
|
|
|
typename Iterator
|
2003-11-29 21:02:45 +00:00
|
|
|
, typename ValueType = BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::value_type
|
2003-11-22 01:18:37 +00:00
|
|
|
>
|
2006-05-07 21:00:35 +00:00
|
|
|
struct WritableIterator
|
2006-05-01 21:42:56 +00:00
|
|
|
: boost::CopyConstructible<Iterator>
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
2006-05-01 21:42:56 +00:00
|
|
|
~WritableIterator()
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
|
|
|
*i = v;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
ValueType v;
|
|
|
|
Iterator i;
|
2003-07-07 14:14:36 +00:00
|
|
|
};
|
2006-05-01 21:42:56 +00:00
|
|
|
|
|
|
|
template <
|
|
|
|
typename Iterator
|
|
|
|
, typename ValueType = BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::value_type
|
|
|
|
>
|
|
|
|
struct WritableIteratorConcept : WritableIterator<Iterator,ValueType> {};
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
BOOST_concept(SwappableIterator,(Iterator))
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
2006-05-01 21:42:56 +00:00
|
|
|
~SwappableIterator()
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
|
|
|
std::iter_swap(i1, i2);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
Iterator i1;
|
|
|
|
Iterator i2;
|
2003-07-07 14:14:36 +00:00
|
|
|
};
|
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
BOOST_concept(LvalueIterator,(Iterator))
|
2003-11-22 01:18:37 +00:00
|
|
|
{
|
|
|
|
typedef typename boost::detail::iterator_traits<Iterator>::value_type value_type;
|
2006-04-29 20:27:14 +00:00
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
~LvalueIterator()
|
2003-11-22 01:18:37 +00:00
|
|
|
{
|
2004-01-28 14:01:45 +00:00
|
|
|
value_type& r = const_cast<value_type&>(*i);
|
2004-01-27 18:34:00 +00:00
|
|
|
boost::ignore_unused_variable_warning(r);
|
2004-01-27 18:14:48 +00:00
|
|
|
}
|
2006-04-29 20:27:14 +00:00
|
|
|
private:
|
|
|
|
Iterator i;
|
2003-07-07 14:14:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
// Iterator Traversal Concepts
|
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
BOOST_concept(IncrementableIterator,(Iterator))
|
|
|
|
: boost::Assignable<Iterator>
|
|
|
|
, boost::CopyConstructible<Iterator>
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
|
|
|
typedef typename boost::iterator_traversal<Iterator>::type traversal_category;
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
~IncrementableIterator()
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
2006-04-30 03:33:33 +00:00
|
|
|
BOOST_CONCEPT_ASSERT((
|
2006-05-01 21:42:56 +00:00
|
|
|
boost::Convertible<
|
2006-04-30 03:33:33 +00:00
|
|
|
traversal_category
|
|
|
|
, boost::incrementable_traversal_tag
|
|
|
|
>));
|
2006-04-29 20:27:14 +00:00
|
|
|
|
|
|
|
++i;
|
|
|
|
(void)i++;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
Iterator i;
|
2003-07-07 14:14:36 +00:00
|
|
|
};
|
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
BOOST_concept(SinglePassIterator,(Iterator))
|
|
|
|
: IncrementableIterator<Iterator>
|
|
|
|
, boost::EqualityComparable<Iterator>
|
2006-04-29 20:27:14 +00:00
|
|
|
|
|
|
|
{
|
2006-05-01 21:42:56 +00:00
|
|
|
~SinglePassIterator()
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
2006-04-30 03:33:33 +00:00
|
|
|
BOOST_CONCEPT_ASSERT((
|
2006-05-01 21:42:56 +00:00
|
|
|
boost::Convertible<
|
|
|
|
BOOST_DEDUCED_TYPENAME SinglePassIterator::traversal_category
|
2006-04-29 20:27:14 +00:00
|
|
|
, boost::single_pass_traversal_tag
|
|
|
|
> ));
|
|
|
|
}
|
2003-07-07 14:14:36 +00:00
|
|
|
};
|
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
BOOST_concept(ForwardTraversal,(Iterator))
|
|
|
|
: SinglePassIterator<Iterator>
|
|
|
|
, boost::DefaultConstructible<Iterator>
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
|
|
|
typedef typename boost::detail::iterator_traits<Iterator>::difference_type difference_type;
|
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
~ForwardTraversal()
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
|
|
|
BOOST_MPL_ASSERT((boost::is_integral<difference_type>));
|
|
|
|
BOOST_MPL_ASSERT_RELATION(std::numeric_limits<difference_type>::is_signed, ==, true);
|
|
|
|
|
2006-04-30 03:33:33 +00:00
|
|
|
BOOST_CONCEPT_ASSERT((
|
2006-05-01 21:42:56 +00:00
|
|
|
boost::Convertible<
|
|
|
|
BOOST_DEDUCED_TYPENAME ForwardTraversal::traversal_category
|
2006-04-29 20:27:14 +00:00
|
|
|
, boost::forward_traversal_tag
|
|
|
|
> ));
|
2003-07-07 14:14:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
BOOST_concept(BidirectionalTraversal,(Iterator))
|
|
|
|
: ForwardTraversal<Iterator>
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
2006-05-01 21:42:56 +00:00
|
|
|
~BidirectionalTraversal()
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
2006-04-30 03:33:33 +00:00
|
|
|
BOOST_CONCEPT_ASSERT((
|
2006-05-01 21:42:56 +00:00
|
|
|
boost::Convertible<
|
|
|
|
BOOST_DEDUCED_TYPENAME BidirectionalTraversal::traversal_category
|
2006-04-29 20:27:14 +00:00
|
|
|
, boost::bidirectional_traversal_tag
|
|
|
|
> ));
|
|
|
|
|
|
|
|
--i;
|
|
|
|
(void)i--;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
Iterator i;
|
2003-07-07 14:14:36 +00:00
|
|
|
};
|
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
BOOST_concept(RandomAccessTraversal,(Iterator))
|
|
|
|
: BidirectionalTraversal<Iterator>
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
|
|
|
public:
|
2006-05-01 21:42:56 +00:00
|
|
|
~RandomAccessTraversal()
|
2006-04-29 20:27:14 +00:00
|
|
|
{
|
2006-04-30 03:33:33 +00:00
|
|
|
BOOST_CONCEPT_ASSERT((
|
2006-05-01 21:42:56 +00:00
|
|
|
boost::Convertible<
|
|
|
|
BOOST_DEDUCED_TYPENAME RandomAccessTraversal::traversal_category
|
2006-04-29 20:27:14 +00:00
|
|
|
, boost::random_access_traversal_tag
|
|
|
|
> ));
|
|
|
|
|
|
|
|
i += n;
|
|
|
|
i = i + n;
|
|
|
|
i = n + i;
|
|
|
|
i -= n;
|
|
|
|
i = i - n;
|
|
|
|
n = i - j;
|
|
|
|
}
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2006-04-29 20:27:14 +00:00
|
|
|
private:
|
2006-05-01 21:42:56 +00:00
|
|
|
typename BidirectionalTraversal<Iterator>::difference_type n;
|
2006-04-29 20:27:14 +00:00
|
|
|
Iterator i, j;
|
2003-07-07 14:14:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================
|
2006-05-01 21:42:56 +00:00
|
|
|
// Iterator Interoperability
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2004-01-14 03:44:45 +00:00
|
|
|
namespace detail
|
2003-07-07 14:14:36 +00:00
|
|
|
{
|
2004-01-14 03:44:45 +00:00
|
|
|
template <typename Iterator1, typename Iterator2>
|
|
|
|
void interop_single_pass_constraints(Iterator1 const& i1, Iterator2 const& i2)
|
|
|
|
{
|
2006-04-29 20:27:14 +00:00
|
|
|
bool b;
|
|
|
|
b = i1 == i2;
|
|
|
|
b = i1 != i2;
|
|
|
|
|
|
|
|
b = i2 == i1;
|
|
|
|
b = i2 != i1;
|
|
|
|
boost::ignore_unused_variable_warning(b);
|
2004-01-14 03:44:45 +00:00
|
|
|
}
|
2006-04-29 20:27:14 +00:00
|
|
|
|
2004-01-14 03:44:45 +00:00
|
|
|
template <typename Iterator1, typename Iterator2>
|
2006-04-29 20:27:14 +00:00
|
|
|
void interop_rand_access_constraints(
|
|
|
|
Iterator1 const& i1, Iterator2 const& i2,
|
|
|
|
boost::random_access_traversal_tag, boost::random_access_traversal_tag)
|
2004-01-14 03:44:45 +00:00
|
|
|
{
|
2006-04-29 20:27:14 +00:00
|
|
|
bool b;
|
|
|
|
typename boost::detail::iterator_traits<Iterator2>::difference_type n;
|
|
|
|
b = i1 < i2;
|
|
|
|
b = i1 <= i2;
|
|
|
|
b = i1 > i2;
|
|
|
|
b = i1 >= i2;
|
|
|
|
n = i1 - i2;
|
|
|
|
|
|
|
|
b = i2 < i1;
|
|
|
|
b = i2 <= i1;
|
|
|
|
b = i2 > i1;
|
|
|
|
b = i2 >= i1;
|
|
|
|
n = i2 - i1;
|
|
|
|
boost::ignore_unused_variable_warning(b);
|
|
|
|
boost::ignore_unused_variable_warning(n);
|
2004-01-14 03:44:45 +00:00
|
|
|
}
|
2006-04-29 20:27:14 +00:00
|
|
|
|
2004-01-14 03:44:45 +00:00
|
|
|
template <typename Iterator1, typename Iterator2>
|
2006-04-29 20:27:14 +00:00
|
|
|
void interop_rand_access_constraints(
|
|
|
|
Iterator1 const&, Iterator2 const&,
|
|
|
|
boost::single_pass_traversal_tag, boost::single_pass_traversal_tag)
|
2004-01-14 03:44:45 +00:00
|
|
|
{ }
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2004-01-14 03:44:45 +00:00
|
|
|
} // namespace detail
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
BOOST_concept(InteroperableIterator,(Iterator)(ConstIterator))
|
2003-07-07 14:14:36 +00:00
|
|
|
{
|
2006-04-29 20:27:14 +00:00
|
|
|
private:
|
2004-01-14 03:44:45 +00:00
|
|
|
typedef typename boost::detail::pure_traversal_tag<
|
|
|
|
typename boost::iterator_traversal<
|
|
|
|
Iterator
|
|
|
|
>::type
|
|
|
|
>::type traversal_category;
|
|
|
|
|
|
|
|
typedef typename boost::detail::pure_traversal_tag<
|
|
|
|
typename boost::iterator_traversal<
|
|
|
|
ConstIterator
|
|
|
|
>::type
|
|
|
|
>::type const_traversal_category;
|
2006-04-29 20:27:14 +00:00
|
|
|
|
|
|
|
public:
|
2006-05-01 21:42:56 +00:00
|
|
|
~InteroperableIterator()
|
2003-07-07 14:14:36 +00:00
|
|
|
{
|
2006-05-01 21:42:56 +00:00
|
|
|
BOOST_CONCEPT_ASSERT((SinglePassIterator<Iterator>));
|
|
|
|
BOOST_CONCEPT_ASSERT((SinglePassIterator<ConstIterator>));
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2004-01-14 03:44:45 +00:00
|
|
|
detail::interop_single_pass_constraints(i, ci);
|
|
|
|
detail::interop_rand_access_constraints(i, ci, traversal_category(), const_traversal_category());
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2004-01-14 03:44:45 +00:00
|
|
|
ci = i;
|
|
|
|
}
|
2006-04-29 20:27:14 +00:00
|
|
|
|
|
|
|
private:
|
2004-01-14 03:44:45 +00:00
|
|
|
Iterator i;
|
|
|
|
ConstIterator ci;
|
|
|
|
};
|
2003-07-07 14:14:36 +00:00
|
|
|
|
|
|
|
} // namespace boost_concepts
|
|
|
|
|
2006-05-01 21:42:56 +00:00
|
|
|
#include <boost/concept/detail/concept_undef.hpp>
|
2003-07-07 14:14:36 +00:00
|
|
|
|
|
|
|
#endif // BOOST_ITERATOR_CONCEPTS_HPP
|