+2010-09-29 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/Makefile.am: Add debug/forward_list.
+ * include/Makefile.in: Regenerate.
+
+ * testsuite/util/testsuite_container_traits.h (traits_base):
+ Add has_erase_after and hash_insert_after typedefs.
+ (traits<forward_list<>>): Adjust.
+ * testsuite/util/exception/safety.h (erase_point, erase_range,
+ insert_point): Deal correctly with forward_list.
+ * include/Makefile.am: Add.
+
+2010-09-29 François Dumont <francois.cppdevs@free.fr>
+
+ * src/debug.cc: Add forward_list specific debug messages.
+ * include/debug/forward_list: New.
+ * include/debug/formatter.h: Add debug message ids and before begin
+ iterator state.
+ * include/debug/macros.h (__glibcxx_check_insert_after,
+ __glibcxx_check_insert_range_after, __glibcxx_check_erase_after,
+ __glibcxx_check_erase_range_after): Add.
+ * include/debug/safe_iterator.h (_BeforeBeginHelper): Add.
+ (_Safe_iterator<>::_M_before_dereferenceable,
+ _Safe_iterator<>::_M_is_before_begin): Add.
+ (_Safe_iterator<>::_M_dereferenceable, _Safe_iterator<>::_M_is_end,
+ _Safe_iterator<>::_M_incrementable): Adjust.
+ * include/std/forward_list: Include debug/forward when _GLIBCXX_DEBUG
+ defined.
+ * include/bits/forward_list.h, forward_list.tcc: Put in std::__norm
+ when debug mode is active.
+ * testsuite/23_containers/forward_list/capacity/1.cc: Fix to compile
+ even in debug mode.
+ * testsuite/23_containers/forward_list/debug/erase_after1.cc,
+ erase_after2.cc, erase_after3.cc, erase_after4.cc, erase_after5.cc,
+ insert_after1.cc,erase_after6.cc, erase_after7.cc, insert_after2.cc,
+ erase_after8.cc, insert_after3.cc, erase_after9.cc: New
+
2010-09-28 DJ Delorie <dj@redhat.com>
* libsupc++/hash_bytes.cc (_Hash_bytes): Replace "clength" with
${debug_srcdir}/debug.h \
${debug_srcdir}/deque \
${debug_srcdir}/formatter.h \
+ ${debug_srcdir}/forward_list \
${debug_srcdir}/functions.h \
${debug_srcdir}/list \
${debug_srcdir}/map \
${debug_srcdir}/debug.h \
${debug_srcdir}/deque \
${debug_srcdir}/formatter.h \
+ ${debug_srcdir}/forward_list \
${debug_srcdir}/functions.h \
${debug_srcdir}/list \
${debug_srcdir}/map \
#include <memory>
#include <initializer_list>
-_GLIBCXX_BEGIN_NAMESPACE(std)
+_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
/**
* @brief A helper basic node class for %forward_list.
forward_list<_Tp, _Alloc>& __ly)
{ __lx.swap(__ly); }
-_GLIBCXX_END_NAMESPACE // namespace std
+_GLIBCXX_END_NESTED_NAMESPACE // namespace std
#endif // _FORWARD_LIST_H
#ifndef _FORWARD_LIST_TCC
#define _FORWARD_LIST_TCC 1
-_GLIBCXX_BEGIN_NAMESPACE(std)
+_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
template<typename _Tp, typename _Alloc>
_Fwd_list_base<_Tp, _Alloc>::
}
}
-_GLIBCXX_END_NAMESPACE // namespace std
+_GLIBCXX_END_NESTED_NAMESPACE // namespace std
#endif /* _FORWARD_LIST_TCC */
__msg_output_ostream,
// istreambuf_iterator
__msg_deref_istreambuf,
- __msg_inc_istreambuf
+ __msg_inc_istreambuf,
+ // forward_list
+ __msg_insert_after_end,
+ __msg_erase_after_bad,
+ __msg_valid_range2
};
class _Error_formatter
__begin, // dereferenceable, and at the beginning
__middle, // dereferenceable, not at the beginning
__end, // past-the-end, may be at beginning if sequence empty
+ __before_begin, // before begin
__last_state
};
_M_variant._M_iterator._M_state = __singular;
else
{
- bool __is_begin = __it._M_is_begin();
- bool __is_end = __it._M_is_end();
- if (__is_end)
+ if (__it._M_is_before_begin())
+ _M_variant._M_iterator._M_state = __before_begin;
+ else if (__it._M_is_end())
_M_variant._M_iterator._M_state = __end;
- else if (__is_begin)
+ else if (__it._M_is_begin())
_M_variant._M_iterator._M_state = __begin;
else
_M_variant._M_iterator._M_state = __middle;
--- /dev/null
+// <forward_list> -*- C++ -*-
+
+// Copyright (C) 2010 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 3, 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.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file debug/forward_list
+ * This file is a GNU debug extension to the Standard C++ Library.
+ */
+
+#ifndef _GLIBCXX_DEBUG_FORWARD_LIST
+#define _GLIBCXX_DEBUG_FORWARD_LIST 1
+
+#pragma GCC system_header
+
+#include <forward_list>
+#include <debug/safe_sequence.h>
+#include <debug/safe_iterator.h>
+
+namespace std
+{
+namespace __debug
+{
+ /// Class std::forward_list with safety/checking/debug instrumentation.
+ template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
+ class forward_list
+ : public _GLIBCXX_STD_D::forward_list<_Tp, _Alloc>,
+ public __gnu_debug::_Safe_sequence<forward_list<_Tp, _Alloc> >
+ {
+ typedef _GLIBCXX_STD_D::forward_list<_Tp, _Alloc> _Base;
+ typedef __gnu_debug::_Safe_sequence<forward_list> _Safe_base;
+
+ public:
+ typedef typename _Base::reference reference;
+ typedef typename _Base::const_reference const_reference;
+
+ typedef __gnu_debug::_Safe_iterator<typename _Base::iterator,
+ forward_list> iterator;
+ typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator,
+ forward_list> const_iterator;
+
+ typedef typename _Base::size_type size_type;
+ typedef typename _Base::difference_type difference_type;
+
+ typedef _Tp value_type;
+ typedef _Alloc allocator_type;
+ typedef typename _Base::pointer pointer;
+ typedef typename _Base::const_pointer const_pointer;
+
+ // 23.2.3.1 construct/copy/destroy:
+ explicit
+ forward_list(const _Alloc& __al = _Alloc())
+ : _Base(__al) { }
+
+ forward_list(const forward_list& __list, const _Alloc& __al)
+ : _Base(__list, __al)
+ { }
+
+ forward_list(forward_list&& __list, const _Alloc& __al)
+ : _Base(std::move(__list), __al)
+ {
+ this->_M_swap(__list);
+ }
+
+ explicit
+ forward_list(size_type __n)
+ : _Base(__n)
+ { }
+
+ forward_list(size_type __n, const _Tp& __value,
+ const _Alloc& __al = _Alloc())
+ : _Base(__n, __value, __al)
+ { }
+
+ template<typename _InputIterator>
+ forward_list(_InputIterator __first, _InputIterator __last,
+ const _Alloc& __al = _Alloc())
+ : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
+ __last)),
+ __gnu_debug::__base(__last), __al)
+ { }
+
+ forward_list(const forward_list& __list)
+ : _Base(__list)
+ { }
+
+ forward_list(forward_list&& __list)
+ : _Base(std::move(__list)) { }
+
+ forward_list(std::initializer_list<_Tp> __il,
+ const _Alloc& __al = _Alloc())
+ : _Base(__il, __al)
+ { }
+
+ ~forward_list()
+ { }
+
+ forward_list&
+ operator=(const forward_list& __list)
+ {
+ static_cast<_Base&>(*this) = __list;
+ this->_M_invalidate_all();
+ return *this;
+ }
+
+ forward_list&
+ operator=(forward_list&& __list)
+ {
+ // NB: DR 1204.
+ // NB: DR 675.
+ clear();
+ swap(__list);
+ return *this;
+ }
+
+ forward_list&
+ operator=(std::initializer_list<_Tp> __il)
+ {
+ static_cast<_Base&>(*this) = __il;
+ this->_M_invalidate_all();
+ return *this;
+ }
+
+ template<typename _InputIterator>
+ void
+ assign(_InputIterator __first, _InputIterator __last)
+ {
+ __glibcxx_check_valid_range(__first, __last);
+ _Base::assign(__gnu_debug::__base(__first),
+ __gnu_debug::__base(__last));
+ this->_M_invalidate_all();
+ }
+
+ void
+ assign(size_type __n, const _Tp& __val)
+ {
+ _Base::assign(__n, __val);
+ this->_M_invalidate_all();
+ }
+
+ void
+ assign(std::initializer_list<_Tp> __il)
+ {
+ _Base::assign(__il);
+ this->_M_invalidate_all();
+ }
+
+ using _Base::get_allocator;
+
+ // iterators:
+
+ iterator
+ before_begin()
+ { return iterator(_Base::before_begin(), this); }
+
+ const_iterator
+ before_begin() const
+ { return const_iterator(_Base::before_begin(), this); }
+
+ iterator
+ begin()
+ { return iterator(_Base::begin(), this); }
+
+ const_iterator
+ begin() const
+ { return const_iterator(_Base::begin(), this); }
+
+ iterator
+ end()
+ { return iterator(_Base::end(), this); }
+
+ const_iterator
+ end() const
+ { return const_iterator(_Base::end(), this); }
+
+ const_iterator
+ cbegin() const
+ { return const_iterator(_Base::cbegin(), this); }
+
+ const_iterator
+ cbefore_begin() const
+ { return const_iterator(_Base::cbefore_begin(), this); }
+
+ const_iterator
+ cend() const
+ { return const_iterator(_Base::cend(), this); }
+
+ using _Base::empty;
+ using _Base::max_size;
+
+ // element access:
+
+ reference
+ front()
+ {
+ __glibcxx_check_nonempty();
+ return _Base::front();
+ }
+
+ const_reference
+ front() const
+ {
+ __glibcxx_check_nonempty();
+ return _Base::front();
+ }
+
+ // modifiers:
+
+ using _Base::emplace_front;
+ using _Base::push_front;
+
+ void
+ pop_front()
+ {
+ __glibcxx_check_nonempty();
+ iterator __victim = begin();
+ __victim._M_invalidate();
+ _Base::pop_front();
+ }
+
+ template<typename... _Args>
+ iterator
+ emplace_after(const_iterator __pos, _Args&&... __args)
+ {
+ __glibcxx_check_insert_after(__pos);
+ return iterator(_Base::emplace_after(__pos.base(),
+ std::forward<_Args>(__args)...),
+ this);
+ }
+
+ iterator
+ insert_after(const_iterator __pos, const _Tp& __val)
+ {
+ __glibcxx_check_insert_after(__pos);
+ return iterator(_Base::insert_after(__pos.base(), __val), this);
+ }
+
+ iterator
+ insert_after(const_iterator __pos, _Tp&& __val)
+ {
+ __glibcxx_check_insert_after(__pos);
+ return iterator(_Base::insert_after(__pos.base(), std::move(__val)),
+ this);
+ }
+
+ iterator
+ insert_after(const_iterator __pos, size_type __n, const _Tp& __val)
+ {
+ __glibcxx_check_insert_after(__pos);
+ return iterator(_Base::insert_after(__pos.base(), __n, __val),
+ this);
+ }
+
+ template<typename _InputIterator>
+ iterator
+ insert_after(const_iterator __pos,
+ _InputIterator __first, _InputIterator __last)
+ {
+ __glibcxx_check_insert_range_after(__pos, __first, __last);
+ return iterator(_Base::insert_after(__pos.base(),
+ __gnu_debug::__base(__first),
+ __gnu_debug::__base(__last)),
+ this);
+ }
+
+ iterator
+ insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
+ {
+ __glibcxx_check_insert_after(__pos);
+ return iterator(_Base::insert_after(__pos.base(), __il), this);
+ }
+
+ void
+ erase_after(const_iterator __pos)
+ {
+ __glibcxx_check_erase_after(__pos);
+ const_iterator __victim = __pos;
+ ++__victim;
+ __victim._M_invalidate();
+ _Base::erase_after(__pos.base());
+ }
+
+ void
+ erase_after(const_iterator __pos, const_iterator __last)
+ {
+ __glibcxx_check_erase_range_after(__pos, __last);
+ for (const_iterator __victim = std::next(__pos); __victim != __last; )
+ {
+ const_iterator __old = __victim++;
+ __old._M_invalidate();
+ }
+ _Base::erase_after(__pos.base(), __last.base());
+ }
+
+ void
+ swap(forward_list& __list)
+ {
+ _Base::swap(__list);
+ this->_M_swap(__list);
+ }
+
+ void
+ resize(size_type __sz)
+ {
+ this->_M_detach_singular();
+
+ // if __sz < size(), invalidate all iterators in [begin+__sz, end()
+ iterator __victim = begin();
+ iterator __end = end();
+ for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
+ ++__victim;
+
+ while (__victim != __end)
+ {
+ iterator __real_victim = __victim++;
+ __real_victim._M_invalidate();
+ }
+
+ __try
+ {
+ _Base::resize(__sz);
+ }
+ __catch(...)
+ {
+ this->_M_revalidate_singular();
+ __throw_exception_again;
+ }
+ }
+
+ void
+ resize(size_type __sz, const value_type& __val)
+ {
+ this->_M_detach_singular();
+
+ // if __sz < size(), invalidate all iterators in [begin+__sz, end())
+ iterator __victim = begin();
+ iterator __end = end();
+ for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
+ ++__victim;
+
+ while (__victim != __end)
+ {
+ iterator __real_victim = __victim++;
+ __real_victim._M_invalidate();
+ }
+
+ __try
+ {
+ _Base::resize(__sz, __val);
+ }
+ __catch(...)
+ {
+ this->_M_revalidate_singular();
+ __throw_exception_again;
+ }
+ }
+
+ void
+ clear()
+ {
+ _Base::clear();
+ this->_M_invalidate_all();
+ }
+
+ // 23.2.3.5 forward_list operations:
+ private:
+ void
+ _M_splice_after(const_iterator __pos, forward_list&& __list,
+ const_iterator __before, const_iterator __last)
+ {
+ for (const_iterator __tmp = std::next(__before); __tmp != __last; )
+ {
+ _GLIBCXX_DEBUG_VERIFY(&__list != this || __tmp != __pos,
+ _M_message(__gnu_debug::__msg_splice_overlap)
+ ._M_iterator(__tmp, "position")
+ ._M_iterator(__before, "before")
+ ._M_iterator(__last, "last"));
+ const_iterator __victim = __tmp++;
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 250. splicing invalidates iterators
+ this->_M_transfer_iter(__victim);
+ }
+
+ _Base::splice_after(__pos.base(), std::move(__list._M_base()),
+ __before.base(), __last.base());
+ }
+
+ public:
+ void
+ splice_after(const_iterator __pos, forward_list&& __list)
+ {
+ __glibcxx_check_insert_after(__pos);
+ _GLIBCXX_DEBUG_VERIFY(&__list != this,
+ _M_message(__gnu_debug::__msg_self_splice)
+ ._M_sequence(*this, "this"));
+ _M_splice_after(__pos, std::move(__list),
+ __list.before_begin(), __list.end());
+ }
+
+ void
+ splice_after(const_iterator __pos, forward_list&& __list,
+ const_iterator __i)
+ {
+ __glibcxx_check_insert_after(__pos);
+ _GLIBCXX_DEBUG_VERIFY(__i._M_before_dereferenceable(),
+ _M_message(__gnu_debug::__msg_splice_bad)
+ ._M_iterator(__i, "__i"));
+ _GLIBCXX_DEBUG_VERIFY(__i._M_attached_to(&__list),
+ _M_message(__gnu_debug::__msg_splice_other)
+ ._M_iterator(__i, "__i")
+ ._M_sequence(__list, "__list"));
+
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 250. splicing invalidates iterators
+ this->_M_transfer_iter(__i);
+ _Base::splice_after(__pos.base(), std::move(__list._M_base()),
+ __i.base());
+ }
+
+ void
+ splice_after(const_iterator __pos, forward_list&& __list,
+ const_iterator __before, const_iterator __last)
+ {
+ __glibcxx_check_insert_after(__pos);
+ __glibcxx_check_valid_range(__before, __last);
+ _GLIBCXX_DEBUG_VERIFY(__before._M_attached_to(&__list),
+ _M_message(__gnu_debug::__msg_splice_other)
+ ._M_sequence(__list, "list")
+ ._M_iterator(__before, "before"));
+ _GLIBCXX_DEBUG_VERIFY(__before._M_dereferenceable()
+ || __before._M_is_before_begin(),
+ _M_message(__gnu_debug::__msg_valid_range2)
+ ._M_sequence(__list, "list")
+ ._M_iterator(__before, "before")
+ ._M_iterator(__last, "last"));
+ _GLIBCXX_DEBUG_VERIFY(__before != __last,
+ _M_message(__gnu_debug::__msg_valid_range2)
+ ._M_sequence(__list, "list")
+ ._M_iterator(__before, "before")
+ ._M_iterator(__last, "last"));
+ _M_splice_after(__pos, std::move(__list), __before, __last);
+ }
+
+ void
+ remove(const _Tp& __val)
+ {
+ iterator __x = before_begin();
+ iterator __old = __x++;
+ while (__x.base() != _Base::end())
+ {
+ if (*__x == __val)
+ {
+ erase_after(__old);
+ __x = __old; ++__x;
+ }
+ else
+ __old = __x++;
+ }
+ }
+
+ template<typename _Pred>
+ void
+ remove_if(_Pred __pred)
+ {
+ iterator __x = before_begin();
+ iterator __old = __x++;
+ while (__x.base() != _Base::end())
+ {
+ if (__pred(*__x))
+ {
+ erase_after(__old);
+ __x = std::next(__old);
+ }
+ else
+ __old = __x++;
+ }
+ }
+
+ void
+ unique()
+ {
+ iterator __first = begin();
+ iterator __last = end();
+ if (__first == __last)
+ return;
+ iterator __next = __first;
+ while (++__next != __last)
+ {
+ if (*__first == *__next)
+ {
+ erase_after(__first);
+ __next = __first;
+ }
+ else
+ __first = __next;
+ }
+ }
+
+ template<typename _BinPred>
+ void
+ unique(_BinPred __binary_pred)
+ {
+ iterator __first = begin();
+ iterator __last = end();
+ if (__first == __last)
+ return;
+ iterator __next = __first;
+ while (++__next != __last)
+ {
+ if (__binary_pred(*__first, *__next))
+ {
+ erase_after(__first);
+ __next = __first;
+ }
+ else
+ __first = __next;
+ }
+ }
+
+ void
+ merge(forward_list&& __list)
+ {
+ if (this != &__list)
+ {
+ __glibcxx_check_sorted(_Base::begin(), _Base::end());
+ __glibcxx_check_sorted(__list._M_base().begin(),
+ __list._M_base().end());
+ for (iterator __tmp = __list.begin(); __tmp != __list.end();)
+ {
+ iterator __victim = __tmp++;
+ this->_M_transfer_iter(__victim);
+ }
+ _Base::merge(std::move(__list._M_base()));
+ }
+ }
+
+ template<typename _Comp>
+ void
+ merge(forward_list&& __list, _Comp __comp)
+ {
+ if (this != &__list)
+ {
+ __glibcxx_check_sorted_pred(_Base::begin(), _Base::end(), __comp);
+ __glibcxx_check_sorted_pred(__list._M_base().begin(),
+ __list._M_base().end(), __comp);
+ for (iterator __tmp = __list.begin(); __tmp != __list.end();)
+ {
+ iterator __victim = __tmp++;
+ this->_M_transfer_iter(__victim);
+ }
+ _Base::merge(std::move(__list._M_base()), __comp);
+ }
+ }
+
+ using _Base::sort;
+ using _Base::reverse;
+
+ _Base&
+ _M_base() { return *this; }
+
+ const _Base&
+ _M_base() const { return *this; }
+
+ private:
+ void
+ _M_invalidate_all()
+ {
+ typedef typename _Base::const_iterator _Base_const_iterator;
+ typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
+ this->_M_invalidate_if(_Not_equal(_M_base().end()));
+ }
+ };
+
+ template<typename _Tp, typename _Alloc>
+ bool
+ operator==(const forward_list<_Tp, _Alloc>& __lx,
+ const forward_list<_Tp, _Alloc>& __ly)
+ { return __lx._M_base() == __ly._M_base(); }
+
+ template<typename _Tp, typename _Alloc>
+ inline bool
+ operator<(const forward_list<_Tp, _Alloc>& __lx,
+ const forward_list<_Tp, _Alloc>& __ly)
+ { return __lx._M_base() < __ly._M_base(); }
+
+ template<typename _Tp, typename _Alloc>
+ inline bool
+ operator!=(const forward_list<_Tp, _Alloc>& __lx,
+ const forward_list<_Tp, _Alloc>& __ly)
+ { return !(__lx == __ly); }
+
+ /// Based on operator<
+ template<typename _Tp, typename _Alloc>
+ inline bool
+ operator>(const forward_list<_Tp, _Alloc>& __lx,
+ const forward_list<_Tp, _Alloc>& __ly)
+ { return (__ly < __lx); }
+
+ /// Based on operator<
+ template<typename _Tp, typename _Alloc>
+ inline bool
+ operator>=(const forward_list<_Tp, _Alloc>& __lx,
+ const forward_list<_Tp, _Alloc>& __ly)
+ { return !(__lx < __ly); }
+
+ /// Based on operator<
+ template<typename _Tp, typename _Alloc>
+ inline bool
+ operator<=(const forward_list<_Tp, _Alloc>& __lx,
+ const forward_list<_Tp, _Alloc>& __ly)
+ { return !(__ly < __lx); }
+
+ /// See std::forward_list::swap().
+ template<typename _Tp, typename _Alloc>
+ inline void
+ swap(forward_list<_Tp, _Alloc>& __lx,
+ forward_list<_Tp, _Alloc>& __ly)
+ { __lx.swap(__ly); }
+
+} // namespace __debug
+} // namespace std
+
+namespace __gnu_debug
+{
+ template<class _Tp, class _Alloc>
+ struct _BeforeBeginHelper<std::__debug::forward_list<_Tp, _Alloc> >
+ {
+ typedef typename forward_list<_Tp, _Alloc>::const_iterator _It;
+
+ static bool
+ _M_Is(_It __it, const forward_list<_Tp, _Alloc>* __seq)
+ { return __it == __seq->before_begin(); }
+ };
+}
+
+#endif
/** Verify that we can insert into *this with the iterator _Position.
* Insertion into a container at a specific position requires that
- * the iterator be nonsingular (i.e., either dereferenceable or
- * past-the-end) and that it reference the sequence we are inserting
- * into. Note that this macro is only valid when the container is a
- * _Safe_sequence and the iterator is a _Safe_iterator.
+ * the iterator be nonsingular, either dereferenceable or past-the-end,
+ * and that it reference the sequence we are inserting into. Note that
+ * this macro is only valid when the container is a_Safe_sequence and
+ * the iterator is a _Safe_iterator.
*/
#define __glibcxx_check_insert(_Position) \
_GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(), \
._M_sequence(*this, "this") \
._M_iterator(_Position, #_Position))
+/** Verify that we can insert into *this after the iterator _Position.
+ * Insertion into a container after a specific position requires that
+ * the iterator be nonsingular, either dereferenceable or before-begin,
+ * and that it reference the sequence we are inserting into. Note that
+ * this macro is only valid when the container is a_Safe_sequence and
+ * the iterator is a _Safe_iterator.
+*/
+#define __glibcxx_check_insert_after(_Position) \
+__glibcxx_check_insert(_Position); \
+_GLIBCXX_DEBUG_VERIFY(!_Position._M_is_end(), \
+ _M_message(__gnu_debug::__msg_insert_after_end) \
+ ._M_sequence(*this, "this") \
+ ._M_iterator(_Position, #_Position))
+
/** Verify that we can insert the values in the iterator range
* [_First, _Last) into *this with the iterator _Position. Insertion
* into a container at a specific position requires that the iterator
*/
#define __glibcxx_check_insert_range(_Position,_First,_Last) \
__glibcxx_check_valid_range(_First,_Last); \
-_GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(), \
- _M_message(__gnu_debug::__msg_insert_singular) \
- ._M_sequence(*this, "this") \
- ._M_iterator(_Position, #_Position)); \
-_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
- _M_message(__gnu_debug::__msg_insert_different) \
- ._M_sequence(*this, "this") \
- ._M_iterator(_Position, #_Position))
+__glibcxx_check_insert(_Position)
+
+/** Verify that we can insert the values in the iterator range
+ * [_First, _Last) into *this after the iterator _Position. Insertion
+ * into a container after a specific position requires that the iterator
+ * be nonsingular (i.e., either dereferenceable or past-the-end),
+ * that it reference the sequence we are inserting into, and that the
+ * iterator range [_First, Last) is a valid (possibly empty)
+ * range. Note that this macro is only valid when the container is a
+ * _Safe_sequence and the iterator is a _Safe_iterator.
+ *
+ * @todo We would like to be able to check for noninterference of
+ * _Position and the range [_First, _Last), but that can't (in
+ * general) be done.
+*/
+#define __glibcxx_check_insert_range_after(_Position,_First,_Last) \
+__glibcxx_check_valid_range(_First,_Last); \
+__glibcxx_check_insert_after(_Position)
/** Verify that we can erase the element referenced by the iterator
* _Position. We can erase the element if the _Position iterator is
._M_sequence(*this, "this") \
._M_iterator(_Position, #_Position))
+/** Verify that we can erase the element after the iterator
+ * _Position. We can erase the element if the _Position iterator is
+ * before a dereferenceable one and references this sequence.
+*/
+#define __glibcxx_check_erase_after(_Position) \
+_GLIBCXX_DEBUG_VERIFY(_Position._M_before_dereferenceable(), \
+ _M_message(__gnu_debug::__msg_erase_after_bad) \
+ ._M_sequence(*this, "this") \
+ ._M_iterator(_Position, #_Position)); \
+_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
+ _M_message(__gnu_debug::__msg_erase_different) \
+ ._M_sequence(*this, "this") \
+ ._M_iterator(_Position, #_Position))
+
/** Verify that we can erase the elements in the iterator range
* [_First, _Last). We can erase the elements if [_First, _Last) is a
* valid iterator range within this sequence.
._M_iterator(_First, #_First) \
._M_iterator(_Last, #_Last))
+/** Verify that we can erase the elements in the iterator range
+ * (_First, _Last). We can erase the elements if (_First, _Last) is a
+ * valid iterator range within this sequence.
+*/
+#define __glibcxx_check_erase_range_after(_First,_Last) \
+_GLIBCXX_DEBUG_VERIFY(_First._M_can_compare(_Last), \
+ _M_message(__gnu_debug::__msg_erase_different) \
+ ._M_sequence(*this, "this") \
+ ._M_iterator(_First, #_First) \
+ ._M_iterator(_Last, #_Last)); \
+_GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this), \
+ _M_message(__gnu_debug::__msg_erase_different) \
+ ._M_sequence(*this, "this") \
+ ._M_iterator(_First, #_First)); \
+_GLIBCXX_DEBUG_VERIFY(_First != _Last, \
+ _M_message(__gnu_debug::__msg_valid_range2) \
+ ._M_sequence(*this, "this") \
+ ._M_iterator(_First, #_First) \
+ ._M_iterator(_Last, #_Last)); \
+_GLIBCXX_DEBUG_VERIFY(_First._M_incrementable(), \
+ _M_message(__gnu_debug::__msg_valid_range2) \
+ ._M_sequence(*this, "this") \
+ ._M_iterator(_First, #_First) \
+ ._M_iterator(_Last, #_Last)); \
+_GLIBCXX_DEBUG_VERIFY(!_Last._M_is_before_begin(), \
+ _M_message(__gnu_debug::__msg_valid_range2) \
+ ._M_sequence(*this, "this") \
+ ._M_iterator(_First, #_First) \
+ ._M_iterator(_Last, #_Last)) \
+
// Verify that the subscript _N is less than the container's size.
#define __glibcxx_check_subscript(_N) \
_GLIBCXX_DEBUG_VERIFY(_N < this->size(), \
namespace __gnu_debug
{
+ /** Helper struct to deal with sequence offering a before_begin
+ * iterator.
+ **/
+ template <typename _Sequence>
+ struct _BeforeBeginHelper
+ {
+ typedef typename _Sequence::const_iterator _It;
+
+ static bool
+ _M_Is(_It __it, const _Sequence* __seq)
+ { return false; }
+ };
+
/** Iterators that derive from _Safe_iterator_base but that aren't
* _Safe_iterators can be determined singular or non-singular via
* _Safe_iterator_base.
/// Is the iterator dereferenceable?
bool
_M_dereferenceable() const
- { return !this->_M_singular() && !_M_is_end(); }
+ { return !this->_M_singular() && !_M_is_end() && !_M_is_before_begin(); }
+
+ /// Is the iterator before a dereferenceable one?
+ bool
+ _M_before_dereferenceable() const
+ {
+ _Self __it = *this;
+ return __it._M_incrementable() && (++__it)._M_dereferenceable();
+ }
/// Is the iterator incrementable?
bool
- _M_incrementable() const { return this->_M_dereferenceable(); }
+ _M_incrementable() const
+ { return !this->_M_singular() && !_M_is_end(); }
// Is the iterator decrementable?
bool
/// Is this iterator equal to the sequence's begin() iterator?
bool _M_is_begin() const
- { return *this == static_cast<const _Sequence*>(_M_sequence)->begin(); }
+ { return *this == _M_get_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(); }
+ { return *this == _M_get_sequence()->end(); }
+
+ /// Is this iterator equal to the sequence's before_begin() iterator if
+ /// any?
+ bool _M_is_before_begin() const
+ { return _BeforeBeginHelper<_Sequence>::_M_Is(*this, _M_get_sequence()); }
};
template<typename _IteratorL, typename _IteratorR, typename _Sequence>
# include <bits/forward_list.tcc>
#endif
+#ifdef _GLIBCXX_DEBUG
+# include <debug/forward_list>
+#endif
+
#endif // __GXX_EXPERIMENTAL_CXX0X__
#endif // _GLIBCXX_FORWARD_LIST
// Debugging mode support code -*- C++ -*-
-// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
"attempt to output via an ostream_iterator with no associated stream",
"attempt to dereference an end-of-stream istreambuf_iterator"
" (this is a GNU extension)",
- "attempt to increment an end-of-stream istreambuf_iterator"
+ "attempt to increment an end-of-stream istreambuf_iterator",
+ "attempt to insert into container after an end iterator",
+ "attempt to erase from container after a %2.state; iterator not followed"
+ " by a dereferenceable one",
+ "function requires a valid iterator range (%1.name;, %2.name;)"
+ ", %1.name; shall not be equal to %2.name;"
};
void
"singular",
"dereferenceable (start-of-sequence)",
"dereferenceable",
- "past-the-end"
+ "past-the-end",
+ "before begin"
};
__formatter->_M_print_word(__state_names[_M_variant.
_M_iterator._M_state]);
fld.resize(0);
VERIFY(fld.empty() == true);
+#ifndef _GLIBCXX_DEBUG
+ using std::_Fwd_list_node;
+#else
+ using std::_GLIBCXX_STD_D::_Fwd_list_node;
+#endif
+
VERIFY( (fld.max_size()
- == std::allocator<std::_Fwd_list_node<double> >().max_size()) );
+ == std::allocator<_Fwd_list_node<double> >().max_size()) );
}
int
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::forward_list<int> fl1{1, 2, 3};
+
+ auto it = fl1.begin();
+ VERIFY( *it == 1 );
+
+ fl1.erase_after(fl1.before_begin());
+
+ VERIFY( *it == 1 );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+
+void
+test01()
+{
+ std::forward_list<int> fl1{1, 2, 3};
+ fl1.erase_after(fl1.end());
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+
+void
+test01()
+{
+ std::forward_list<int> fl1{1};
+ fl1.erase_after(fl1.begin());
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+
+void
+test01()
+{
+ std::forward_list<int> fl1{1, 2, 3};
+ std::forward_list<int> fl2{1, 2, 3};
+
+ fl1.erase_after(fl1.before_begin(), fl2.begin());
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+
+void
+test01()
+{
+ std::forward_list<int> fl1{1, 2, 3};
+ std::forward_list<int> fl2{1, 2, 3};
+
+ fl1.erase_after(fl2.before_begin(), fl2.begin());
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+
+void
+test01()
+{
+ std::forward_list<int> fl1{1, 2, 3};
+
+ fl1.erase_after(fl1.before_begin(), fl1.before_begin());
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+
+void
+test01()
+{
+ std::forward_list<int> fl1{1, 2, 3};
+
+ fl1.erase_after(fl1.end(), fl1.begin());
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+
+void
+test01()
+{
+ std::forward_list<int> fl1{1, 2, 3};
+
+ fl1.erase_after(fl1.begin(), fl1.before_begin());
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+
+void
+test01()
+{
+ std::forward_list<int> fl1{1, 2, 3};
+
+ auto it = fl1.begin();
+ ++it;
+ fl1.erase_after(it, fl1.begin());
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+
+void
+test01()
+{
+ std::forward_list<int> fl1{1, 2, 3};
+ std::forward_list<int> fl2{1, 2, 3};
+
+ fl1.insert_after(fl1.before_begin(), fl2.before_begin(), fl2.end());
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+
+void
+test01()
+{
+ std::forward_list<int> fl1{1, 2, 3};
+ std::forward_list<int> fl2{0};
+
+ fl1.insert_after(fl1.before_begin(), fl2.begin(), fl2.before_begin());
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+
+void
+test01()
+{
+ std::forward_list<int> fl1{1, 2, 3};
+
+ fl1.insert_after(fl1.end(), 4);
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
_F_erase_range(&container_type::erase) { }
};
- template<typename _Tp, bool = traits<_Tp>::has_erase::value>
- struct erase_point : public erase_base<_Tp>
+ template<typename _Tp,
+ bool = traits<_Tp>::has_erase::value,
+ bool = traits<_Tp>::has_erase_after::value>
+ struct erase_point;
+
+ // Specialization for most containers.
+ template<typename _Tp>
+ struct erase_point<_Tp, true, false> : public erase_base<_Tp>
{
using erase_base<_Tp>::_F_erase_point;
}
};
+ // Specialization for forward_list.
+ template<typename _Tp>
+ struct erase_point<_Tp, false, true> : public erase_base<_Tp>
+ {
+ using erase_base<_Tp>::_F_erase_point;
+
+ void
+ operator()(_Tp& __container)
+ {
+ try
+ {
+ // NB: Should be equivalent to size() member function, but
+ // computed with begin() and end().
+ const size_type sz = std::distance(__container.begin(),
+ __container.end());
+
+ // NB: Lowest common denominator: use forward iterator operations.
+ auto i = __container.before_begin();
+ std::advance(i, generate(sz));
+
+ // Makes it easier to think of this as __container.erase(i)
+ (__container.*_F_erase_point)(i);
+ }
+ catch(const __gnu_cxx::forced_error&)
+ { throw; }
+ }
+ };
+
// Specialization, empty.
template<typename _Tp>
- struct erase_point<_Tp, false>
+ struct erase_point<_Tp, false, false>
{
void
operator()(_Tp&) { }
};
- template<typename _Tp, bool = traits<_Tp>::has_erase::value>
- struct erase_range : public erase_base<_Tp>
+ template<typename _Tp,
+ bool = traits<_Tp>::has_erase::value,
+ bool = traits<_Tp>::has_erase_after::value>
+ struct erase_range;
+
+ // Specialization for most containers.
+ template<typename _Tp>
+ struct erase_range<_Tp, true, false> : public erase_base<_Tp>
{
using erase_base<_Tp>::_F_erase_range;
}
};
+ // Specialization for forward_list.
+ template<typename _Tp>
+ struct erase_range<_Tp, false, true> : public erase_base<_Tp>
+ {
+ using erase_base<_Tp>::_F_erase_range;
+
+ void
+ operator()(_Tp& __container)
+ {
+ try
+ {
+ const size_type sz = std::distance(__container.begin(),
+ __container.end());
+ size_type s1 = generate(sz);
+ size_type s2 = generate(sz);
+ auto i1 = __container.before_begin();
+ auto i2 = __container.before_begin();
+ std::advance(i1, std::min(s1, s2));
+ std::advance(i2, std::max(s1, s2));
+
+ // Makes it easier to think of this as __container.erase(i1, i2).
+ (__container.*_F_erase_range)(i1, i2);
+ }
+ catch(const __gnu_cxx::forced_error&)
+ { throw; }
+ }
+ };
+
// Specialization, empty.
template<typename _Tp>
- struct erase_range<_Tp, false>
+ struct erase_range<_Tp, false, false>
{
void
operator()(_Tp&) { }
insert_base() : _F_insert_point(&container_type::insert) { }
};
- template<typename _Tp, bool = traits<_Tp>::has_insert::value>
- struct insert_point : public insert_base<_Tp>
+ template<typename _Tp,
+ bool = traits<_Tp>::has_insert::value,
+ bool = traits<_Tp>::has_insert_after::value>
+ struct insert_point;
+
+ // Specialization for most containers.
+ template<typename _Tp>
+ struct insert_point<_Tp, true, false> : public insert_base<_Tp>
{
typedef _Tp container_type;
typedef typename container_type::value_type value_type;
}
};
+ // Specialization for forward_list.
+ template<typename _Tp>
+ struct insert_point<_Tp, false, true> : public insert_base<_Tp>
+ {
+ typedef _Tp container_type;
+ typedef typename container_type::value_type value_type;
+ using insert_base<_Tp>::_F_insert_point;
+
+ void
+ operator()(_Tp& __test)
+ {
+ try
+ {
+ const value_type cv = generate_unique<value_type>();
+ const size_type sz = std::distance(__test.begin(), __test.end());
+ size_type s = generate(sz);
+ auto i = __test.before_begin();
+ std::advance(i, s);
+ (__test.*_F_insert_point)(i, cv);
+ }
+ catch(const __gnu_cxx::forced_error&)
+ { throw; }
+ }
+
+ // Assumes containers start out equivalent.
+ void
+ operator()(_Tp& __control, _Tp& __test)
+ {
+ try
+ {
+ const value_type cv = generate_unique<value_type>();
+ const size_type sz = std::distance(__test.begin(), __test.end());
+ size_type s = generate(sz);
+ auto i = __test.before_begin();
+ std::advance(i, s);
+ (__test.*_F_insert_point)(i, cv);
+ }
+ catch(const __gnu_cxx::forced_error&)
+ { throw; }
+ }
+ };
+
// Specialization, empty.
template<typename _Tp>
- struct insert_point<_Tp, false>
+ struct insert_point<_Tp, false, false>
{
void
operator()(_Tp&) { }
typedef std::false_type is_mapped;
typedef std::false_type has_erase;
+ typedef std::false_type has_erase_after;
typedef std::false_type has_throwing_erase;
typedef std::false_type has_insert;
+ typedef std::false_type has_insert_after;
typedef std::false_type has_push_pop;
typedef std::false_type has_size_type_constructor;
};
typedef std::true_type is_container;
typedef std::true_type is_allocator_aware;
- typedef std::true_type has_erase;
- typedef std::true_type has_insert;
+ typedef std::true_type has_erase_after;
+ typedef std::true_type has_insert_after;
typedef std::true_type has_push_pop;
typedef std::true_type has_size_type_constructor;
};