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-23 17:07:04 +00:00
|
|
|
#include <boost/type_traits/is_convertible.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>
|
|
|
|
|
|
|
|
namespace boost_concepts {
|
|
|
|
// Used a different namespace here (instead of "boost") so that the
|
|
|
|
// concept descriptions do not take for granted the names in
|
|
|
|
// namespace boost.
|
|
|
|
|
|
|
|
// We use this in place of STATIC_ASSERT((is_convertible<...>))
|
|
|
|
// because some compilers (CWPro7.x) can't detect convertibility.
|
|
|
|
//
|
|
|
|
// Of course, that just gets us a different error at the moment with
|
|
|
|
// some tests, since new iterator category deduction still depends
|
|
|
|
// on convertibility detection. We might need some specializations
|
|
|
|
// to support this compiler.
|
|
|
|
template <class Target, class Source>
|
|
|
|
struct static_assert_base_and_derived
|
|
|
|
{
|
|
|
|
static_assert_base_and_derived(Target* = (Source*)0) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
// Iterator Access Concepts
|
|
|
|
|
|
|
|
template <typename Iterator>
|
|
|
|
class ReadableIteratorConcept {
|
|
|
|
public:
|
2003-11-28 16:21:15 +00:00
|
|
|
typedef BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::value_type value_type;
|
2003-07-07 14:14:36 +00:00
|
|
|
|
|
|
|
void constraints() {
|
2004-01-12 20:43:30 +00:00
|
|
|
boost::function_requires< boost::AssignableConcept<Iterator> >();
|
|
|
|
boost::function_requires< boost::CopyConstructibleConcept<Iterator> >();
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2004-01-12 20:43:30 +00:00
|
|
|
value_type v = *i;
|
2003-07-07 14:14:36 +00:00
|
|
|
boost::ignore_unused_variable_warning(v);
|
|
|
|
}
|
|
|
|
Iterator i;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
>
|
2003-07-07 14:14:36 +00:00
|
|
|
class WritableIteratorConcept {
|
|
|
|
public:
|
2003-11-22 01:18:37 +00:00
|
|
|
|
2003-07-07 14:14:36 +00:00
|
|
|
void constraints() {
|
2004-01-12 20:43:30 +00:00
|
|
|
boost::function_requires< boost::CopyConstructibleConcept<Iterator> >();
|
|
|
|
*i = v;
|
2003-07-07 14:14:36 +00:00
|
|
|
}
|
|
|
|
ValueType v;
|
|
|
|
Iterator i;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Iterator>
|
|
|
|
class SwappableIteratorConcept {
|
|
|
|
public:
|
|
|
|
|
|
|
|
void constraints() {
|
|
|
|
std::iter_swap(i1, i2);
|
|
|
|
}
|
|
|
|
Iterator i1;
|
|
|
|
Iterator i2;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Iterator>
|
2004-01-27 18:14:48 +00:00
|
|
|
class LvalueIteratorConcept
|
2003-11-22 01:18:37 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef typename boost::detail::iterator_traits<Iterator>::value_type value_type;
|
|
|
|
void constraints()
|
|
|
|
{
|
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
|
|
|
}
|
2003-07-07 14:14:36 +00:00
|
|
|
Iterator i;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
// Iterator Traversal Concepts
|
|
|
|
|
|
|
|
template <typename Iterator>
|
|
|
|
class IncrementableIteratorConcept {
|
|
|
|
public:
|
2003-11-22 01:18:37 +00:00
|
|
|
typedef typename boost::iterator_traversal<Iterator>::type traversal_category;
|
2003-07-07 14:14:36 +00:00
|
|
|
|
|
|
|
void constraints() {
|
2004-01-12 20:43:30 +00:00
|
|
|
boost::function_requires< boost::AssignableConcept<Iterator> >();
|
|
|
|
boost::function_requires< boost::CopyConstructibleConcept<Iterator> >();
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2003-11-22 01:18:37 +00:00
|
|
|
BOOST_STATIC_ASSERT(
|
|
|
|
(boost::is_convertible<
|
|
|
|
traversal_category
|
|
|
|
, boost::incrementable_traversal_tag
|
|
|
|
>::value
|
|
|
|
));
|
2003-07-07 14:14:36 +00:00
|
|
|
|
|
|
|
++i;
|
|
|
|
(void)i++;
|
|
|
|
}
|
|
|
|
Iterator i;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Iterator>
|
|
|
|
class SinglePassIteratorConcept {
|
|
|
|
public:
|
2003-11-22 01:18:37 +00:00
|
|
|
typedef typename boost::iterator_traversal<Iterator>::type traversal_category;
|
2003-07-07 14:14:36 +00:00
|
|
|
typedef typename boost::detail::iterator_traits<Iterator>::difference_type difference_type;
|
|
|
|
|
|
|
|
void constraints() {
|
|
|
|
boost::function_requires< IncrementableIteratorConcept<Iterator> >();
|
|
|
|
boost::function_requires< boost::EqualityComparableConcept<Iterator> >();
|
|
|
|
|
2003-11-22 01:18:37 +00:00
|
|
|
BOOST_STATIC_ASSERT(
|
|
|
|
(boost::is_convertible<
|
|
|
|
traversal_category
|
|
|
|
, boost::single_pass_traversal_tag
|
|
|
|
>::value
|
|
|
|
));
|
2003-07-07 14:14:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Iterator>
|
|
|
|
class ForwardTraversalConcept {
|
|
|
|
public:
|
2003-11-22 01:18:37 +00:00
|
|
|
typedef typename boost::iterator_traversal<Iterator>::type traversal_category;
|
2003-07-07 14:14:36 +00:00
|
|
|
typedef typename boost::detail::iterator_traits<Iterator>::difference_type difference_type;
|
|
|
|
|
|
|
|
void constraints() {
|
|
|
|
boost::function_requires< SinglePassIteratorConcept<Iterator> >();
|
2004-01-12 20:43:30 +00:00
|
|
|
boost::function_requires<
|
|
|
|
boost::DefaultConstructibleConcept<Iterator> >();
|
2003-07-07 14:14:36 +00:00
|
|
|
|
|
|
|
typedef boost::mpl::and_<
|
|
|
|
boost::is_integral<difference_type>,
|
|
|
|
boost::mpl::bool_< std::numeric_limits<difference_type>::is_signed >
|
|
|
|
> difference_type_is_signed_integral;
|
|
|
|
|
|
|
|
BOOST_STATIC_ASSERT(difference_type_is_signed_integral::value);
|
2003-11-22 01:18:37 +00:00
|
|
|
BOOST_STATIC_ASSERT(
|
|
|
|
(boost::is_convertible<
|
|
|
|
traversal_category
|
|
|
|
, boost::forward_traversal_tag
|
|
|
|
>::value
|
|
|
|
));
|
2003-07-07 14:14:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Iterator>
|
|
|
|
class BidirectionalTraversalConcept {
|
|
|
|
public:
|
2003-11-22 01:18:37 +00:00
|
|
|
typedef typename boost::iterator_traversal<Iterator>::type traversal_category;
|
2003-07-07 14:14:36 +00:00
|
|
|
|
|
|
|
void constraints() {
|
|
|
|
boost::function_requires< ForwardTraversalConcept<Iterator> >();
|
|
|
|
|
2003-11-22 01:18:37 +00:00
|
|
|
BOOST_STATIC_ASSERT(
|
|
|
|
(boost::is_convertible<
|
|
|
|
traversal_category
|
|
|
|
, boost::bidirectional_traversal_tag
|
|
|
|
>::value
|
|
|
|
));
|
2003-07-07 14:14:36 +00:00
|
|
|
|
|
|
|
--i;
|
|
|
|
(void)i--;
|
|
|
|
}
|
|
|
|
Iterator i;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Iterator>
|
|
|
|
class RandomAccessTraversalConcept {
|
|
|
|
public:
|
2003-11-22 01:18:37 +00:00
|
|
|
typedef typename boost::iterator_traversal<Iterator>::type traversal_category;
|
2003-07-07 14:14:36 +00:00
|
|
|
typedef typename boost::detail::iterator_traits<Iterator>::difference_type
|
|
|
|
difference_type;
|
|
|
|
|
|
|
|
void constraints() {
|
|
|
|
boost::function_requires< BidirectionalTraversalConcept<Iterator> >();
|
|
|
|
|
2003-11-22 01:18:37 +00:00
|
|
|
BOOST_STATIC_ASSERT(
|
|
|
|
(boost::is_convertible<
|
|
|
|
traversal_category
|
|
|
|
, boost::random_access_traversal_tag
|
|
|
|
>::value
|
|
|
|
));
|
2003-07-07 14:14:36 +00:00
|
|
|
|
|
|
|
i += n;
|
|
|
|
i = i + n;
|
|
|
|
i = n + i;
|
|
|
|
i -= n;
|
|
|
|
i = i - n;
|
|
|
|
n = i - j;
|
|
|
|
}
|
|
|
|
difference_type n;
|
|
|
|
Iterator i, j;
|
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
// Iterator Interoperability Concept
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
bool b;
|
|
|
|
b = i1 == i2;
|
|
|
|
b = i1 != i2;
|
|
|
|
|
|
|
|
b = i2 == i1;
|
|
|
|
b = i2 != i1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Iterator1, typename Iterator2>
|
|
|
|
void interop_rand_access_constraints(Iterator1 const& i1, Iterator2 const& i2,
|
|
|
|
boost::random_access_traversal_tag, boost::random_access_traversal_tag)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
template <typename Iterator1, typename Iterator2>
|
|
|
|
void interop_rand_access_constraints(Iterator1 const& i1, Iterator2 const& i2,
|
|
|
|
boost::single_pass_traversal_tag, boost::single_pass_traversal_tag)
|
|
|
|
{ }
|
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 Iterator, typename ConstIterator>
|
|
|
|
class InteroperableIteratorConcept
|
2003-07-07 14:14:36 +00:00
|
|
|
{
|
2004-01-14 03:44:45 +00:00
|
|
|
public:
|
|
|
|
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;
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2004-01-14 03:44:45 +00:00
|
|
|
void constraints()
|
2003-07-07 14:14:36 +00:00
|
|
|
{
|
2004-01-14 03:44:45 +00:00
|
|
|
boost::function_requires< SinglePassIteratorConcept<Iterator> >();
|
|
|
|
boost::function_requires< SinglePassIteratorConcept<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;
|
|
|
|
}
|
|
|
|
Iterator i;
|
|
|
|
ConstIterator ci;
|
|
|
|
};
|
2003-07-07 14:14:36 +00:00
|
|
|
|
|
|
|
} // namespace boost_concepts
|
|
|
|
|
|
|
|
|
|
|
|
#endif // BOOST_ITERATOR_CONCEPTS_HPP
|