From 5e1bc30db9a36c4855ec30a0c45802f21c9e8ba6 Mon Sep 17 00:00:00 2001 From: Jeremy Siek Date: Mon, 5 Feb 2001 05:39:43 +0000 Subject: [PATCH] 1st draft [SVN r8939] --- development/boost/iterator_concepts.hpp | 282 ++++++++++++++++++++++++ development/boost/iterator_traits.hpp | 60 +++++ 2 files changed, 342 insertions(+) create mode 100644 development/boost/iterator_concepts.hpp create mode 100644 development/boost/iterator_traits.hpp diff --git a/development/boost/iterator_concepts.hpp b/development/boost/iterator_concepts.hpp new file mode 100644 index 0000000..acea6e3 --- /dev/null +++ b/development/boost/iterator_concepts.hpp @@ -0,0 +1,282 @@ +#ifndef BOOST_ITERATOR_CONCEPTS_HPP +#define BOOST_ITERATOR_CONCEPTS_HPP + +#include +#include + +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. + + + //=========================================================================== + + template + class ReadableIteratorConcept { + public: + typedef typename boost::iterator_traits::value_type value_type; + typedef typename boost::iterator_traits::reference reference; + typedef typename boost::iterator_traits::return_category + return_category; + + void constraints() { + boost::function_requires< boost::SGIAssignableConcept >(); + boost::function_requires< boost::EqualityComparableConcept >(); + boost::function_requires< boost::DefaultConstructibleConcept >(); + + boost::function_requires< + boost::ConvertibleConcept >(); + + reference r = *i; // or perhaps read(x) + value_type v(r); + boost::ignore_unused_variable_warning(v); + } + Iterator i; + }; + + template + class WritableIteratorConcept { + public: + typedef typename boost::iterator_traits::return_category + return_category; + + void constraints() { + boost::function_requires< boost::SGIAssignableConcept >(); + boost::function_requires< boost::EqualityComparableConcept >(); + boost::function_requires< boost::DefaultConstructibleConcept >(); + + boost::function_requires< + boost::ConvertibleConcept >(); + + *i = v; // an alternative could be something like write(x, v) + } + ValueType v; + Iterator i; + }; + + template + class ConstantLvalueIteratorConcept { + public: + typedef typename boost::iterator_traits::value_type value_type; + typedef typename boost::iterator_traits::reference reference; + typedef typename boost::iterator_traits::return_category + return_category; + + void constraints() { + boost::function_requires< ReadableIteratorConcept >(); + + boost::function_requires< + boost::ConvertibleConcept >(); + + typedef typename boost::require_same::type req; + + reference v = *i; + boost::ignore_unused_variable_warning(v); + } + Iterator i; + }; + + template + class MutableLvalueIteratorConcept { + public: + typedef typename boost::iterator_traits::value_type value_type; + typedef typename boost::iterator_traits::reference reference; + typedef typename boost::iterator_traits::return_category + return_category; + + void constraints() { + boost::function_requires< ReadableIteratorConcept >(); + boost::function_requires< WritableIteratorConcept >(); + + boost::function_requires< + boost::ConvertibleConcept >(); + + typedef typename boost::require_same::type req; + + reference v = *i; + boost::ignore_unused_variable_warning(v); + } + Iterator i; + }; + + //=========================================================================== + + template + class SinglePassIteratorConcept { + public: + typedef typename boost::iterator_traits::motion_category + motion_category; + typedef typename boost::iterator_traits::difference_type + difference_type; + + void constraints() { + boost::function_requires< boost::SGIAssignableConcept >(); + boost::function_requires< boost::EqualityComparableConcept >(); + boost::function_requires< boost::DefaultConstructibleConcept >(); + + boost::function_requires< + boost::ConvertibleConcept >(); + + // difference_type must be a signed integral type + + ++i; + (void)i++; + } + + Iterator i; + }; + + template + class ForwardIteratorConcept { + public: + typedef typename boost::iterator_traits::motion_category + motion_category; + + void constraints() { + boost::function_requires< SinglePassIteratorConcept >(); + + boost::function_requires< + boost::ConvertibleConcept >(); + } + }; + + template + class BidirectionalIteratorConcept { + public: + typedef typename boost::iterator_traits::motion_category + motion_category; + + void constraints() { + boost::function_requires< ForwardIteratorConcept >(); + + boost::function_requires< + boost::ConvertibleConcept >(); + + --i; + (void)i--; + } + Iterator i; + }; + + template + class RandomAccessIteratorConcept { + public: + typedef typename boost::iterator_traits::motion_category + motion_category; + typedef typename boost::iterator_traits::difference_type + difference_type; + + void constraints() { + boost::function_requires< BidirectionalIteratorConcept >(); + + boost::function_requires< + boost::ConvertibleConcept >(); + + i += n; + i = i + n; + i = n + i; + i -= n; + i = i - n; + n = i - j; + } + difference_type n; + Iterator i, j; + }; + + //=========================================================================== + + template + class ReadableRandomAccessIteratorConcept { + public: + typedef typename boost::iterator_traits::value_type value_type; + typedef typename boost::iterator_traits::reference reference; + typedef typename boost::iterator_traits::difference_type + difference_type; + + void constraints() { + boost::function_requires< RandomAccessIteratorConcept >(); + boost::function_requires< ReadableIteratorConcept >(); + + reference r = i[n]; + value_type v(r); + boost::ignore_unused_variable_warning(v); + } + difference_type n; + Iterator i; + }; + + template + class WritableRandomAccessIteratorConcept { + public: + typedef typename boost::iterator_traits::value_type value_type; + typedef typename boost::iterator_traits::difference_type + difference_type; + + void constraints() { + boost::function_requires< RandomAccessIteratorConcept >(); + boost::function_requires< WritableIteratorConcept >(); + + i[n] = v; + boost::ignore_unused_variable_warning(v); + } + difference_type n; + value_type v; + Iterator i; + }; + + template + class ConstantLvalueRandomAccessIteratorConcept { + public: + typedef typename boost::iterator_traits::value_type value_type; + typedef typename boost::iterator_traits::reference reference; + typedef typename boost::iterator_traits::difference_type + difference_type; + + void constraints() { + boost::function_requires< RandomAccessIteratorConcept >(); + boost::function_requires< ReadableIteratorConcept >(); + + typedef typename boost::require_same::type req; + + reference v = i[n]; + boost::ignore_unused_variable_warning(v); + } + difference_type n; + value_type v; + Iterator i; + }; + + template + class MutableLvalueRandomAccessIteratorConcept { + public: + typedef typename boost::iterator_traits::value_type value_type; + typedef typename boost::iterator_traits::reference reference; + typedef typename boost::iterator_traits::difference_type + difference_type; + + void constraints() { + boost::function_requires< RandomAccessIteratorConcept >(); + boost::function_requires< WritableIteratorConcept >(); + boost::function_requires< ReadableIteratorConcept >(); + + typedef typename boost::require_same::type req; + + reference v = i[n]; + boost::ignore_unused_variable_warning(v); + } + difference_type n; + value_type v; + Iterator i; + }; + +} // namespace boost_concepts + + +#endif // BOOST_ITERATOR_CONCEPTS_HPP diff --git a/development/boost/iterator_traits.hpp b/development/boost/iterator_traits.hpp new file mode 100644 index 0000000..585f194 --- /dev/null +++ b/development/boost/iterator_traits.hpp @@ -0,0 +1,60 @@ +#ifndef BOOST_ITERATOR_TRAITS_HPP +#define BOOST_ITERATOR_TRAITS_HPP + +#include +#include + +namespace boost { + + template + struct iterator_traits { + 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::motion_category motion_category; + }; + + // Motion 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 { }; + +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) + + namespace detail { + template + struct pointer_return_category { + typedef constant_lvalue_iterator_tag type; + }; + template <> + struct pointer_return_category { + typedef mutable_lvalue_iterator_tag type; + }; + } // namespace detail + + template + struct iterator_traits { + typedef T value_type; + typedef T& reference; + typedef T* pointer; + typedef std::ptrdiff_t difference_type; + typedef typename detail::pointer_return_category::value>::type + return_category; + typedef random_access_iterator_tag motion_category; + }; + +#endif + +} // namespace boost + +#endif // BOOST_ITERATOR_TRAITS_HPP