diff --git a/development/libs/iterator/iterator_categories.htm b/development/libs/iterator/iterator_categories.htm new file mode 100644 index 0000000..83c29e5 --- /dev/null +++ b/development/libs/iterator/iterator_categories.htm @@ -0,0 +1,160 @@ + + +
++The boost::traversal_category and +boost::return_category traits classes provides access to the +category tags for iterators that model the Boost Iterator Concepts, which are a +replacement for the iterator requirements in the C++ standard. The +other associated types of the Boost iterator concepts are accessed +through the std::iterator_traits class. + +
+An important feature of the boost::traversal_category and +boost::return_category classes is that they are backwards +compatible, i.e., they automatically work for iterators for which +there are valid definitions of std::iterator_traits. The old +iterator_category is mapped to the appropriate traversal and +return categories. + +
+When creating a new iterator type that is meant to work with +boost::traversal_category and +boost::return_category, you can either create a +specialization of these classes for your iterator type, or you can +provide all the necessary associated types as nested typedefs. In +this case, your iterator class will need to inherit from +new_iterator_base to let the category traits know +that it will be able to find typedefs for traversal_category +and return_category in you iterator class. + + +Each of the new iterator requirements will need a category tag. + +
+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 : 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 { }; + +} ++ +
+The following is pseudo-code for the iterator category traits classes. + +
+namespace boost { + + // 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 { }; + + template <typename Iterator> + struct return_category + { + // Pseudo-code + if (Iterator inherits from new_iterator_base) { + typedef typename Iterator::return_category type; + } else { + typedef std::iterator_traits<Iterator> OldTraits; + typedef typename OldTraits::iterator_category Cat; + if (Cat inherits from std::forward_iterator_tag) + if (is-const(T)) + typedef boost::constant_lvalue_iterator_tag type; + else + typedef boost::mutable_lvalue_iterator_tag type; + else if (Cat inherits from std::input_iterator_tag) + typedef boost::readable_iterator_tag type; + else if (Cat inherits from std::output_iterator_tag) + typedef boost::writable_iterator_tag type; + } + }; + + template <typename T> + struct return_category<T*> + { + // Pseudo-code + if (is-const(T)) + typedef boost::constant_lvalue_iterator_tag type; + else + typedef boost::mutable_lvalue_iterator_tag type; + }; + + template <typename Iterator> + struct traversal_category + { + // Pseudo-code + if (Iterator inherits from new_iterator_base) { + typedef typename Iterator::traversal_category type; + } else { + typedef std::iterator_traits<Iterator> OldTraits; + typedef typename OldTraits::iterator_category Cat; + + if (Cat inherits from std::random_access_iterator_tag) + typedef boost::random_access_traversal_tag type; + else if (Cat inherits from std::bidirectional_iterator_tag) + typedef boost::bidirectional_traversal_tag type; + else if (Cat inherits from std::forward_iterator_tag) + typedef boost::forward_traversal_tag type; + } + }; + + template <typename T> + struct traversal_category<T*> + { + typedef boost::random_access_traversal_tag type; + }; + +} ++ +