From 29a34b199d6c2e72a561a4ee05032685b6cc16ea Mon Sep 17 00:00:00 2001 From: Jeremy Siek Date: Tue, 20 Mar 2001 05:12:35 +0000 Subject: [PATCH] new file, fixes shadow_iterator [SVN r9607] --- .../graph/detail/new_iterator_adaptors.hpp | 297 ++++++++++++++++++ .../boost/graph/detail/shadow_iterator.hpp | 4 +- 2 files changed, 299 insertions(+), 2 deletions(-) create mode 100644 include/boost/graph/detail/new_iterator_adaptors.hpp diff --git a/include/boost/graph/detail/new_iterator_adaptors.hpp b/include/boost/graph/detail/new_iterator_adaptors.hpp new file mode 100644 index 00000000..f32a2119 --- /dev/null +++ b/include/boost/graph/detail/new_iterator_adaptors.hpp @@ -0,0 +1,297 @@ +// (C) Copyright David Abrahams 2000. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +// +// (C) Copyright Jeremy Siek 2000. Permission to copy, use, modify, +// sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +// +// Revision History: + +// 20 Mar 2001 Jeremy Siek +// Branched off of old iterator_adaptors.hpp with intention of +// changing this to use the new iterator_traits in +// development. For now the only difference is that the +// conformance checks are removed so that shadow_iterator works. + +#ifndef BOOST_NEW_ITERATOR_ADAPTOR_DWA053000_HPP_ +# define BOOST_NEW_ITERATOR_ADAPTOR_DWA053000_HPP_ + +# include + +namespace boost { + +// This macro definition is only temporary in this file +# if !defined(BOOST_MSVC) +# define BOOST_ARG_DEPENDENT_TYPENAME typename +# else +# define BOOST_ARG_DEPENDENT_TYPENAME +# endif + +//============================================================================ +//new_iterator_adaptor - Adapts a generic piece of data as an iterator. Adaptation +// is especially easy if the data being adapted is itself an iterator +// +// Base - the base (usually iterator) type being wrapped. +// +// Policies - a set of policies determining how the resulting iterator +// works. +// +// Value - if supplied, the value_type of the resulting iterator, unless +// const. If const, a conforming compiler strips constness for the +// value_type. If not supplied, iterator_traits::value_type is used +// +// Reference - the reference type of the resulting iterator, and in +// particular, the result type of operator*(). If not supplied but +// Value is supplied, Value& is used. Otherwise +// iterator_traits::reference is used. +// +// Pointer - the pointer type of the resulting iterator, and in +// particular, the result type of operator->(). If not +// supplied but Value is supplied, Value* is used. Otherwise +// iterator_traits::pointer is used. +// +// Category - the iterator_category of the resulting iterator. If not +// supplied, iterator_traits::iterator_category is used. +// +// Distance - the difference_type of the resulting iterator. If not +// supplied, iterator_traits::difference_type is used. +template ::type, + class Pointer = BOOST_ARG_DEPENDENT_TYPENAME detail::choose_default_argument::type, + class Category = BOOST_ARG_DEPENDENT_TYPENAME detail::choose_default_argument::type, + class Distance = BOOST_ARG_DEPENDENT_TYPENAME detail::choose_default_argument::type + > +struct new_iterator_adaptor : +#ifdef BOOST_RELOPS_AMBIGUITY_BUG + iterator_comparisons< + new_iterator_adaptor, + typename detail::iterator_adaptor_traits_gen::type + > +#else + detail::iterator_adaptor_traits_gen::type +#endif +{ + typedef new_iterator_adaptor self; + public: + typedef typename detail::iterator_adaptor_traits_gen::type Traits; + + typedef typename Traits::difference_type difference_type; + typedef typename Traits::value_type value_type; + typedef typename Traits::pointer pointer; + typedef typename Traits::reference reference; + typedef typename Traits::iterator_category iterator_category; + + typedef Base base_type; + typedef Policies policies_type; + + private: + // checks for category conformance... + + public: + new_iterator_adaptor() { } + + explicit + new_iterator_adaptor(const Base& it, const Policies& p = Policies()) + : m_iter_p(it, p) { + policies().initialize(iter()); + } + + template + new_iterator_adaptor ( + const new_iterator_adaptor& src) + : m_iter_p(src.iter(), src.policies()) + { + policies().initialize(iter()); + } + +#ifdef BOOST_MSVC + // This is required to prevent a bug in how VC++ generates + // the assignment operator for compressed_pair. + new_iterator_adaptor& operator= (const new_iterator_adaptor& x) { + m_iter_p = x.m_iter_p; + return *this; + } +#endif + reference operator*() const { + return policies().dereference(type(), iter()); + } + +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning( disable : 4284 ) +#endif + + typename boost::detail::operator_arrow_result_generator::type + operator->() const + { return detail::operator_arrow(*this, iterator_category()); } + +#ifdef _MSC_VER +# pragma warning(pop) +#endif + + value_type operator[](difference_type n) const + { return *(*this + n); } + + self& operator++() { +#ifdef __MWERKS__ + // Odd bug, MWERKS couldn't deduce the type for the member template + // Workaround by explicitly specifying the type. + policies().increment(iter()); +#else + policies().increment(iter()); +#endif + return *this; + } + + self operator++(int) { self tmp(*this); ++*this; return tmp; } + + self& operator--() { + policies().decrement(iter()); + return *this; + } + + self operator--(int) { self tmp(*this); --*this; return tmp; } + + self& operator+=(difference_type n) { + policies().advance(iter(), n); + return *this; + } + + self& operator-=(difference_type n) { + policies().advance(iter(), -n); + return *this; + } + + base_type base() const { return m_iter_p.first(); } + + // Moved from global scope to avoid ambiguity with the operator-() which + // subtracts iterators from one another. + self operator-(difference_type x) const + { self result(*this); return result -= x; } +private: + compressed_pair m_iter_p; + +public: // implementation details (too many compilers have trouble when these are private). + Policies& policies() { return m_iter_p.second(); } + const Policies& policies() const { return m_iter_p.second(); } + + Base& iter() { return m_iter_p.first(); } + const Base& iter() const { return m_iter_p.first(); } +}; + +template +new_iterator_adaptor +operator+( + new_iterator_adaptor p, + Distance2 x) +{ + return p += x; +} + +template +new_iterator_adaptor +operator+( + Distance2 x, + new_iterator_adaptor p) +{ + return p += x; +} + +template +typename new_iterator_adaptor::difference_type +operator-( + const new_iterator_adaptor& x, + const new_iterator_adaptor& y) +{ + typedef typename new_iterator_adaptor::difference_type difference_type; + return x.policies().distance(type(), y.iter(), x.iter()); +} + +#ifndef BOOST_RELOPS_AMBIGUITY_BUG +template +inline bool +operator==( + const new_iterator_adaptor& x, + const new_iterator_adaptor& y) +{ + return x.policies().equal(x.iter(), y.iter()); +} + +template +inline bool +operator<( + const new_iterator_adaptor& x, + const new_iterator_adaptor& y) +{ + return x.policies().less(x.iter(), y.iter()); +} + +template +inline bool +operator>( + const new_iterator_adaptor& x, + const new_iterator_adaptor& y) +{ + return x.policies().less(y.iter(), x.iter()); +} + +template +inline bool +operator>=( + const new_iterator_adaptor& x, + const new_iterator_adaptor& y) +{ + return !x.policies().less(x.iter(), y.iter()); +} + +template +inline bool +operator<=( + const new_iterator_adaptor& x, + const new_iterator_adaptor& y) +{ + return !x.policies().less(y.iter(), x.iter()); +} + +template +inline bool +operator!=( + const new_iterator_adaptor& x, + const new_iterator_adaptor& y) +{ + return !x.policies().equal(x.iter(), y.iter()); +} +#endif + + +} // namespace boost +# undef BOOST_ARG_DEPENDENT_TYPENAME + + +#endif + + + diff --git a/include/boost/graph/detail/shadow_iterator.hpp b/include/boost/graph/detail/shadow_iterator.hpp index dab90984..153e9d0b 100644 --- a/include/boost/graph/detail/shadow_iterator.hpp +++ b/include/boost/graph/detail/shadow_iterator.hpp @@ -7,7 +7,7 @@ #ifndef BOOST_SHADOW_ITERATOR_HPP #define BOOST_SHADOW_ITERATOR_HPP -#include +#include #include namespace boost { @@ -87,7 +87,7 @@ namespace boost { typedef typename std::iterator_traits::difference_type D; typedef detail::shadow_proxy V; typedef detail::shadow_proxy R; - typedef iterator_adaptor< std::pair, + typedef new_iterator_adaptor< std::pair, detail::shadow_iterator_policies, V, R, V*, std::random_access_iterator_tag, D> type;