From e1b64d45e2f4a35403d52e348a3cfc63304d2c0a Mon Sep 17 00:00:00 2001 From: Jeremy Siek Date: Sun, 14 Jan 2001 01:14:39 +0000 Subject: [PATCH] MIPSpro port, avoid using operators that are not defined [SVN r8584] --- include/boost/pending/iterator_adaptors.hpp | 54 ++++++++++++++++----- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/include/boost/pending/iterator_adaptors.hpp b/include/boost/pending/iterator_adaptors.hpp index 7b5c6c4..8838b9b 100644 --- a/include/boost/pending/iterator_adaptors.hpp +++ b/include/boost/pending/iterator_adaptors.hpp @@ -213,6 +213,45 @@ inline bool operator<=(const iterator_comparisons& xb, } #endif +//============================================================================ +// Some compilers (SGI MIPSpro) instantiate/compile member functions +// whether or not they are used. The following functions make sure that +// when the base iterators do not support particular operators, those +// operators do not get used. + +namespace detail { + + // Dummy version for iterators that don't support member access + template + inline typename Iter::pointer + operator_arrow(const Iter&, Cat) { + typedef typename Iter::pointer Pointer; + return Pointer(); + } + // Real version + template + inline typename Iter::pointer + operator_arrow(const Iter& i, std::forward_iterator_tag) { + return &(*i); + } + + // Dummy version for iterators that don't support member access + template + inline void advance_impl(const Iter&, Diff, Cat) { } + + // Real version + template + inline typename Iter::pointer + advance_impl(const Iter& i, Diff n, std::random_access_iterator_tag) { +#ifdef __MWERKS__ + i.policies().advance(iter(), n); +#else + i.policies().advance(iter(), n); +#endif + } + +} // namespace detail + //============================================================================ // iterator_adaptor - A generalized adaptor around an existing // iterator, which is itself an iterator @@ -274,7 +313,7 @@ public: #endif pointer operator->() const - { return &*this; } + { return detail::operator_arrow(*this, iterator_category()); } #ifdef _MSC_VER # pragma warning(pop) @@ -308,20 +347,12 @@ public: Self operator--(int) { Self tmp(*this); --*this; return tmp; } Self& operator+=(difference_type n) { -#ifdef __MWERKS__ - policies().advance(iter(), n); -#else - policies().advance(iter(), n); -#endif + detail::advance_impl(*this, n, iterator_category()); return *this; } Self& operator-=(difference_type n) { -#ifdef __MWERKS__ - policies().advance(iter(), -n); -#else - policies().advance(iter(), -n); -#endif + detail::advance_impl(*this, -n, iterator_category()); return *this; } @@ -337,6 +368,7 @@ public: // too many compilers have trouble when these are private. const Iterator& iter() const { return m_iter_p.first(); } }; + template iterator_adaptor operator-(iterator_adaptor p, const typename Traits::difference_type x)