updated to match my paper to the committee

[SVN r10259]
This commit is contained in:
Jeremy Siek
2001-06-03 21:06:49 +00:00
parent d7023154a3
commit 42e4db1539
3 changed files with 179 additions and 184 deletions

View File

@ -0,0 +1,159 @@
#ifndef BOOST_ITERATOR_CATEGORIES_HPP
#define BOOST_ITERATOR_CATEGORIES_HPP
#include <boost/config.hpp>
#include <boost/type_traits/conversion_traits.hpp>
#include <boost/type_traits/cv_traits.hpp>
#include <boost/pending/ct_if.hpp>
#include <boost/detail/iterator.hpp>
namespace boost {
// Return Type Categories
struct readable_iterator_tag { };
struct writable_iterator_tag { };
struct swappable_iterator_tag { };
struct mutable_lvalue_iterator_tag :
virtual public writable_iterator_tag,
virtual public readable_iterator_tag { };
struct constant_lvalue_iterator_tag :
virtual public readable_iterator_tag { };
// Traversal Categories
struct forward_traversal_tag { };
struct bidirectional_traversal_tag : public forward_traversal_tag { };
struct random_access_traversal_tag : public bidirectional_traversal_tag { };
struct error_iterator_tag { };
// Inherit from iterator_base if your iterator defines its own
// return_category and traversal_category. Otherwise, the "old style"
// iterator category will be mapped to the return_category and
// traversal_category.
struct new_iterator_base { };
namespace detail {
struct return_category_from_nested_type {
template <typename Iterator> struct bind {
typedef typename Iterator::return_category type;
};
};
struct traversal_category_from_nested_type {
template <typename Iterator> struct bind {
typedef typename Iterator::traversal_category type;
};
};
template <typename ValueType>
struct choose_lvalue_return {
typedef typename ct_if<is_const<ValueType>::value,
boost::constant_lvalue_iterator_tag,
boost::mutable_lvalue_iterator_tag>::type type;
};
template <typename Category, typename ValueType>
struct iter_category_to_return {
typedef typename ct_if<
is_convertible<Category*, std::forward_iterator_tag*>::value,
typename choose_lvalue_return<ValueType>::type,
typename ct_if<
is_convertible<Category*, std::input_iterator_tag*>::value,
boost::readable_iterator_tag,
typename ct_if<
is_convertible<Category*, std::output_iterator_tag*>::value,
boost::writable_iterator_tag,
boost::error_iterator_tag
>::type
>::type
>::type type;
};
template <typename Category>
struct iter_category_to_traversal {
typedef typename ct_if<
is_convertible<Category*, std::random_access_iterator_tag*>::value,
random_access_traversal_tag,
typename ct_if<
is_convertible<Category*, std::bidirectional_iterator_tag*>::value,
bidirectional_traversal_tag,
forward_traversal_tag
>::type
>::type type;
};
struct return_category_from_old_traits {
template <typename Iterator> class bind {
typedef boost::detail::iterator_traits<Iterator> OldTraits;
typedef typename OldTraits::iterator_category Cat;
typedef typename OldTraits::value_type value_type;
public:
typedef iter_category_to_return<Cat, value_type>::type type;
};
};
struct traversal_category_from_old_traits {
template <typename Iterator> class bind {
typedef boost::detail::iterator_traits<Iterator> OldTraits;
typedef typename OldTraits::iterator_category Cat;
public:
typedef iter_category_to_traversal<Cat>::type type;
};
};
template <typename Iterator>
class choose_return_category {
typedef typename ct_if<is_convertible<Iterator*,
new_iterator_base*>::value,
return_category_from_nested_type,
return_category_from_old_traits>::type Choice;
public:
typedef typename Choice:: template bind<Iterator>::type type;
};
template <typename Iterator>
class choose_traversal_category {
typedef typename ct_if<is_convertible<Iterator*,
new_iterator_base*>::value,
traversal_category_from_nested_type,
traversal_category_from_old_traits>::type Choice;
public:
typedef typename Choice:: template bind<Iterator>::type type;
};
} // namespace detail
template <class Iterator>
struct return_category {
typedef typename detail::choose_return_category<Iterator>::type type;
};
template <class Iterator>
struct traversal_category {
typedef typename detail::choose_traversal_category<Iterator>::type type;
};
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <typename T>
struct return_category<T*>
{
typedef typename ct_if<is_const<T>::value,
constant_lvalue_iterator_tag,
mutable_lvalue_iterator_tag>::type type;
};
template <typename T>
struct traversal_category<T*>
{
typedef random_access_traversal_tag type;
};
#endif
} // namespace boost
#endif // BOOST_ITERATOR_CATEGORIES_HPP

