285b36d6a5
2003-11-11 Doug Gregor <gregod@cs.rpi.edu> * docs/html/debug.html: Document libstdc++ debug mode. * docs/html/debug_mode.html: Document libstdc++ debug mode design. * docs/html/test.html: Document how to test under debug mode. * docs/html/17_intro/howto.html: Document debug-mode macros. * include/Makefile.am: Install debug-mode headers. * src/Makefile.am: Include debug.cc. * include/bits/basic_string.tcc: (basic_string::_S_construct): Fix NULL pointer check. (__is_null_pointer): New. Add precondition annotations. * include/bits/stream_iterator.h (istream_iterator, ostream_iterator): Added precondition annotations. * include/bits/streambuf_iterator.h (istreambuf_iterator): Ditto. * include/bits/stl_queue.h (queue, priority_queue): Ditto. * include/bits/stl_stack.h (stack): Ditto. * include/bits/basic_string.h (basic_string): Ditto. * include/bits/basic_string.tcc (basic_string): Ditto. * include/std/std_memory.h (auto_ptr): Ditto. * include/std/std_valarray.h (valarray): Ditto. * include/bits/stl_algo.h: Added algorithm precondition annotations. * include/bits/stl_algobase.h: Added algorithm precondition annotations. * include/bits/stl_numeric.h: Ditto. * include/ext/algorithm: Added algorithm precondition annotations. (__is_heap): Moved away from here. * include/bits/stl_heap.h: Added algorithm precondition annotations. (__is_heap): Moved to the top of this file. (__is_heap): Added iterator range overloads. * testsuite/20_util/auto_ptr_neg.cc: Fix line numbers to match up with changes in std_memory.h. * testsuite/23_containers/list/operators/4.cc: Don't verify performance guarantees when in debug mode. * testsuite/23_containers/bitset/invalidation/1.cc: New. * testsuite/23_containers/deque/invalidation/1.cc: New. * testsuite/23_containers/deque/invalidation/2.cc: New. * testsuite/23_containers/deque/invalidation/3.cc: New. * testsuite/23_containers/deque/invalidation/4.cc: New. * testsuite/23_containers/list/invalidation/1.cc: New. * testsuite/23_containers/list/invalidation/2.cc: New. * testsuite/23_containers/list/invalidation/3.cc: New. * testsuite/23_containers/list/invalidation/4.cc: New. * testsuite/23_containers/map/invalidation/1.cc: New. * testsuite/23_containers/map/invalidation/2.cc: New. * testsuite/23_containers/multimap/invalidation/1.cc: New. * testsuite/23_containers/multimap/invalidation/2.cc: New. * testsuite/23_containers/multiset/invalidation/1.cc: New. * testsuite/23_containers/multiset/invalidation/2.cc: New. * testsuite/23_containers/set/invalidation/1.cc: New. * testsuite/23_containers/set/invalidation/2.cc: New. * testsuite/23_containers/vector/invalidation/1.cc: New. * testsuite/23_containers/vector/invalidation/2.cc: New. * testsuite/23_containers/vector/invalidation/3.cc: New. * testsuite/23_containers/vector/invalidation/4.cc: New. * testsuite/25_algorithms/heap.cc: Don't verify performance guarantees when in debug mode. * include/debug/bitset: New. * include/debug/debug.h: New. * include/debug/deque: New. * include/debug/formatter.h: New. * include/debug/hash_map: New. * include/debug/hash_map.h: New. * include/debug/hash_multimap.h: New. * include/debug/hash_set: New. * include/debug/hash_set.h: New. * include/debug/hash_multiset.h: New. * include/debug/list: New. * include/debug/map: New. * include/debug/map.h: New. * include/debug/multimap.h: New. * include/debug/multiset.h: New. * include/debug/safe_base.h: New. * include/debug/safe_iterator.h: New. * include/debug/safe_iterator.tcc: New. * include/debug/safe_sequence.h: New. * include/debug/set: New. * include/debug/set.h: New. * include/debug/string: New. * include/debug/vector: New. * src/debug.cc: New. * config/linker-map.gnu: Add debug mode symbols. 2003-11-11 Benjamin Kosnik <bkoz@redhat.com> * src/string-inst.cc: Tweak namespaces. * src/misc-inst.cc: Same. * docs/html/debug.html: Edits. * config/link-map.gnu: Remove cruft. * include/bits/c++config: Add in namespace associations. * include/std/std_bitset.h: Adjust namespace to __gnu_norm, comment tweaks. * include/bits/deque.tcc: Same. * include/bits/list.tcc: Same. * include/bits/stl_bvector.h: Same. * include/bits/stl_deque.h: Same. * include/bits/stl_list.h: Same. * include/bits/stl_map.h: Same. * include/bits/stl_multimap.h: Same. * include/bits/stl_multiset.h: Same. * include/bits/stl_set.h: Same. * include/bits/stl_vector.h: Same. * include/bits/vector.tcc: Same. * include/std/std_algorithm.h: Remove markup comments. * include/std/std_functional.h: Same. * include/std/std_iterator.h: Same. * include/std/std_numeric.h: Same. * include/std/std_utility.h: Same. * include/bits/stl_queue.h: Formatting tweaks. * include/bits/stl_stack.h: Same. * include/std/std_deque.h: Include debugging version in debug mode. * include/std/std_list.h: Same. * include/std/std_map.h: Same. * include/std/std_set.h: Same. * include/std/std_vector.h: Same. * include/std/std_queue.h: Use deque, vector. * include/std/std_stack.h: Same. From-SVN: r73459
608 lines
20 KiB
C++
608 lines
20 KiB
C++
// Safe iterator implementation -*- C++ -*-
|
|
|
|
// Copyright (C) 2003
|
|
// Free Software Foundation, Inc.
|
|
//
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
// software; you can redistribute it and/or modify it under the
|
|
// terms of the GNU General Public License as published by the
|
|
// Free Software Foundation; either version 2, or (at your option)
|
|
// any later version.
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
// with this library; see the file COPYING. If not, write to the Free
|
|
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
// USA.
|
|
|
|
// As a special exception, you may use this file as part of a free software
|
|
// library without restriction. Specifically, if other files instantiate
|
|
// templates or use macros or inline functions from this file, or you compile
|
|
// this file and link it with other files to produce an executable, this
|
|
// file does not by itself cause the resulting executable to be covered by
|
|
// the GNU General Public License. This exception does not however
|
|
// invalidate any other reasons why the executable file might be covered by
|
|
// the GNU General Public License.
|
|
|
|
#ifndef _GLIBCXX_DEBUG_SAFE_ITERATOR_H
|
|
#define _GLIBCXX_DEBUG_SAFE_ITERATOR_H 1
|
|
|
|
#include <bits/stl_pair.h>
|
|
#include <debug/debug.h>
|
|
#include <debug/formatter.h>
|
|
#include <debug/safe_base.h>
|
|
|
|
namespace __gnu_debug
|
|
{
|
|
/** Iterators that derive from _Safe_iterator_base but that aren't
|
|
* _Safe_iterators can be determined singular or non-singular via
|
|
* _Safe_iterator_base.
|
|
*/
|
|
inline bool __check_singular_aux(const _Safe_iterator_base* __x)
|
|
{ return __x->_M_singular(); }
|
|
|
|
/** \brief Safe iterator wrapper.
|
|
*
|
|
* The class template %_Safe_iterator is a wrapper around an
|
|
* iterator that tracks the iterator's movement among sequences and
|
|
* checks that operations performed on the "safe" iterator are
|
|
* legal. In additional to the basic iterator operations (which are
|
|
* validated, and then passed to the underlying iterator),
|
|
* %_Safe_iterator has member functions for iterator invalidation,
|
|
* attaching/detaching the iterator from sequences, and querying
|
|
* the iterator's state.
|
|
*/
|
|
template<typename _Iterator, typename _Sequence>
|
|
class _Safe_iterator : public _Safe_iterator_base
|
|
{
|
|
typedef _Safe_iterator _Self;
|
|
|
|
/** The precision to which we can calculate the distance between
|
|
* two iterators.
|
|
*/
|
|
enum _Distance_precision
|
|
{
|
|
__dp_equality, //< Can compare iterator equality, only
|
|
__dp_sign, //< Can determine equality and ordering
|
|
__dp_exact //< Can determine distance precisely
|
|
};
|
|
|
|
/// The underlying iterator
|
|
_Iterator _M_current;
|
|
|
|
/// Determine if this is a constant iterator.
|
|
bool
|
|
_M_constant() const
|
|
{
|
|
typedef typename _Sequence::const_iterator const_iterator;
|
|
return __is_same<const_iterator, _Safe_iterator>::value;
|
|
}
|
|
|
|
typedef iterator_traits<_Iterator> _Traits;
|
|
|
|
public:
|
|
typedef typename _Traits::iterator_category iterator_category;
|
|
typedef typename _Traits::value_type value_type;
|
|
typedef typename _Traits::difference_type difference_type;
|
|
typedef typename _Traits::reference reference;
|
|
typedef typename _Traits::pointer pointer;
|
|
|
|
/// @post the iterator is singular and unattached
|
|
_Safe_iterator() : _M_current() { }
|
|
|
|
/**
|
|
* @brief Safe iterator construction from an unsafe iterator and
|
|
* its sequence.
|
|
*
|
|
* @pre @p seq is not NULL
|
|
* @post this is not singular
|
|
*/
|
|
_Safe_iterator(const _Iterator& __i, const _Sequence* __seq)
|
|
: _Safe_iterator_base(__seq, _M_constant()), _M_current(__i)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
|
|
_M_message(__msg_init_singular)
|
|
._M_iterator(*this, "this"));
|
|
}
|
|
|
|
/**
|
|
* @brief Copy construction.
|
|
* @pre @p x is not singular
|
|
*/
|
|
_Safe_iterator(const _Safe_iterator& __x)
|
|
: _Safe_iterator_base(__x, _M_constant()), _M_current(__x._M_current)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(!__x._M_singular(),
|
|
_M_message(__msg_init_copy_singular)
|
|
._M_iterator(*this, "this")
|
|
._M_iterator(__x, "other"));
|
|
}
|
|
|
|
/**
|
|
* @brief Converting constructor from a mutable iterator to a
|
|
* constant iterator.
|
|
*
|
|
* @pre @p x is not singular
|
|
*/
|
|
template<typename _MutableIterator>
|
|
_Safe_iterator(const _Safe_iterator<_MutableIterator, _Sequence>& __x)
|
|
: _Safe_iterator_base(__x, _M_constant()), _M_current(__x.base())
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(!__x._M_singular(),
|
|
_M_message(__msg_init_const_singular)
|
|
._M_iterator(*this, "this")
|
|
._M_iterator(__x, "other"));
|
|
}
|
|
|
|
/**
|
|
* @brief Copy assignment.
|
|
* @pre @p x is not singular
|
|
*/
|
|
_Safe_iterator&
|
|
operator=(const _Safe_iterator& __x)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(!__x._M_singular(),
|
|
_M_message(__msg_copy_singular)
|
|
._M_iterator(*this, "this")
|
|
._M_iterator(__x, "other"));
|
|
_M_current = __x._M_current;
|
|
this->_M_attach(static_cast<_Sequence*>(__x._M_sequence));
|
|
return *this;
|
|
}
|
|
|
|
/**
|
|
* @brief Iterator dereference.
|
|
* @pre iterator is dereferenceable
|
|
*/
|
|
reference
|
|
operator*() const
|
|
{
|
|
|
|
_GLIBCXX_DEBUG_VERIFY(this->_M_dereferenceable(),
|
|
_M_message(__msg_bad_deref)
|
|
._M_iterator(*this, "this"));
|
|
return *_M_current;
|
|
}
|
|
|
|
/**
|
|
* @brief Iterator dereference.
|
|
* @pre iterator is dereferenceable
|
|
* @todo Make this correct w.r.t. iterators that return proxies
|
|
* @todo Use addressof() instead of & operator
|
|
*/
|
|
pointer
|
|
operator->() const
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(this->_M_dereferenceable(),
|
|
_M_message(__msg_bad_deref)
|
|
._M_iterator(*this, "this"));
|
|
return &*_M_current;
|
|
}
|
|
|
|
// ------ Input iterator requirements ------
|
|
/**
|
|
* @brief Iterator preincrement
|
|
* @pre iterator is incrementable
|
|
*/
|
|
_Safe_iterator&
|
|
operator++()
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(this->_M_incrementable(),
|
|
_M_message(__msg_bad_inc)
|
|
._M_iterator(*this, "this"));
|
|
++_M_current;
|
|
return *this;
|
|
}
|
|
|
|
/**
|
|
* @brief Iterator postincrement
|
|
* @pre iterator is incrementable
|
|
*/
|
|
_Safe_iterator
|
|
operator++(int)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(this->_M_incrementable(),
|
|
_M_message(__msg_bad_inc)
|
|
._M_iterator(*this, "this"));
|
|
_Safe_iterator __tmp(*this);
|
|
++_M_current;
|
|
return __tmp;
|
|
}
|
|
|
|
// ------ Bidirectional iterator requirements ------
|
|
/**
|
|
* @brief Iterator predecrement
|
|
* @pre iterator is decrementable
|
|
*/
|
|
_Safe_iterator&
|
|
operator--()
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(this->_M_decrementable(),
|
|
_M_message(__msg_bad_dec)
|
|
._M_iterator(*this, "this"));
|
|
--_M_current;
|
|
return *this;
|
|
}
|
|
|
|
/**
|
|
* @brief Iterator postdecrement
|
|
* @pre iterator is decrementable
|
|
*/
|
|
_Safe_iterator
|
|
operator--(int)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(this->_M_decrementable(),
|
|
_M_message(__msg_bad_dec)
|
|
._M_iterator(*this, "this"));
|
|
_Safe_iterator __tmp(*this);
|
|
--_M_current;
|
|
return __tmp;
|
|
}
|
|
|
|
// ------ Random access iterator requirements ------
|
|
reference
|
|
operator[](const difference_type& __n) const
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(this->_M_can_advance(__n)
|
|
&& this->_M_can_advance(__n+1),
|
|
_M_message(__msg_iter_subscript_oob)
|
|
._M_iterator(*this)._M_integer(__n));
|
|
|
|
return _M_current[__n];
|
|
}
|
|
|
|
_Safe_iterator&
|
|
operator+=(const difference_type& __n)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(this->_M_can_advance(__n),
|
|
_M_message(__msg_advance_oob)
|
|
._M_iterator(*this)._M_integer(__n));
|
|
_M_current += __n;
|
|
return *this;
|
|
}
|
|
|
|
_Safe_iterator
|
|
operator+(const difference_type& __n) const
|
|
{
|
|
_Safe_iterator __tmp(*this);
|
|
__tmp += __n;
|
|
return __tmp;
|
|
}
|
|
|
|
_Safe_iterator&
|
|
operator-=(const difference_type& __n)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(this->_M_can_advance(-__n),
|
|
_M_message(__msg_retreat_oob)
|
|
._M_iterator(*this)._M_integer(__n));
|
|
_M_current += -__n;
|
|
return *this;
|
|
}
|
|
|
|
_Safe_iterator
|
|
operator-(const difference_type& __n) const
|
|
{
|
|
_Safe_iterator __tmp(*this);
|
|
__tmp -= __n;
|
|
return __tmp;
|
|
}
|
|
|
|
// ------ Utilities ------
|
|
/**
|
|
* @brief Return the underlying iterator
|
|
*/
|
|
_Iterator
|
|
base() const { return _M_current; }
|
|
|
|
/**
|
|
* @brief Conversion to underlying non-debug iterator to allow
|
|
* better interaction with non-debug containers.
|
|
*/
|
|
operator _Iterator() const { return _M_current; }
|
|
|
|
/** Attach iterator to the given sequence. */
|
|
void
|
|
_M_attach(const _Sequence* __seq)
|
|
{
|
|
_Safe_iterator_base::_M_attach(const_cast<_Sequence*>(__seq),
|
|
_M_constant());
|
|
}
|
|
|
|
/** Invalidate the iterator, making it singular. */
|
|
void
|
|
_M_invalidate();
|
|
|
|
/// Is the iterator dereferenceable?
|
|
bool
|
|
_M_dereferenceable() const
|
|
{ return !this->_M_singular() && !_M_is_end(); }
|
|
|
|
/// Is the iterator incrementable?
|
|
bool
|
|
_M_incrementable() const { return this->_M_dereferenceable(); }
|
|
|
|
// Is the iterator decrementable?
|
|
bool
|
|
_M_decrementable() const { return !_M_singular() && !_M_is_begin(); }
|
|
|
|
// Can we advance the iterator @p __n steps (@p __n may be negative)
|
|
bool
|
|
_M_can_advance(const difference_type& __n) const;
|
|
|
|
// Is the iterator range [*this, __rhs) valid?
|
|
template<typename _Other>
|
|
bool
|
|
_M_valid_range(const _Safe_iterator<_Other, _Sequence>& __rhs) const;
|
|
|
|
// The sequence this iterator references.
|
|
const _Sequence*
|
|
_M_get_sequence() const
|
|
{ return static_cast<const _Sequence*>(_M_sequence); }
|
|
|
|
/** Determine the distance between two iterators with some known
|
|
* precision.
|
|
*/
|
|
template<typename _Iterator1, typename _Iterator2>
|
|
static pair<difference_type, _Distance_precision>
|
|
_M_get_distance(const _Iterator1& __lhs, const _Iterator2& __rhs)
|
|
{
|
|
typedef typename iterator_traits<_Iterator1>::iterator_category
|
|
_Category;
|
|
return _M_get_distance(__lhs, __rhs, _Category());
|
|
}
|
|
|
|
template<typename _Iterator1, typename _Iterator2>
|
|
static pair<difference_type, _Distance_precision>
|
|
_M_get_distance(const _Iterator1& __lhs, const _Iterator2& __rhs,
|
|
std::random_access_iterator_tag)
|
|
{
|
|
return std::make_pair(__rhs.base() - __lhs.base(), __dp_exact);
|
|
}
|
|
|
|
template<typename _Iterator1, typename _Iterator2>
|
|
static pair<difference_type, _Distance_precision>
|
|
_M_get_distance(const _Iterator1& __lhs, const _Iterator2& __rhs,
|
|
std::forward_iterator_tag)
|
|
{
|
|
return std::make_pair(__lhs.base() == __rhs.base()? 0 : 1,
|
|
__dp_equality);
|
|
}
|
|
|
|
/// Is this iterator equal to the sequence's begin() iterator?
|
|
bool _M_is_begin() const
|
|
{ return *this == static_cast<const _Sequence*>(_M_sequence)->begin(); }
|
|
|
|
/// Is this iterator equal to the sequence's end() iterator?
|
|
bool _M_is_end() const
|
|
{ return *this == static_cast<const _Sequence*>(_M_sequence)->end(); }
|
|
};
|
|
|
|
template<typename _IteratorL, typename _IteratorR, typename _Sequence>
|
|
inline bool
|
|
operator==(const _Safe_iterator<_IteratorL, _Sequence>& __lhs,
|
|
const _Safe_iterator<_IteratorR, _Sequence>& __rhs)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(! __lhs._M_singular() && ! __rhs._M_singular(),
|
|
_M_message(__msg_iter_compare_bad)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
_GLIBCXX_DEBUG_VERIFY(__lhs._M_can_compare(__rhs),
|
|
_M_message(__msg_compare_different)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
return __lhs.base() == __rhs.base();
|
|
}
|
|
|
|
template<typename _Iterator, typename _Sequence>
|
|
inline bool
|
|
operator==(const _Safe_iterator<_Iterator, _Sequence>& __lhs,
|
|
const _Safe_iterator<_Iterator, _Sequence>& __rhs)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(! __lhs._M_singular() && ! __rhs._M_singular(),
|
|
_M_message(__msg_iter_compare_bad)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
_GLIBCXX_DEBUG_VERIFY(__lhs._M_can_compare(__rhs),
|
|
_M_message(__msg_compare_different)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
return __lhs.base() == __rhs.base();
|
|
}
|
|
|
|
template<typename _IteratorL, typename _IteratorR, typename _Sequence>
|
|
inline bool
|
|
operator!=(const _Safe_iterator<_IteratorL, _Sequence>& __lhs,
|
|
const _Safe_iterator<_IteratorR, _Sequence>& __rhs)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(! __lhs._M_singular() && ! __rhs._M_singular(),
|
|
_M_message(__msg_iter_compare_bad)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
_GLIBCXX_DEBUG_VERIFY(__lhs._M_can_compare(__rhs),
|
|
_M_message(__msg_compare_different)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
return __lhs.base() != __rhs.base();
|
|
}
|
|
|
|
template<typename _Iterator, typename _Sequence>
|
|
inline bool
|
|
operator!=(const _Safe_iterator<_Iterator, _Sequence>& __lhs,
|
|
const _Safe_iterator<_Iterator, _Sequence>& __rhs)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(! __lhs._M_singular() && ! __rhs._M_singular(),
|
|
_M_message(__msg_iter_compare_bad)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
_GLIBCXX_DEBUG_VERIFY(__lhs._M_can_compare(__rhs),
|
|
_M_message(__msg_compare_different)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
return __lhs.base() != __rhs.base();
|
|
}
|
|
|
|
template<typename _IteratorL, typename _IteratorR, typename _Sequence>
|
|
inline bool
|
|
operator<(const _Safe_iterator<_IteratorL, _Sequence>& __lhs,
|
|
const _Safe_iterator<_IteratorR, _Sequence>& __rhs)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(! __lhs._M_singular() && ! __rhs._M_singular(),
|
|
_M_message(__msg_iter_order_bad)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
_GLIBCXX_DEBUG_VERIFY(__lhs._M_can_compare(__rhs),
|
|
_M_message(__msg_order_different)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
return __lhs.base() < __rhs.base();
|
|
}
|
|
|
|
template<typename _Iterator, typename _Sequence>
|
|
inline bool
|
|
operator<(const _Safe_iterator<_Iterator, _Sequence>& __lhs,
|
|
const _Safe_iterator<_Iterator, _Sequence>& __rhs)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(! __lhs._M_singular() && ! __rhs._M_singular(),
|
|
_M_message(__msg_iter_order_bad)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
_GLIBCXX_DEBUG_VERIFY(__lhs._M_can_compare(__rhs),
|
|
_M_message(__msg_order_different)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
return __lhs.base() < __rhs.base();
|
|
}
|
|
|
|
template<typename _IteratorL, typename _IteratorR, typename _Sequence>
|
|
inline bool
|
|
operator<=(const _Safe_iterator<_IteratorL, _Sequence>& __lhs,
|
|
const _Safe_iterator<_IteratorR, _Sequence>& __rhs)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(! __lhs._M_singular() && ! __rhs._M_singular(),
|
|
_M_message(__msg_iter_order_bad)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
_GLIBCXX_DEBUG_VERIFY(__lhs._M_can_compare(__rhs),
|
|
_M_message(__msg_order_different)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
return __lhs.base() <= __rhs.base();
|
|
}
|
|
|
|
template<typename _Iterator, typename _Sequence>
|
|
inline bool
|
|
operator<=(const _Safe_iterator<_Iterator, _Sequence>& __lhs,
|
|
const _Safe_iterator<_Iterator, _Sequence>& __rhs)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(! __lhs._M_singular() && ! __rhs._M_singular(),
|
|
_M_message(__msg_iter_order_bad)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
_GLIBCXX_DEBUG_VERIFY(__lhs._M_can_compare(__rhs),
|
|
_M_message(__msg_order_different)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
return __lhs.base() <= __rhs.base();
|
|
}
|
|
|
|
template<typename _IteratorL, typename _IteratorR, typename _Sequence>
|
|
inline bool
|
|
operator>(const _Safe_iterator<_IteratorL, _Sequence>& __lhs,
|
|
const _Safe_iterator<_IteratorR, _Sequence>& __rhs)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(! __lhs._M_singular() && ! __rhs._M_singular(),
|
|
_M_message(__msg_iter_order_bad)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
_GLIBCXX_DEBUG_VERIFY(__lhs._M_can_compare(__rhs),
|
|
_M_message(__msg_order_different)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
return __lhs.base() > __rhs.base();
|
|
}
|
|
|
|
template<typename _Iterator, typename _Sequence>
|
|
inline bool
|
|
operator>(const _Safe_iterator<_Iterator, _Sequence>& __lhs,
|
|
const _Safe_iterator<_Iterator, _Sequence>& __rhs)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(! __lhs._M_singular() && ! __rhs._M_singular(),
|
|
_M_message(__msg_iter_order_bad)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
_GLIBCXX_DEBUG_VERIFY(__lhs._M_can_compare(__rhs),
|
|
_M_message(__msg_order_different)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
return __lhs.base() > __rhs.base();
|
|
}
|
|
|
|
template<typename _IteratorL, typename _IteratorR, typename _Sequence>
|
|
inline bool
|
|
operator>=(const _Safe_iterator<_IteratorL, _Sequence>& __lhs,
|
|
const _Safe_iterator<_IteratorR, _Sequence>& __rhs)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(! __lhs._M_singular() && ! __rhs._M_singular(),
|
|
_M_message(__msg_iter_order_bad)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
_GLIBCXX_DEBUG_VERIFY(__lhs._M_can_compare(__rhs),
|
|
_M_message(__msg_order_different)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
return __lhs.base() >= __rhs.base();
|
|
}
|
|
|
|
template<typename _Iterator, typename _Sequence>
|
|
inline bool
|
|
operator>=(const _Safe_iterator<_Iterator, _Sequence>& __lhs,
|
|
const _Safe_iterator<_Iterator, _Sequence>& __rhs)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(! __lhs._M_singular() && ! __rhs._M_singular(),
|
|
_M_message(__msg_iter_order_bad)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
_GLIBCXX_DEBUG_VERIFY(__lhs._M_can_compare(__rhs),
|
|
_M_message(__msg_order_different)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
return __lhs.base() >= __rhs.base();
|
|
}
|
|
|
|
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
// According to the resolution of DR179 not only the various comparison
|
|
// operators but also operator- must accept mixed iterator/const_iterator
|
|
// parameters.
|
|
template<typename _IteratorL, typename _IteratorR, typename _Sequence>
|
|
inline typename _Safe_iterator<_IteratorL, _Sequence>::difference_type
|
|
operator-(const _Safe_iterator<_IteratorL, _Sequence>& __lhs,
|
|
const _Safe_iterator<_IteratorR, _Sequence>& __rhs)
|
|
{
|
|
_GLIBCXX_DEBUG_VERIFY(! __lhs._M_singular() && ! __rhs._M_singular(),
|
|
_M_message(__msg_distance_bad)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
_GLIBCXX_DEBUG_VERIFY(__lhs._M_can_compare(__rhs),
|
|
_M_message(__msg_distance_different)
|
|
._M_iterator(__lhs, "lhs")
|
|
._M_iterator(__rhs, "rhs"));
|
|
return __lhs.base() - __rhs.base();
|
|
}
|
|
|
|
template<typename _Iterator, typename _Sequence>
|
|
inline _Safe_iterator<_Iterator, _Sequence>
|
|
operator+(typename _Safe_iterator<_Iterator,_Sequence>::difference_type __n,
|
|
const _Safe_iterator<_Iterator, _Sequence>& __i)
|
|
{ return __i + __n; }
|
|
} // namespace __gnu_debug
|
|
|
|
#ifndef _GLIBCXX_EXPORT_TEMPLATE
|
|
# include <debug/safe_iterator.tcc>
|
|
#endif
|
|
|
|
#endif
|