View File

@ -2,7 +2,7 @@
#define BOOST_ITERATOR_CONCEPTS_HPP #define BOOST_ITERATOR_CONCEPTS_HPP
#include <boost/concept_check.hpp> #include <boost/concept_check.hpp>
#include <boost/iterator_traits.hpp> #include <boost/iterator_categories.hpp>
#include <boost/type_traits/conversion_traits.hpp> #include <boost/type_traits/conversion_traits.hpp>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
@ -18,10 +18,9 @@ namespace boost_concepts {
template <typename Iterator> template <typename Iterator>
class ReadableIteratorConcept { class ReadableIteratorConcept {
public: public:
typedef typename boost::iterator_traits<Iterator>::value_type value_type; typedef typename std::iterator_traits<Iterator>::value_type value_type;
typedef typename boost::iterator_traits<Iterator>::reference reference; typedef typename std::iterator_traits<Iterator>::reference reference;
typedef typename boost::iterator_traits<Iterator>::return_category typedef typename boost::return_category<Iterator>::type return_category;
return_category;
void constraints() { void constraints() {
boost::function_requires< boost::SGIAssignableConcept<Iterator> >(); boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
@ -42,8 +41,7 @@ namespace boost_concepts {
template <typename Iterator, typename ValueType> template <typename Iterator, typename ValueType>
class WritableIteratorConcept { class WritableIteratorConcept {
public: public:
typedef typename boost::iterator_traits<Iterator>::return_category typedef typename boost::return_category<Iterator>::type return_category;
return_category;
void constraints() { void constraints() {
boost::function_requires< boost::SGIAssignableConcept<Iterator> >(); boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
@ -54,7 +52,7 @@ namespace boost_concepts {
BOOST_STATIC_ASSERT((boost::is_convertible<return_category*, BOOST_STATIC_ASSERT((boost::is_convertible<return_category*,
boost::writable_iterator_tag*>::value)); boost::writable_iterator_tag*>::value));
*i = v; // an alternative could be something like write(x, v) *i = v; // a good alternative could be something like write(x, v)
} }
ValueType v; ValueType v;
Iterator i; Iterator i;
@ -63,10 +61,9 @@ namespace boost_concepts {
template <typename Iterator> template <typename Iterator>
class ConstantLvalueIteratorConcept { class ConstantLvalueIteratorConcept {
public: public:
typedef typename boost::iterator_traits<Iterator>::value_type value_type; typedef typename std::iterator_traits<Iterator>::value_type value_type;
typedef typename boost::iterator_traits<Iterator>::reference reference; typedef typename std::iterator_traits<Iterator>::reference reference;
typedef typename boost::iterator_traits<Iterator>::return_category typedef typename boost::return_category<Iterator>::type return_category;
return_category;
void constraints() { void constraints() {
boost::function_requires< ReadableIteratorConcept<Iterator> >(); boost::function_requires< ReadableIteratorConcept<Iterator> >();
@ -86,10 +83,9 @@ namespace boost_concepts {
template <typename Iterator> template <typename Iterator>
class MutableLvalueIteratorConcept { class MutableLvalueIteratorConcept {
public: public:
typedef typename boost::iterator_traits<Iterator>::value_type value_type; typedef typename std::iterator_traits<Iterator>::value_type value_type;
typedef typename boost::iterator_traits<Iterator>::reference reference; typedef typename std::iterator_traits<Iterator>::reference reference;
typedef typename boost::iterator_traits<Iterator>::return_category typedef typename boost::return_category<Iterator>::type return_category;
return_category;
void constraints() { void constraints() {
boost::function_requires< ReadableIteratorConcept<Iterator> >(); boost::function_requires< ReadableIteratorConcept<Iterator> >();
@ -111,12 +107,9 @@ namespace boost_concepts {
// Iterator Traversal Concepts // Iterator Traversal Concepts
template <typename Iterator> template <typename Iterator>
class SinglePassIteratorConcept { class ForwardIteratorConcept {
public: public:
typedef typename boost::iterator_traits<Iterator>::traversal_category typedef typename boost::traversal_category<Iterator>::type traversal_category;
traversal_category;
typedef typename boost::iterator_traits<Iterator>::difference_type
difference_type;
void constraints() { void constraints() {
boost::function_requires< boost::SGIAssignableConcept<Iterator> >(); boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
@ -125,42 +118,23 @@ namespace boost_concepts {
boost::DefaultConstructibleConcept<Iterator> >(); boost::DefaultConstructibleConcept<Iterator> >();
BOOST_STATIC_ASSERT((boost::is_convertible<traversal_category*, BOOST_STATIC_ASSERT((boost::is_convertible<traversal_category*,
boost::single_pass_iterator_tag*>::value)); boost::forward_traversal_tag*>::value));
// difference_type must be a signed integral type
++i; ++i;
(void)i++; (void)i++;
} }
Iterator i; Iterator i;
}; };
template <typename Iterator>
class ForwardIteratorConcept {
public:
typedef typename boost::iterator_traits<Iterator>::traversal_category
traversal_category;
void constraints() {
boost::function_requires< SinglePassIteratorConcept<Iterator> >();
BOOST_STATIC_ASSERT((boost::is_convertible<traversal_category*,
boost::forward_iterator_tag*>::value));
}
};
template <typename Iterator> template <typename Iterator>
class BidirectionalIteratorConcept { class BidirectionalIteratorConcept {
public: public:
typedef typename boost::iterator_traits<Iterator>::traversal_category typedef typename boost::traversal_category<Iterator>::type traversal_category;
traversal_category;
void constraints() { void constraints() {
boost::function_requires< ForwardIteratorConcept<Iterator> >(); boost::function_requires< ForwardIteratorConcept<Iterator> >();
BOOST_STATIC_ASSERT((boost::is_convertible<traversal_category*, BOOST_STATIC_ASSERT((boost::is_convertible<traversal_category*,
boost::bidirectional_iterator_tag*>::value)); boost::bidirectional_traversal_tag*>::value));
--i; --i;
(void)i--; (void)i--;
@ -171,16 +145,15 @@ namespace boost_concepts {
template <typename Iterator> template <typename Iterator>
class RandomAccessIteratorConcept { class RandomAccessIteratorConcept {
public: public:
typedef typename boost::iterator_traits<Iterator>::traversal_category typedef typename boost::traversal_category<Iterator>::type traversal_category;
traversal_category; typedef typename std::iterator_traits<Iterator>::difference_type
typedef typename boost::iterator_traits<Iterator>::difference_type
difference_type; difference_type;
void constraints() { void constraints() {
boost::function_requires< BidirectionalIteratorConcept<Iterator> >(); boost::function_requires< BidirectionalIteratorConcept<Iterator> >();
BOOST_STATIC_ASSERT((boost::is_convertible<traversal_category*, BOOST_STATIC_ASSERT((boost::is_convertible<traversal_category*,
boost::random_access_iterator_tag*>::value)); boost::random_access_traversal_tag*>::value));
i += n; i += n;
i = i + n; i = i + n;

View File

@ -1,137 +0,0 @@
#ifndef BOOST_ITERATOR_TRAITS_HPP
#define BOOST_ITERATOR_TRAITS_HPP
#include <boost/config.hpp>
#include <boost/type_traits/conversion_traits.hpp>
#include <boost/type_traits/cv_traits.hpp>
#include <boost/pending/ct_if.hpp>
#include <boost/detail/iterator.hpp>
namespace boost {
// Traversal Categories
struct single_pass_iterator_tag { };
struct forward_iterator_tag : public single_pass_iterator_tag { };
struct bidirectional_iterator_tag : public forward_iterator_tag { };
struct random_access_iterator_tag : public bidirectional_iterator_tag { };
// Return Type Categories
struct readable_iterator_tag { };
struct writable_iterator_tag { };
struct mutable_lvalue_iterator_tag : virtual public writable_iterator_tag,
virtual public readable_iterator_tag { };
struct constant_lvalue_iterator_tag : public readable_iterator_tag { };
struct error_iterator_tag { };
// Inherit from iterator_base if your iterator defines its own
// return_category and traversal_category. Otherwise, the "old style"
// iterator category will be mapped to the return_category and
// traversal_category.
struct new_iterator_base { };
namespace detail {
struct iter_traits_from_nested_types {
template <typename Iterator> struct bind {
typedef typename Iterator::value_type value_type;
typedef typename Iterator::reference reference;
typedef typename Iterator::pointer pointer;
typedef typename Iterator::difference_type difference_type;
typedef typename Iterator::return_category return_category;
typedef typename Iterator::traversal_category traversal_category;
};
};
template <typename ValueType>
struct choose_lvalue_return {
typedef typename ct_if<is_const<ValueType>::value,
boost::constant_lvalue_iterator_tag,
boost::mutable_lvalue_iterator_tag>::type type;
};
template <typename Category, typename ValueType>
struct iter_category_to_return {
typedef typename ct_if<
is_convertible<Category*, std::forward_iterator_tag*>::value,
typename choose_lvalue_return<ValueType>::type,
typename ct_if<
is_convertible<Category*, std::input_iterator_tag*>::value,
boost::readable_iterator_tag,
typename ct_if<
is_convertible<Category*, std::output_iterator_tag*>::value,
boost::writable_iterator_tag,
boost::error_iterator_tag
>::type
>::type
>::type type;
};
template <typename Category>
struct iter_category_to_traversal {
typedef typename ct_if<
is_convertible<Category*, std::random_access_iterator_tag*>::value,
boost::random_access_iterator_tag,
typename ct_if<
is_convertible<Category*, std::bidirectional_iterator_tag*>::value,
boost::bidirectional_iterator_tag,
typename ct_if<
is_convertible<Category*, std::forward_iterator_tag*>::value,
boost::forward_iterator_tag,
boost::single_pass_iterator_tag>::type
>::type
>::type type;
};
struct iter_traits_from_old_traits {
template <typename Iterator> class bind {
typedef boost::detail::iterator_traits<Iterator> OldTraits;
typedef typename OldTraits::iterator_category Cat;
public:
typedef typename OldTraits::value_type value_type;
typedef typename OldTraits::reference reference;
typedef typename OldTraits::pointer pointer;
typedef typename OldTraits::difference_type difference_type;
typedef iter_category_to_return<Cat,value_type>::type return_category;
typedef iter_category_to_traversal<Cat>::type traversal_category;
};
};
template <typename Iterator>
class choose_iter_traits {
typedef typename ct_if<is_convertible<Iterator*,
new_iterator_base*>::value,
iter_traits_from_nested_types,
iter_traits_from_old_traits>::type Choice;
public:
typedef typename Choice:: template bind<Iterator> type;
};
} // namespace detail
template <typename Iterator>
class iterator_traits
: public detail::choose_iter_traits<Iterator>::type { };
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <typename T>
struct iterator_traits<T*>
{
typedef T value_type;
typedef T& reference;
typedef T* pointer;
typedef std::ptrdiff_t difference_type;
typedef typename ct_if<is_const<T>::value,
boost::constant_lvalue_iterator_tag,
boost::mutable_lvalue_iterator_tag>::type
return_category;
typedef boost::random_access_iterator_tag traversal_category;
};
#endif
} // namespace boost
#endif // BOOST_ITERATOR_TRAITS_HPP