head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC4:1.1.1.10
	netbsd-11-0-RC3:1.1.1.10
	netbsd-11-0-RC2:1.1.1.10
	netbsd-11-0-RC1:1.1.1.10
	gcc-14-3-0:1.1.1.11
	perseant-exfatfs-base-20250801:1.1.1.10
	netbsd-11:1.1.1.10.0.4
	netbsd-11-base:1.1.1.10
	gcc-12-5-0:1.1.1.10
	netbsd-10-1-RELEASE:1.1.1.9
	perseant-exfatfs-base-20240630:1.1.1.10
	gcc-12-4-0:1.1.1.10
	perseant-exfatfs:1.1.1.10.0.2
	perseant-exfatfs-base:1.1.1.10
	netbsd-8-3-RELEASE:1.1.1.2
	netbsd-9-4-RELEASE:1.1.1.4
	netbsd-10-0-RELEASE:1.1.1.9
	netbsd-10-0-RC6:1.1.1.9
	netbsd-10-0-RC5:1.1.1.9
	netbsd-10-0-RC4:1.1.1.9
	netbsd-10-0-RC3:1.1.1.9
	netbsd-10-0-RC2:1.1.1.9
	netbsd-10-0-RC1:1.1.1.9
	gcc-12-3-0:1.1.1.10
	gcc-10-5-0:1.1.1.9
	netbsd-10:1.1.1.9.0.6
	netbsd-10-base:1.1.1.9
	netbsd-9-3-RELEASE:1.1.1.4
	gcc-10-4-0:1.1.1.9
	cjep_sun2x-base1:1.1.1.9
	cjep_sun2x:1.1.1.9.0.4
	cjep_sun2x-base:1.1.1.9
	cjep_staticlib_x-base1:1.1.1.9
	netbsd-9-2-RELEASE:1.1.1.4
	cjep_staticlib_x:1.1.1.9.0.2
	cjep_staticlib_x-base:1.1.1.9
	gcc-10-3-0:1.1.1.9
	netbsd-9-1-RELEASE:1.1.1.4
	gcc-9-3-0:1.1.1.8
	gcc-7-5-0:1.1.1.6
	phil-wifi-20200421:1.1.1.5
	phil-wifi-20200411:1.1.1.5
	is-mlppp:1.1.1.5.0.2
	is-mlppp-base:1.1.1.5
	phil-wifi-20200406:1.1.1.5
	netbsd-8-2-RELEASE:1.1.1.2
	gcc-8-4-0:1.1.1.7
	netbsd-9-0-RELEASE:1.1.1.4
	netbsd-9-0-RC2:1.1.1.4
	netbsd-9-0-RC1:1.1.1.4
	phil-wifi-20191119:1.1.1.5
	gcc-8-3-0:1.1.1.5
	netbsd-9:1.1.1.4.0.2
	netbsd-9-base:1.1.1.4
	phil-wifi-20190609:1.1.1.4
	netbsd-8-1-RELEASE:1.1.1.2
	netbsd-8-1-RC1:1.1.1.2
	pgoyette-compat-merge-20190127:1.1.1.3.2.1
	pgoyette-compat-20190127:1.1.1.4
	gcc-7-4-0:1.1.1.4
	pgoyette-compat-20190118:1.1.1.3
	pgoyette-compat-1226:1.1.1.3
	pgoyette-compat-1126:1.1.1.3
	gcc-6-5-0:1.1.1.3
	pgoyette-compat-1020:1.1.1.3
	pgoyette-compat-0930:1.1.1.3
	pgoyette-compat-0906:1.1.1.3
	netbsd-7-2-RELEASE:1.1.1.1
	pgoyette-compat-0728:1.1.1.3
	netbsd-8-0-RELEASE:1.1.1.2
	phil-wifi:1.1.1.3.0.4
	phil-wifi-base:1.1.1.3
	pgoyette-compat-0625:1.1.1.3
	netbsd-8-0-RC2:1.1.1.2
	pgoyette-compat-0521:1.1.1.3
	pgoyette-compat-0502:1.1.1.3
	pgoyette-compat-0422:1.1.1.3
	netbsd-8-0-RC1:1.1.1.2
	pgoyette-compat-0415:1.1.1.3
	pgoyette-compat-0407:1.1.1.3
	pgoyette-compat-0330:1.1.1.3
	pgoyette-compat-0322:1.1.1.3
	pgoyette-compat-0315:1.1.1.3
	netbsd-7-1-2-RELEASE:1.1.1.1
	pgoyette-compat:1.1.1.3.0.2
	pgoyette-compat-base:1.1.1.3
	gcc-6-4-0:1.1.1.3
	netbsd-7-1-1-RELEASE:1.1.1.1
	gcc-5-5-0:1.1.1.2
	matt-nb8-mediatek:1.1.1.2.0.12
	matt-nb8-mediatek-base:1.1.1.2
	perseant-stdc-iso10646:1.1.1.2.0.10
	perseant-stdc-iso10646-base:1.1.1.2
	netbsd-8:1.1.1.2.0.8
	netbsd-8-base:1.1.1.2
	prg-localcount2-base3:1.1.1.2
	prg-localcount2-base2:1.1.1.2
	prg-localcount2-base1:1.1.1.2
	prg-localcount2:1.1.1.2.0.6
	prg-localcount2-base:1.1.1.2
	pgoyette-localcount-20170426:1.1.1.2
	bouyer-socketcan-base1:1.1.1.2
	pgoyette-localcount-20170320:1.1.1.2
	netbsd-7-1:1.1.1.1.0.14
	netbsd-7-1-RELEASE:1.1.1.1
	netbsd-7-1-RC2:1.1.1.1
	netbsd-7-nhusb-base-20170116:1.1.1.1
	bouyer-socketcan:1.1.1.2.0.4
	bouyer-socketcan-base:1.1.1.2
	pgoyette-localcount-20170107:1.1.1.2
	netbsd-7-1-RC1:1.1.1.1
	pgoyette-localcount-20161104:1.1.1.2
	netbsd-7-0-2-RELEASE:1.1.1.1
	localcount-20160914:1.1.1.2
	netbsd-7-nhusb:1.1.1.1.0.12
	netbsd-7-nhusb-base:1.1.1.1
	pgoyette-localcount-20160806:1.1.1.2
	pgoyette-localcount-20160726:1.1.1.2
	pgoyette-localcount:1.1.1.2.0.2
	pgoyette-localcount-base:1.1.1.2
	gcc-5-4-0:1.1.1.2
	netbsd-7-0-1-RELEASE:1.1.1.1
	gcc-5-3-0:1.1.1.2
	netbsd-7-0:1.1.1.1.0.10
	netbsd-7-0-RELEASE:1.1.1.1
	gcc-4-8-5-pre-gcc-old-import:1.1.1.1
	netbsd-7-0-RC3:1.1.1.1
	netbsd-7-0-RC2:1.1.1.1
	post-gcc-4-8-5-merge:1.1.1.1
	gcc-4-8-5:1.1.1.1
	netbsd-7-0-RC1:1.1.1.1
	gcc-4-8-4:1.1.1.1
	gcc-4-8-20141009:1.1.1.1
	tls-maxphys-base:1.1.1.1
	tls-maxphys:1.1.1.1.0.8
	netbsd-7:1.1.1.1.0.6
	netbsd-7-base:1.1.1.1
	gcc-4-8-3:1.1.1.1
	yamt-pagecache:1.1.1.1.0.4
	yamt-pagecache-base9:1.1.1.1
	tls-earlyentropy:1.1.1.1.0.2
	tls-earlyentropy-base:1.1.1.1
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.1.1.1
	riastradh-drm2-base3:1.1.1.1
	gcc-4-8-3-pre-r208254:1.1.1.1
	gcc-4-8-3-pre-r206687:1.1.1.1
	FSF:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2014.03.01.08.41.31;	author mrg;	state Exp;
branches
	1.1.1.1;
next	;
commitid	TtaB91QNTknAoYqx;

1.1.1.1
date	2014.03.01.08.41.31;	author mrg;	state Exp;
branches
	1.1.1.1.4.1
	1.1.1.1.8.1;
next	1.1.1.2;
commitid	TtaB91QNTknAoYqx;

1.1.1.2
date	2016.01.24.06.05.53;	author mrg;	state Exp;
branches;
next	1.1.1.3;
commitid	uWWfbLp08zOK79Sy;

1.1.1.3
date	2018.02.02.01.59.03;	author mrg;	state Exp;
branches
	1.1.1.3.2.1
	1.1.1.3.4.1;
next	1.1.1.4;
commitid	XNKaycqpfhzd5epA;

1.1.1.4
date	2019.01.19.10.14.11;	author mrg;	state Exp;
branches;
next	1.1.1.5;
commitid	VQ8OwWIg5RS9kn8B;

1.1.1.5
date	2019.10.01.09.36.06;	author mrg;	state Exp;
branches;
next	1.1.1.6;
commitid	smvgr2IPAQDr89FB;

1.1.1.6
date	2020.08.11.05.10.39;	author mrg;	state Exp;
branches;
next	1.1.1.7;
commitid	5dBRDT7i6e65xBjC;

1.1.1.7
date	2020.08.11.05.30.09;	author mrg;	state Exp;
branches;
next	1.1.1.8;
commitid	7AI4OfpLi4eqEBjC;

1.1.1.8
date	2020.09.05.07.52.09;	author mrg;	state Exp;
branches;
next	1.1.1.9;
commitid	ZRYA7IOuwfMjAPmC;

1.1.1.9
date	2021.04.10.22.10.03;	author mrg;	state Exp;
branches;
next	1.1.1.10;
commitid	eC4g0MRpqTvEkNOC;

1.1.1.10
date	2023.07.30.05.21.20;	author mrg;	state Exp;
branches;
next	1.1.1.11;
commitid	tk6nV4mbc9nVEMyE;

1.1.1.11
date	2025.09.13.23.45.48;	author mrg;	state Exp;
branches;
next	;
commitid	KwhwN4krNWa6XBaG;

1.1.1.1.4.1
date	2014.03.01.08.41.31;	author yamt;	state dead;
branches;
next	1.1.1.1.4.2;
commitid	DX8bafDLmqEbpyBx;

1.1.1.1.4.2
date	2014.05.22.16.37.48;	author yamt;	state Exp;
branches;
next	;
commitid	DX8bafDLmqEbpyBx;

1.1.1.1.8.1
date	2014.03.01.08.41.31;	author tls;	state dead;
branches;
next	1.1.1.1.8.2;
commitid	jTnpym9Qu0o4R1Nx;

1.1.1.1.8.2
date	2014.08.19.23.54.50;	author tls;	state Exp;
branches;
next	;
commitid	jTnpym9Qu0o4R1Nx;

1.1.1.3.2.1
date	2019.01.26.21.59.34;	author pgoyette;	state Exp;
branches;
next	;
commitid	JKpcmvSjdT25dl9B;

1.1.1.3.4.1
date	2019.06.10.21.54.51;	author christos;	state Exp;
branches;
next	1.1.1.3.4.2;
commitid	jtc8rnCzWiEEHGqB;

1.1.1.3.4.2
date	2020.04.13.07.58.37;	author martin;	state Exp;
branches;
next	;
commitid	X01YhRUPVUDaec4C;


desc
@@


1.1
log
@Initial revision
@
text
@// <forward_list> -*- C++ -*-

// Copyright (C) 2010-2013 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 _GLIBCXX_VISIBILITY(default)
{
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_C::forward_list<_Tp, _Alloc>,
      public __gnu_debug::_Safe_sequence<forward_list<_Tp, _Alloc> >
    {
      typedef _GLIBCXX_STD_C::forward_list<_Tp, _Alloc> _Base;

      typedef typename _Base::iterator       _Base_iterator;
      typedef typename _Base::const_iterator _Base_const_iterator;

      typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
        rebind<_GLIBCXX_STD_C::_Fwd_list_node<_Tp>>::other _Node_alloc_type;

      typedef __gnu_cxx::__alloc_traits<_Node_alloc_type> _Node_alloc_traits;

    public:
      typedef typename _Base::reference             reference;
      typedef typename _Base::const_reference       const_reference;

      typedef __gnu_debug::_Safe_iterator<_Base_iterator,
					  forward_list> iterator;
      typedef __gnu_debug::_Safe_iterator<_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._M_base()), __al)
      {
	if (__list.get_allocator() == __al)
	  this->_M_swap(__list);
	else
	  __list._M_invalidate_all();
      }

      explicit
      forward_list(size_type __n, const _Alloc& __al = _Alloc())
      : _Base(__n, __al)
      { }

      forward_list(size_type __n, const _Tp& __value,
                   const _Alloc& __al = _Alloc())
      : _Base(__n, __value, __al)
      { }

      template<typename _InputIterator,
	       typename = std::_RequireInputIter<_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) noexcept
      : _Base(std::move(__list._M_base()))
      {
	this->_M_swap(__list);
      }

      forward_list(std::initializer_list<_Tp> __il,
                   const _Alloc& __al = _Alloc())
      : _Base(__il, __al)
      { }

      ~forward_list() noexcept
      { }

      forward_list&
      operator=(const forward_list& __list)
      {
	static_cast<_Base&>(*this) = __list;
	this->_M_invalidate_all();
	return *this;
      }

      forward_list&
      operator=(forward_list&& __list)
      noexcept(_Node_alloc_traits::_S_nothrow_move())
      {
	__glibcxx_check_self_move_assign(__list);
	bool xfer_memory = _Node_alloc_traits::_S_propagate_on_move_assign()
	    || __list.get_allocator() == this->get_allocator();
	static_cast<_Base&>(*this) = std::move(__list);
	if (xfer_memory)
	  this->_M_swap(__list);
	else
	  this->_M_invalidate_all();
	__list._M_invalidate_all();
	return *this;
      }

      forward_list&
      operator=(std::initializer_list<_Tp> __il)
      {
	static_cast<_Base&>(*this) = __il;
	this->_M_invalidate_all();
        return *this;
      }

      template<typename _InputIterator,
	       typename = std::_RequireInputIter<_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() noexcept
      { return iterator(_Base::before_begin(), this); }

      const_iterator
      before_begin() const noexcept
      { return const_iterator(_Base::before_begin(), this); }

      iterator
      begin() noexcept
      { return iterator(_Base::begin(), this); }

      const_iterator
      begin() const noexcept
      { return const_iterator(_Base::begin(), this); }

      iterator
      end() noexcept
      { return iterator(_Base::end(), this); }

      const_iterator
      end() const noexcept
      { return const_iterator(_Base::end(), this); }

      const_iterator
      cbegin() const noexcept
      { return const_iterator(_Base::cbegin(), this); }

      const_iterator
      cbefore_begin() const noexcept
      { return const_iterator(_Base::cbefore_begin(), this); }

      const_iterator
      cend() const noexcept
      { 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();
      }

      // modiﬁers:

      using _Base::emplace_front;
      using _Base::push_front;

      void
      pop_front()
      {
	__glibcxx_check_nonempty();
	this->_M_invalidate_if([this](_Base_const_iterator __it)
	  { return __it == this->_M_base().cbegin(); });
	_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,
	       typename = std::_RequireInputIter<_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);
      }

    private:
      _Base_iterator
      _M_erase_after(_Base_const_iterator __pos)
      {
	_Base_const_iterator __next = std::next(__pos);
	this->_M_invalidate_if([__next](_Base_const_iterator __it)
	  { return __it == __next; });
	return _Base::erase_after(__pos);
      }
    public:
      iterator
      erase_after(const_iterator __pos)
      {
	__glibcxx_check_erase_after(__pos);
	return iterator(_M_erase_after(__pos.base()), this);
      }

      iterator
      erase_after(const_iterator __pos, const_iterator __last)
      {
	__glibcxx_check_erase_range_after(__pos, __last);
	for (_Base_const_iterator __victim = std::next(__pos.base());
	    __victim != __last.base(); ++__victim)
	  {
	    _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
				  _M_message(__gnu_debug::__msg_valid_range2)
				  ._M_sequence(*this, "this")
				  ._M_iterator(__pos, "pos")
				  ._M_iterator(__last, "last"));
	    this->_M_invalidate_if([__victim](_Base_const_iterator __it)
	      { return __it == __victim; });
	  }
	return iterator(_Base::erase_after(__pos.base(), __last.base()), this);
      }

      void
      swap(forward_list& __list)
      noexcept(_Node_alloc_traits::_S_nothrow_swap())
      {
	if (!_Node_alloc_traits::_S_propagate_on_swap())
	  __glibcxx_check_equal_allocs(__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()
	_Base_iterator __victim = _Base::begin();
	_Base_iterator __end = _Base::end();
	for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
	  ++__victim;

	for (; __victim != __end; ++__victim)
	  {
	    this->_M_invalidate_if([__victim](_Base_const_iterator __it)
	      { return __it == __victim; });
	  }

	__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())
	_Base_iterator __victim = _Base::begin();
	_Base_iterator __end = _Base::end();
	for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
	  ++__victim;

	for (; __victim != __end; ++__victim)
	  {
	    this->_M_invalidate_if([__victim](_Base_const_iterator __it)
	      { return __it == __victim; });
	  }

	__try
	  {
	    _Base::resize(__sz, __val);
	  }
	__catch(...)
	  {
	    this->_M_revalidate_singular();
	    __throw_exception_again;
          }
      }

      void
      clear() noexcept
      {
	_Base::clear();
	this->_M_invalidate_all();
      }

      // 23.2.3.5 forward_list operations:
      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"));
	_GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
			      _M_message(__gnu_debug::__msg_splice_alloc)
			      ._M_sequence(*this)
			      ._M_sequence(__list, "__list"));
	this->_M_transfer_from_if(__list, [&__list](_Base_const_iterator __it)
	  {
	    return __it != __list._M_base().cbefore_begin()
		   && __it != __list._M_base().end();
	  });
	_Base::splice_after(__pos.base(), std::move(__list._M_base()));
      }

      void
      splice_after(const_iterator __pos, forward_list& __list)
      { splice_after(__pos, std::move(__list)); }

      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_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
			      _M_message(__gnu_debug::__msg_splice_alloc)
			      ._M_sequence(*this)
			      ._M_sequence(__list, "__list"));

	// _GLIBCXX_RESOLVE_LIB_DEFECTS
	// 250. splicing invalidates iterators
	_Base_const_iterator __next = std::next(__i.base());
	this->_M_transfer_from_if(__list, [__next](_Base_const_iterator __it)
	  { return __it == __next; });
	_Base::splice_after(__pos.base(), std::move(__list._M_base()),
			    __i.base());
      }

      void
      splice_after(const_iterator __pos, forward_list& __list,
		   const_iterator __i)
      { splice_after(__pos, std::move(__list), __i); }

      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"));
	_GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
			      _M_message(__gnu_debug::__msg_splice_alloc)
			      ._M_sequence(*this)
			      ._M_sequence(__list, "__list"));

	for (_Base_const_iterator __tmp = std::next(__before.base());
	     __tmp != __last.base(); ++__tmp)
	  {
	    _GLIBCXX_DEBUG_VERIFY(__tmp != __list._M_base().end(),
				  _M_message(__gnu_debug::__msg_valid_range2)
				  ._M_sequence(__list, "list")
				  ._M_iterator(__before, "before")
				  ._M_iterator(__last, "last"));
	    _GLIBCXX_DEBUG_VERIFY(&__list != this || __tmp != __pos.base(),
                                  _M_message(__gnu_debug::__msg_splice_overlap)
                                  ._M_iterator(__tmp, "position")
				  ._M_iterator(__before, "before")
				  ._M_iterator(__last, "last"));
	    // _GLIBCXX_RESOLVE_LIB_DEFECTS
	    // 250. splicing invalidates iterators
	    this->_M_transfer_from_if(__list, [__tmp](_Base_const_iterator __it)
	      { return __it == __tmp; });
	  }

	_Base::splice_after(__pos.base(), std::move(__list._M_base()),
			    __before.base(), __last.base());
      }

      void
      splice_after(const_iterator __pos, forward_list& __list,
		   const_iterator __before, const_iterator __last)
      { splice_after(__pos, std::move(__list), __before, __last); }

      void
      remove(const _Tp& __val)
      {
	_Base_iterator __x = _Base::before_begin();
	_Base_iterator __old = __x++;
	while (__x != _Base::end())
	  {
	    if (*__x == __val)
	      __x = _M_erase_after(__old);
	    else
	      __old = __x++;
	  }
      }

      template<typename _Pred>
        void
        remove_if(_Pred __pred)
	{
	  _Base_iterator __x = _Base::before_begin();
	  _Base_iterator __old = __x++;
	  while (__x != _Base::end())
	    {
	      if (__pred(*__x))
		__x = _M_erase_after(__old);
	      else
		__old = __x++;
	    }
	}

      void
      unique()
      {
	_Base_iterator __first = _Base::begin();
	_Base_iterator __last = _Base::end();
	if (__first == __last)
	  return;
	_Base_iterator __next = std::next(__first);
	while (__next != __last)
	  {
	    if (*__first == *__next)
	      __next = _M_erase_after(__first);
	    else
	      __first = __next++;
	  }
      }

      template<typename _BinPred>
        void
        unique(_BinPred __binary_pred)
	{
	  _Base_iterator __first = _Base::begin();
	  _Base_iterator __last = _Base::end();
	  if (__first == __last)
	    return;
	  _Base_iterator __next = std::next(__first);
	  while (__next != __last)
	    {
	      if (__binary_pred(*__first, *__next))
		__next = _M_erase_after(__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());
	  this->_M_transfer_from_if(__list, [&__list](_Base_const_iterator __it)
	    {
	      return __it != __list._M_base().cbefore_begin()
		     && __it != __list._M_base().cend();
	    });
	  _Base::merge(std::move(__list._M_base()));
	}
      }

      void
      merge(forward_list& __list)
      { merge(std::move(__list)); }

      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);
	    this->_M_transfer_from_if(__list,
				      [&__list](_Base_const_iterator __it)
	      {
	        return __it != __list._M_base().cbefore_begin()
		       && __it != __list._M_base().cend();
	      });
	    _Base::merge(std::move(__list._M_base()), __comp);
	  }
	}

      template<typename _Comp>
        void
        merge(forward_list& __list, _Comp __comp)
        { merge(std::move(__list), __comp); }

      using _Base::sort;
      using _Base::reverse;

      _Base&
      _M_base() noexcept       { return *this; }

      const _Base&
      _M_base() const noexcept { return *this; }

    private:
      void
      _M_invalidate_all()
      {
	this->_M_invalidate_if([this](_Base_const_iterator __it)
	  {
	    return __it != this->_M_base().cbefore_begin()
		   && __it != this->_M_base().cend();
	  });
      }
      typedef __gnu_debug::_Safe_iterator_base _Safe_iterator_base;
      static void
      _M_swap_aux(forward_list& __lhs,
		  _Safe_iterator_base*& __lhs_iterators,
		  forward_list& __rhs,
		  _Safe_iterator_base*& __rhs_iterators);
      void _M_swap(forward_list& __list);
    };

   template<typename _Tp, typename _Alloc>
    void
    forward_list<_Tp, _Alloc>::
    _M_swap_aux(forward_list<_Tp, _Alloc>& __lhs,
		__gnu_debug::_Safe_iterator_base*& __lhs_iterators,
		forward_list<_Tp, _Alloc>& __rhs,
		__gnu_debug::_Safe_iterator_base*& __rhs_iterators)
    {
      using __gnu_debug::_Safe_iterator_base;
      _Safe_iterator_base* __bbegin_its = 0;
      _Safe_iterator_base* __last_bbegin = 0;
      for (_Safe_iterator_base* __iter = __lhs_iterators; __iter;)
	{
	  // Even iterator are casted to const_iterator, not a problem.
	  const_iterator* __victim = static_cast<const_iterator*>(__iter);
	  __iter = __iter->_M_next;
	  if (__victim->base() == __rhs._M_base().cbefore_begin())
	    {
	      __victim->_M_unlink();
	      if (__lhs_iterators == __victim)
		__lhs_iterators = __victim->_M_next;
	      if (__bbegin_its)
		{
		  __victim->_M_next = __bbegin_its;
		  __bbegin_its->_M_prior = __victim;
		}
	      else
		__last_bbegin = __victim;
	      __bbegin_its = __victim;
	    }
	  else
	    __victim->_M_sequence = &__lhs;
	}

      if (__bbegin_its)
	{
	  if (__rhs_iterators)
	    {
	      __rhs_iterators->_M_prior = __last_bbegin;
	      __last_bbegin->_M_next = __rhs_iterators;
	    }
	  __rhs_iterators = __bbegin_its;
	}
    }

  /* Special forward_list _M_swap version that do not swap the
   * before-begin ownership.*/
  template<typename _Tp, typename _Alloc>
    void
    forward_list<_Tp, _Alloc>::
    _M_swap(forward_list<_Tp, _Alloc>& __list)
    {
      __gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());
      std::swap(this->_M_iterators, __list._M_iterators);
      std::swap(this->_M_const_iterators, __list._M_const_iterators);
      // Useless, always 1 on forward_list
      //std::swap(this->_M_version, __list._M_version);
      _Safe_iterator_base* __this_its = this->_M_iterators;
      _M_swap_aux(__list, __list._M_iterators, *this, this->_M_iterators);
      _Safe_iterator_base* __this_const_its = this->_M_const_iterators;
      _M_swap_aux(__list, __list._M_const_iterators, *this,
		  this->_M_const_iterators);
      _M_swap_aux(*this, __this_its, __list, __list._M_iterators);
      _M_swap_aux(*this, __this_const_its, __list, __list._M_const_iterators);
    }

  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 std::__debug::forward_list<_Tp, _Alloc> _Sequence;
      typedef typename _Sequence::const_iterator _It;
      typedef typename _It::iterator_type _BaseIt;

      static bool
      _S_Is(_BaseIt __it, const _Sequence* __seq)
      { return __it == __seq->_M_base().cbefore_begin(); }

      static bool
      _S_Is_Beginnest(_BaseIt __it, const _Sequence* __seq)
      { return _S_Is(__it, __seq); }
    };
}

#endif
@


1.1.1.1
log
@import GCC 4.8 branch at r206687.

highlights from: http://gcc.gnu.org/gcc-4.6/changes.html

   GCC now has stricter checks for invalid command-line options
   New -Wunused-but-set-variable and -Wunused-but-set-parameter
      warnings
   Many platforms have been obsoleted
   Link-time optimization improvements
   A new switch -fstack-usage has been added
   A new function attribute leaf was introduced
   A new warning, enabled by -Wdouble-promotion
   Support for selectively enabling and disabling warnings via
      #pragma GCC diagnostic has been added
   There is now experimental support for some features from the
      upcoming C1X revision of the ISO C standard
   Improved experimental support for the upcoming C++0x ISO C++
      standard
   G++ now issues clearer diagnostics in several cases
   Updates for ARM, x86, MIPS, PPC/PPC64, SPARC
   Darwin, FreeBSD, Solaris 2, MinGW and Cygwin now all support
      __float128 on 32-bit and 64-bit x86 targets. [*1]

highlights from: http://gcc.gnu.org/gcc-4.7/changes.html

   The -fconserve-space flag has been deprecated
   Support for a new parameter --param case-values-threshold=n
      was added
   Interprocedural and Link-time optimization improvements
   A new built-in, __builtin_assume_aligned, has been added
   A new warning option -Wunused-local-typedefs was added
   A new experimental command-line option -ftrack-macro-expansion
      was added
   Support for atomic operations specifying the C++11/C11 memory
      model has been added
   There is support for some more features from the C11 revision
      of the ISO C standard
   Improved experimental support for the new ISO C++ standard,
      C++11
   Updates for ARM, x86, MIPS, PPC/PPC64, SH, SPARC, TILE*
   A new option (-grecord-gcc-switches) was added

highlights from: http://gcc.gnu.org/gcc-4.8/changes.html

   GCC now uses C++ as its implementation language.  This means
      that to build GCC from sources, you will need a C++
      compiler that understands C++ 2003
   DWARF4 is now the default when generating DWARF debug
      information
   A new general optimization level, -Og, has been introduced
   A new option -ftree-partial-pre was added
   The option -fconserve-space has been removed
   The command-line options -fipa-struct-reorg and
      -fipa-matrix-reorg have been removed
   Interprocedural and Link-time optimization improvements
   AddressSanitizer, a fast memory error detector, has been
      added  [*2]
   A new -Wsizeof-pointer-memaccess warning has been added
   G++ now supports a -std=c++1y option for experimentation
      with features proposed for the next revision of the
      standard, expected around 2014
   Improved experimental support for the new ISO C++ standard,
      C++11
   A new port has been added to support AArch64
   Updates for ARM, x86, MIPS, PPC/PPC64, SH, SPARC, TILE*


[*1] we should support this too!
[*2] we should look into this.
     https://code.google.com/p/address-sanitizer/
@
text
@@


1.1.1.2
log
@import GCC 5.3.0.  see these urls for details which are too large to
include here:

	http://gcc.gnu.org/gcc-4.9/changes.html
	http://gcc.gnu.org/gcc-5/changes.html

(note that GCC 5.x is a release stream like GCC 4.9.x, 4.8.x, etc.)


the main issues we will have are:

The default mode for C is now -std=gnu11 instead of -std=gnu89.

ARM:
The deprecated option -mwords-little-endian has been removed.
The options -mapcs, -mapcs-frame, -mtpcs-frame and -mtpcs-leaf-frame
 which are only applicable to the old ABI have been deprecated.

MIPS:
The o32 ABI has been modified and extended. The o32 64-bit
 floating-point register support is now obsolete and has been removed.
 It has been replaced by three ABI extensions FPXX, FP64A, and FP64.
 The meaning of the -mfp64 command-line option has changed. It is now
 used to enable the FP64A and FP64 ABI extensions.
@
text
@d3 1
a3 1
// Copyright (C) 2010-2015 Free Software Foundation, Inc.
a35 1
#include <debug/safe_container.h>
a37 132
namespace __gnu_debug
{
  /// Special iterators swap and invalidation for forward_list because of the
  /// before_begin iterator.
  template<typename _SafeSequence>
    class _Safe_forward_list
    : public _Safe_sequence<_SafeSequence>
    {
      _SafeSequence&
      _M_this() noexcept
      { return *static_cast<_SafeSequence*>(this); }

      static void
      _M_swap_aux(_Safe_sequence_base& __lhs,
		  _Safe_iterator_base*& __lhs_iterators,
		  _Safe_sequence_base& __rhs,
		  _Safe_iterator_base*& __rhs_iterators);

      void _M_swap_single(_Safe_sequence_base&) noexcept;

    protected:
      void
      _M_invalidate_all()
      {
	using _Base_const_iterator = __decltype(_M_this()._M_base().cend());
	this->_M_invalidate_if([this](_Base_const_iterator __it)
	{
	  return __it != _M_this()._M_base().cbefore_begin()
	    && __it != _M_this()._M_base().cend(); });
      }

      void _M_swap(_Safe_sequence_base&) noexcept;
    };

   template<typename _SafeSequence>
    void
    _Safe_forward_list<_SafeSequence>::
    _M_swap_aux(_Safe_sequence_base& __lhs,
		_Safe_iterator_base*& __lhs_iterators,
		_Safe_sequence_base& __rhs,
		_Safe_iterator_base*& __rhs_iterators)
    {
      using const_iterator = typename _SafeSequence::const_iterator;
      _Safe_iterator_base* __bbegin_its = 0;
      _Safe_iterator_base* __last_bbegin = 0;
      _SafeSequence& __rseq = static_cast<_SafeSequence&>(__rhs);

      for (_Safe_iterator_base* __iter = __lhs_iterators; __iter;)
	{
	  // Even iterator is cast to const_iterator, not a problem.
	  _Safe_iterator_base* __victim_base = __iter;
	  const_iterator* __victim =
	    static_cast<const_iterator*>(__victim_base);
	  __iter = __iter->_M_next;
	  if (__victim->base() == __rseq._M_base().cbefore_begin())
	    {
	      __victim->_M_unlink();
	      if (__lhs_iterators == __victim_base)
		__lhs_iterators = __victim_base->_M_next;
	      if (__bbegin_its)
		{
		  __victim_base->_M_next = __bbegin_its;
		  __bbegin_its->_M_prior = __victim_base;
		}
	      else
		__last_bbegin = __victim_base;
	      __bbegin_its = __victim_base;
	    }
	  else
	    __victim_base->_M_sequence = &__lhs;
	}

      if (__bbegin_its)
	{
	  if (__rhs_iterators)
	    {
	      __rhs_iterators->_M_prior = __last_bbegin;
	      __last_bbegin->_M_next = __rhs_iterators;
	    }
	  __rhs_iterators = __bbegin_its;
	}
    }

   template<typename _SafeSequence>
    void
    _Safe_forward_list<_SafeSequence>::
    _M_swap_single(_Safe_sequence_base& __other) noexcept
    {
      std::swap(_M_this()._M_iterators, __other._M_iterators);
      std::swap(_M_this()._M_const_iterators, __other._M_const_iterators);
      // Useless, always 1 on forward_list
      //std::swap(_M_this()_M_version, __other._M_version);
      _Safe_iterator_base* __this_its = _M_this()._M_iterators;
      _M_swap_aux(__other, __other._M_iterators,
		  _M_this(), _M_this()._M_iterators);
      _Safe_iterator_base* __this_const_its = _M_this()._M_const_iterators;
      _M_swap_aux(__other, __other._M_const_iterators,
		  _M_this(), _M_this()._M_const_iterators);
      _M_swap_aux(_M_this(), __this_its,
		  __other, __other._M_iterators);
      _M_swap_aux(_M_this(), __this_const_its,
		  __other, __other._M_const_iterators);
    }

  /* Special forward_list _M_swap version that does not swap the
   * before-begin ownership.*/
   template<typename _SafeSequence>
    void
    _Safe_forward_list<_SafeSequence>::
    _M_swap(_Safe_sequence_base& __other) noexcept
    {
      // We need to lock both sequences to swap
      using namespace __gnu_cxx;
      __mutex *__this_mutex = &_M_this()._M_get_mutex();
      __mutex *__other_mutex =
	&static_cast<_SafeSequence&>(__other)._M_get_mutex();
      if (__this_mutex == __other_mutex)
	{
	  __scoped_lock __lock(*__this_mutex);
	  _M_swap_single(__other);
	}
      else
	{
	  __scoped_lock __l1(__this_mutex < __other_mutex
			     ? *__this_mutex : *__other_mutex);
	  __scoped_lock __l2(__this_mutex < __other_mutex
			     ? *__other_mutex : *__this_mutex);
	  _M_swap_single(__other);
	}
    }
}

d45 2
a46 3
    : public __gnu_debug::_Safe_container<
	forward_list<_Tp, _Alloc>, _Alloc, __gnu_debug::_Safe_forward_list>,
      public _GLIBCXX_STD_C::forward_list<_Tp, _Alloc>
d48 7
a54 3
      typedef _GLIBCXX_STD_C::forward_list<_Tp, _Alloc>		_Base;
      typedef __gnu_debug::_Safe_container<
	forward_list, _Alloc, __gnu_debug::_Safe_forward_list>	_Safe;
d56 1
a56 2
      typedef typename _Base::iterator		_Base_iterator;
      typedef typename _Base::const_iterator	_Base_const_iterator;
d59 2
a60 2
      typedef typename _Base::reference		reference;
      typedef typename _Base::const_reference	const_reference;
d62 12
a73 12
      typedef __gnu_debug::_Safe_iterator<
	_Base_iterator, forward_list>		iterator;
      typedef __gnu_debug::_Safe_iterator<
	_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 typename _Base::allocator_type	allocator_type;
      typedef typename _Base::pointer		pointer;
      typedef typename _Base::const_pointer	const_pointer;
d77 1
a77 1
      forward_list(const allocator_type& __al = allocator_type())
d80 1
a80 1
      forward_list(const forward_list& __list, const allocator_type& __al)
d84 8
a91 4
      forward_list(forward_list&& __list, const allocator_type& __al)
	: _Safe(std::move(__list._M_safe()), __al),
	  _Base(std::move(__list._M_base()), __al)
      { }
d94 1
a94 1
      forward_list(size_type __n, const allocator_type& __al = allocator_type())
d99 1
a99 1
		   const allocator_type& __al = allocator_type())
d106 2
a107 2
		     const allocator_type& __al = allocator_type())
	: _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
d110 1
a110 1
	{ }
d112 3
a114 1
      forward_list(const forward_list&) = default;
d116 5
a120 1
      forward_list(forward_list&&) = default;
d123 1
a123 1
		   const allocator_type& __al = allocator_type())
d127 2
a128 1
      ~forward_list() = default;
d131 6
a136 1
      operator=(const forward_list&) = default;
d139 14
a152 1
      operator=(forward_list&&) = default;
d157 1
a157 1
	_M_base() = __il;
d159 1
a159 1
	return *this;
d165 2
a166 2
	assign(_InputIterator __first, _InputIterator __last)
	{
d171 1
a171 1
	}
d295 4
a298 4
	iterator
	insert_after(const_iterator __pos,
		     _InputIterator __first, _InputIterator __last)
	{
d304 1
a304 1
	}
d350 1
a350 1
	noexcept( noexcept(declval<_Base>().swap(__list)) )
d352 2
a353 1
	_Safe::_M_swap(__list);
d355 1
d383 1
a383 1
	  }
d411 1
a411 1
	  }
d425 1
a425 1
	__glibcxx_check_insert_after(__pos);
d480 1
a480 1
	__glibcxx_check_insert_after(__pos);
d511 2
a512 2
				  _M_message(__gnu_debug::__msg_splice_overlap)
				  ._M_iterator(__tmp, "position")
d545 2
a546 2
	void
	remove_if(_Pred __pred)
d577 2
a578 2
	void
	unique(_BinPred __binary_pred)
d616 2
a617 2
	void
	merge(forward_list&& __list, _Comp __comp)
d627 1
a627 1
		return __it != __list._M_base().cbefore_begin()
d635 3
a637 3
	void
	merge(forward_list& __list, _Comp __comp)
	{ merge(std::move(__list), __comp); }
d643 1
a643 1
      _M_base() noexcept { return *this; }
d647 18
d667 66
d736 1
a736 1
	       const forward_list<_Tp, _Alloc>& __ly)
d742 1
a742 1
	      const forward_list<_Tp, _Alloc>& __ly)
d748 1
a748 1
	       const forward_list<_Tp, _Alloc>& __ly)
d755 1
a755 1
	      const forward_list<_Tp, _Alloc>& __ly)
d762 1
a762 1
	       const forward_list<_Tp, _Alloc>& __ly)
d769 1
a769 1
	       const forward_list<_Tp, _Alloc>& __ly)
d788 2
d791 7
a797 12
      template<typename _Iterator>
	static bool
	_S_Is(const _Safe_iterator<_Iterator, _Sequence>& __it)
	{
	  return
	    __it.base() == __it._M_get_sequence()->_M_base().before_begin();
	}

      template<typename _Iterator>
	static bool
	_S_Is_Beginnest(const _Safe_iterator<_Iterator, _Sequence>& __it)
	{ return _S_Is(__it); }
a798 7

#ifndef _GLIBCXX_DEBUG_PEDANTIC
  template<class _Tp, class _Alloc>
    struct _Insert_range_from_self_is_safe<
      std::__debug::forward_list<_Tp, _Alloc> >
    { enum { __value = 1 }; };
#endif
@


1.1.1.3
log
@import GCC 6.4.0.  see this url for details which are too large to
include here:

   http://gcc.gnu.org/gcc-6/changes.html

the main visible changes appear to be:

- The default mode for C++ is now -std=gnu++14 instead of -std=gnu++98.
- The C and C++ compilers now support attributes on enumerators.
- Diagnostics can now contain "fix-it hints"
- more warnings (some added to -Wall)
@
text
@d3 1
a3 1
// Copyright (C) 2010-2016 Free Software Foundation, Inc.
a38 7
// Special validity check for forward_list ranges.
#define __glibcxx_check_valid_fl_range(_First,_Last,_Dist)		\
_GLIBCXX_DEBUG_VERIFY(_First._M_valid_range(_Last, _Dist, false),	\
		      _M_message(__gnu_debug::__msg_valid_range)	\
		      ._M_iterator(_First, #_First)			\
		      ._M_iterator(_Last, #_Last))

d108 1
a108 1
	    __victim_base->_M_sequence = std::__addressof(__lhs);
a206 3

      forward_list() = default;

d208 1
a208 1
      forward_list(const allocator_type& __al) noexcept
d269 3
a271 9
	  typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
	  __glibcxx_check_valid_range2(__first, __last, __dist);

	  if (__dist.second >= __gnu_debug::__dp_sign)
	    _Base::assign(__gnu_debug::__unsafe(__first),
			  __gnu_debug::__unsafe(__last));
	  else
	    _Base::assign(__first, __last);

d401 5
a405 13
	  typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
	  __glibcxx_check_insert_range_after(__pos, __first, __last, __dist);

	  if (__dist.second >= __gnu_debug::__dp_sign)
	    return
	      {
		_Base::insert_after(__pos.base(),
				    __gnu_debug::__unsafe(__first),
				    __gnu_debug::__unsafe(__last)),
		this
	      };
	  else
	    return { _Base::insert_after(__pos.base(), __first, __last), this };
d452 1
a452 1
	noexcept( noexcept(declval<_Base&>().swap(__list)) )
d526 1
a526 1
	_GLIBCXX_DEBUG_VERIFY(std::__addressof(__list) != this,
d553 1
a553 1
	_GLIBCXX_DEBUG_VERIFY(__i._M_attached_to(std::__addressof(__list)),
a579 2
	typename __gnu_debug::_Distance_traits<const_iterator>::__type __dist;
	auto __listptr = std::__addressof(__list);
d581 2
a582 2
	__glibcxx_check_valid_fl_range(__before, __last, __dist);
	_GLIBCXX_DEBUG_VERIFY(__before._M_attached_to(__listptr),
d610 1
a610 1
	    _GLIBCXX_DEBUG_VERIFY(__listptr != this || __tmp != __pos.base(),
d697 1
a697 1
	if (this != std::__addressof(__list))
d719 1
a719 1
	  if (this != std::__addressof(__list))
d791 2
a792 2
    swap(forward_list<_Tp, _Alloc>& __lx, forward_list<_Tp, _Alloc>& __ly)
    noexcept(noexcept(__lx.swap(__ly)))
d800 1
a800 1
  template<typename _Tp, typename _Alloc>
a818 13
  template<typename _Tp, typename _Alloc>
    struct _Sequence_traits<std::__debug::forward_list<_Tp, _Alloc> >
    {
      typedef typename std::__debug::forward_list<_Tp, _Alloc>::iterator _It;

      static typename _Distance_traits<_It>::__type
      _S_size(const std::__debug::forward_list<_Tp, _Alloc>& __seq)
      {
	return __seq.empty()
	  ? std::make_pair(0, __dp_exact) : std::make_pair(1, __dp_equality);
      }
    };

@


1.1.1.3.4.1
log
@Sync with HEAD
@
text
@d3 1
a3 1
// Copyright (C) 2010-2017 Free Software Foundation, Inc.
@


1.1.1.3.4.2
log
@Mostly merge changes from HEAD upto 20200411
@
text
@d3 1
a3 1
// Copyright (C) 2010-2018 Free Software Foundation, Inc.
a774 10
#if __cpp_deduction_guides >= 201606
  template<typename _InputIterator, typename _ValT
	     = typename iterator_traits<_InputIterator>::value_type,
	   typename _Allocator = allocator<_ValT>,
	   typename = _RequireInputIter<_InputIterator>,
	   typename = _RequireAllocator<_Allocator>>
    forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
      -> forward_list<_ValT, _Allocator>;
#endif

@


1.1.1.3.2.1
log
@Sync with HEAD
@
text
@d3 1
a3 1
// Copyright (C) 2010-2017 Free Software Foundation, Inc.
@


1.1.1.4
log
@import GCC 7.4.0.  main changes include:

The non-standard C++0x type traits has_trivial_default_constructor,
has_trivial_copy_constructor and has_trivial_copy_assign have been
removed.

On ARM targets (arm*-*-*), a bug introduced in GCC 5 that affects
conformance to the procedure call standard (AAPCS) has been fixed.

Many optimiser improvements

DWARF-5 support.

Many new and enhanced warnings.

Warnings about format strings now underline the pertinent part of
the string, and can offer suggested fixes.

Several new warnings related to buffer overflows and buffer
truncation.

New __builtin_add_overflow_p, __builtin_sub_overflow_p,
__builtin_mul_overflow_p built-ins added that test for overflow.

The C++ front end has experimental support for all of the current
C++17 draft.

The -fverbose-asm option has been expanded to prints comments
showing the source lines that correspond to the assembly.

The gcc and g++ driver programs will now provide suggestions for
misspelled arguments to command-line options.


AArch64 specific:

GCC has been updated to the latest revision of the procedure call
standard (AAPCS64) to provide support for parameter passing when
data types have been over-aligned.

The ARMv8.2-A and ARMv8.3-A architecture are now supported.

ARM specific:

Support for the ARMv5 and ARMv5E architectures has been
deprecated (which have no known implementations).

A new command-line option -mpure-code has been added. It does not
allow constant data to be placed in code sections.

x86 specific:

Support for the AVX-512 4FMAPS, 4VNNIW, VPOPCNTDQ and Software
Guard Extensions (SGX) ISA extensions has been added.

PPC specific:

GCC now diagnoses inline assembly that clobbers register r2.

RISC-V specific:

Support for the RISC-V instruction set has been added.

SH specific:

Support for SH5/SH64 has been removed.

Support for SH2A has been enhanced.
@
text
@d3 1
a3 1
// Copyright (C) 2010-2017 Free Software Foundation, Inc.
@


1.1.1.5
log
@import GCC 8.3.  it includes these new features:
- many optimisations improved: inter-procedural, profile-directed,
  LTO, loops including user-controllable unroll support, and more.
- columns numbers added to line numbers in dwarf
- gcov extended significantly
- many sanitizer updates
- many new warning messages
- many better hints and more useful error messages
- minor ABI changes on x86-64 libstdc++, and some c++17 modes
- draft c++2a features
- better c++17 experimental support
- Armv8.4-A supported, better 8.2-A and 8.3-A support, including
  32 bit arm port.  cortex a-55, a-75 and a-55.a-75 combo support.
- in the GCC bugzilla, 8.1 shows 1149 bugs fixed, 8.2 shows 100, and
  8.3 shows 158.
@
text
@d3 1
a3 1
// Copyright (C) 2010-2018 Free Software Foundation, Inc.
a774 10
#if __cpp_deduction_guides >= 201606
  template<typename _InputIterator, typename _ValT
	     = typename iterator_traits<_InputIterator>::value_type,
	   typename _Allocator = allocator<_ValT>,
	   typename = _RequireInputIter<_InputIterator>,
	   typename = _RequireAllocator<_Allocator>>
    forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
      -> forward_list<_ValT, _Allocator>;
#endif

@


1.1.1.6
log
@import GCC 7.5.0.  doing this here so that the vendor branch has
the code we'll merge into gcc.old and the netbsd-9 tree gcc tree.
GCC 8.4.0 will be imported immediately on top of this again,
restoring the current status.

these PRs in the GCC bugzilla are fixed with this update:

89869 80693 89795 84272 85593 86669 87148 87647 87895 88103 88107 88563
88870 88976 89002 89187 89195 89234 89303 89314 89354 89361 89403 89412
89512 89520 89590 89621 89663 89679 89704 89734 89872 89933 90090 90208
87075 85870 89009 89242 88167 80864 81933 85890 86608 87145 88857 89024
89119 89214 89511 89612 89705 89400 81740 82186 84552 86554 87609 88105
88149 88415 88739 88903 89135 89223 89296 89505 89572 89677 89698 89710
90006 90020 90071 90328 90474 91126 91162 91812 91887 90075 88998 89945
87047 87506 88074 88656 88740 91137 89008 84010 89349 91136 91347 91995
89397 87030 60702 78884 85594 87649 87725 88181 88470 88553 88568 88588
88620 88644 88906 88949 89246 89587 89726 89768 89796 89998 90108 90756
90950 91704 88825 88983 86538 51333 89446 90220 91308 92143 89392 90213
90278 91131 91200 91510 89037 91481 87673 88418 88938 88948 90547 27221
58321 61250 67183 67958 77583 83531 86215 88648 88720 88726 89091 89466
89629 90105 90329 90585 90760 90924 91087 89222 81956 71861 35031 69455
81849 82993 85798 88138 88155 88169 88205 88206 88228 88249 88269 88376
77703 80260 82077 86248 88393 90786 57048 66089 66695 67679 68009 71723
72714 84394 85544 87734 88298 90937 91557 63891 64132 65342 68649 68717
71066 71860 71935 77746 78421 78645 78865 78983 79485 79540 85953 88326
89651 90744
@
text
@d3 1
a3 1
// Copyright (C) 2010-2017 Free Software Foundation, Inc.
d775 10
@


1.1.1.7
log
@re-import GCC 8.4.0.
@
text
@d3 1
a3 1
// Copyright (C) 2010-2018 Free Software Foundation, Inc.
a774 10
#if __cpp_deduction_guides >= 201606
  template<typename _InputIterator, typename _ValT
	     = typename iterator_traits<_InputIterator>::value_type,
	   typename _Allocator = allocator<_ValT>,
	   typename = _RequireInputIter<_InputIterator>,
	   typename = _RequireAllocator<_Allocator>>
    forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
      -> forward_list<_ValT, _Allocator>;
#endif

@


1.1.1.8
log
@initial import of GCC 9.3.0.  changes include:

- live patching support
- shell completion help
- generally better diagnostic output (less verbose/more useful)
- diagnostics and optimisation choices can be emitted in json
- asan memory usage reduction
- many general, and specific to switch, inter-procedure,
  profile and link-time optimisations.  from the release notes:
  "Overall compile time of Firefox 66 and LibreOffice 6.2.3 on
  an 8-core machine was reduced by about 5% compared to GCC 8.3"
- OpenMP 5.0 support
- better spell-guesser
- partial experimental support for c2x and c++2a
- c++17 is no longer experimental
- arm AAPCS GCC 6-8 structure passing bug fixed, may cause
  incompatibility (restored compat with GCC 5 and earlier.)
- openrisc support
@
text
@d3 1
a3 1
// Copyright (C) 2010-2019 Free Software Foundation, Inc.
a33 5
#include <bits/c++config.h>
namespace std _GLIBCXX_VISIBILITY(default) { namespace __debug {
  template<typename _Tp, typename _Allocator> class forward_list;
} } // namespace std::__debug

a195 3
      template<typename _ItT, typename _SeqT, typename _CatT>
	friend class ::__gnu_debug::_Safe_iterator;

d244 2
a245 2
	: _Base(__gnu_debug::__base(
		  __glibcxx_check_valid_constructor_range(__first, __last)),
d311 1
a311 1
      { return { _Base::before_begin(), this }; }
d315 1
a315 1
      { return { _Base::before_begin(), this }; }
d319 1
a319 1
      { return { _Base::begin(), this }; }
d323 1
a323 1
      { return { _Base::begin(), this }; }
d327 1
a327 1
      { return { _Base::end(), this }; }
d331 1
a331 1
      { return { _Base::end(), this }; }
d335 1
a335 1
      { return { _Base::cbegin(), this }; }
d339 1
a339 1
      { return { _Base::cbefore_begin(), this }; }
d343 1
a343 1
      { return { _Base::cend(), this }; }
d364 1
a364 1
      // modifiers:
d383 1
a383 1
	  return { _Base::emplace_after(__pos.base(),
d385 1
a385 1
		   this };
d392 1
a392 1
	return { _Base::insert_after(__pos.base(), __val), this };
d399 2
a400 1
	return { _Base::insert_after(__pos.base(), std::move(__val)), this };
d407 2
a408 1
	return { _Base::insert_after(__pos.base(), __n, __val), this };
d436 1
a436 1
	return { _Base::insert_after(__pos.base(), __il), this };
d453 1
a453 1
	return { _M_erase_after(__pos.base()), this };
d463 1
a463 1
	    _GLIBCXX_DEBUG_VERIFY(__victim != _Base::cend(),
d471 1
a471 2

	return { _Base::erase_after(__pos.base(), __last.base()), this };
d656 1
a656 15
    private:
#if __cplusplus > 201703L
      using __remove_return_type = size_type;
# define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG \
      __attribute__((__abi_tag__("__cxx20")))
# define _GLIBCXX20_ONLY(__expr) __expr
#else
      using __remove_return_type = void;
# define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
# define _GLIBCXX20_ONLY(__expr)
#endif

    public:
      _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
      __remove_return_type
a658 4
	if (!this->_M_iterators && !this->_M_const_iterators)
	  return _Base::remove(__val);

	size_type __removed __attribute__((__unused__)) = 0;
a660 1
	_Base_iterator __extra = _Base::end();
d664 3
a666 17
	      {
		if (std::__addressof(*__x) != std::__addressof(__val))
		  {
		    __x = _M_erase_after(__old);
		    _GLIBCXX20_ONLY( __removed++ );
		    continue;
		  }
		else
		  __extra = __old;
	      }
	    __old = __x++;
	  }

	if (__extra != _Base::end())
	  {
	    this->_M_erase_after(__extra);
	    _GLIBCXX20_ONLY( __removed++ );
a667 2

	return _GLIBCXX20_ONLY( __removed );
d671 1
a671 1
	__remove_return_type
a673 4
	  if (!this->_M_iterators && !this->_M_const_iterators)
	    return _Base::remove_if(__pred);

	  size_type __removed __attribute__((__unused__)) = 0;
d677 2
a678 2
	    if (__pred(*__x))
	      {
d680 3
a682 6
		_GLIBCXX20_ONLY( __removed++ );
	      }
	    else
	      __old = __x++;

	  return _GLIBCXX20_ONLY( __removed );
d685 1
a685 2
      _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
      __remove_return_type
d687 14
a700 1
      { return unique(std::equal_to<_Tp>()); }
d703 1
a703 1
	__remove_return_type
a705 3
	  if (!this->_M_iterators && !this->_M_const_iterators)
	    return _Base::unique(__binary_pred);

d709 1
a709 3
	    return _GLIBCXX20_ONLY(0);

	  size_type __removed __attribute__((__unused__)) = 0;
d714 1
a714 4
		{
		  __next = _M_erase_after(__first);
		  _GLIBCXX20_ONLY( __removed++ );
		}
a717 2

	  return _GLIBCXX20_ONLY( __removed );
a719 3
#undef _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
#undef _GLIBCXX20_ONLY

@


1.1.1.9
log
@initial import of GCC 10.3.0.  main changes include:

caveats:
- ABI issue between c++14 and c++17 fixed
- profile mode is removed from libstdc++
- -fno-common is now the default

new features:
- new flags -fallocation-dce, -fprofile-partial-training,
  -fprofile-reproducible, -fprofile-prefix-path, and -fanalyzer
- many new compile and link time optimisations
- enhanced drive optimisations
- openacc 2.6 support
- openmp 5.0 features
- new warnings: -Wstring-compare and -Wzero-length-bounds
- extended warnings: -Warray-bounds, -Wformat-overflow,
  -Wrestrict, -Wreturn-local-addr, -Wstringop-overflow,
  -Warith-conversion, -Wmismatched-tags, and -Wredundant-tags
- some likely C2X features implemented
- more C++20 implemented
- many new arm & intel CPUs known

hundreds of reported bugs are fixed.  full list of changes
can be found at:

   https://gcc.gnu.org/gcc-10/changes.html
@
text
@d3 1
a3 1
// Copyright (C) 2010-2020 Free Software Foundation, Inc.
a840 7
#if __cpp_lib_three_way_comparison
  template<typename _Tp, typename _Alloc>
    constexpr __detail::__synth3way_t<_Tp>
    operator<=>(const forward_list<_Tp, _Alloc>& __x,
		const forward_list<_Tp, _Alloc>& __y)
    { return __x._M_base() <=> __y._M_base(); }
#else
a872 1
#endif // three-way comparison
d914 1
a914 1
	  ? std::make_pair(0, __dp_exact) : std::make_pair(1, __dp_sign);
@


1.1.1.10
log
@initial import of GCC 12.3.0.

major changes in GCC 11 included:

- The default mode for C++ is now -std=gnu++17 instead of -std=gnu++14.
- When building GCC itself, the host compiler must now support C++11,
  rather than C++98.
- Some short options of the gcov tool have been renamed: -i to -j and
  -j to -H.
- ThreadSanitizer improvements.
- Introduce Hardware-assisted AddressSanitizer support.
- For targets that produce DWARF debugging information GCC now defaults
  to DWARF version 5. This can produce up to 25% more compact debug
  information compared to earlier versions.
- Many optimisations.
- The existing malloc attribute has been extended so that it can be
  used to identify allocator/deallocator API pairs. A pair of new
  -Wmismatched-dealloc and -Wmismatched-new-delete warnings are added.
- Other new warnings:
  -Wsizeof-array-div, enabled by -Wall, warns about divisions of two
    sizeof operators when the first one is applied to an array and the
    divisor does not equal the size of the array element.
  -Wstringop-overread, enabled by default, warns about calls to string
    functions reading past the end of the arrays passed to them as
    arguments.
  -Wtsan, enabled by default, warns about unsupported features in
    ThreadSanitizer (currently std::atomic_thread_fence).
- Enchanced warnings:
  -Wfree-nonheap-object detects many more instances of calls to
    deallocation functions with pointers not returned from a dynamic
    memory allocation function.
  -Wmaybe-uninitialized diagnoses passing pointers or references to
    uninitialized memory to functions taking const-qualified arguments.
  -Wuninitialized detects reads from uninitialized dynamically
    allocated memory.
  -Warray-parameter warns about functions with inconsistent array forms.
  -Wvla-parameter warns about functions with inconsistent VLA forms.
- Several new features from the upcoming C2X revision of the ISO C
  standard are supported with -std=c2x and -std=gnu2x.
- Several C++20 features have been implemented.
- The C++ front end has experimental support for some of the upcoming
  C++23 draft.
- Several new C++ warnings.
- Enhanced Arm, AArch64, x86, and RISC-V CPU support.
- The implementation of how program state is tracked within
  -fanalyzer has been completely rewritten with many enhancements.

see https://gcc.gnu.org/gcc-11/changes.html for a full list.

major changes in GCC 12 include:

- An ABI incompatibility between C and C++ when passing or returning
  by value certain aggregates containing zero width bit-fields has
  been discovered on various targets. x86-64, ARM and AArch64
  will always ignore them (so there is a C ABI incompatibility
  between GCC 11 and earlier with GCC 12 or later), PowerPC64 ELFv2
  always take them into account (so there is a C++ ABI
  incompatibility, GCC 4.4 and earlier compatible with GCC 12 or
  later, incompatible with GCC 4.5 through GCC 11). RISC-V has
  changed the handling of these already starting with GCC 10. As
  the ABI requires, MIPS takes them into account handling function
  return values so there is a C++ ABI incompatibility with GCC 4.5
  through 11.
- STABS: Support for emitting the STABS debugging format is
  deprecated and will be removed in the next release. All ports now
  default to emit DWARF (version 2 or later) debugging info or are
  obsoleted.
- Vectorization is enabled at -O2 which is now equivalent to the
  original -O2 -ftree-vectorize -fvect-cost-model=very-cheap.
- GCC now supports the ShadowCallStack sanitizer.
- Support for __builtin_shufflevector compatible with the clang
  language extension was added.
- Support for attribute unavailable was added.
- Support for __builtin_dynamic_object_size compatible with the
  clang language extension was added.
- New warnings:
  -Wbidi-chars warns about potentially misleading UTF-8
    bidirectional control characters.
  -Warray-compare warns about comparisons between two operands of
    array type.
- Some new features from the upcoming C2X revision of the ISO C
  standard are supported with -std=c2x and -std=gnu2x.
- Several C++23 features have been implemented.
- Many C++ enhancements across warnings and -f options.

see https://gcc.gnu.org/gcc-12/changes.html for a full list.
@
text
@d3 1
a3 1
// Copyright (C) 2010-2022 Free Software Foundation, Inc.
a203 8
      // Reference wrapper for base class. See PR libstdc++/90102.
      struct _Base_ref
      {
	_Base_ref(const _Base& __r) : _M_ref(__r) { }

	const _Base& _M_ref;
      };

d234 2
a235 5
	noexcept(
	  std::is_nothrow_constructible<_Base,
	    _Base, const allocator_type&>::value )
      : _Safe(std::move(__list), __al),
	_Base(std::move(__list), __al)
d243 1
a243 1
      forward_list(size_type __n, const __type_identity_t<_Tp>& __value,
a267 2
      forward_list(_Base_ref __x) : _Base(__x._M_ref) { }

d277 1
a277 1
	_Base::operator=(__il);
a316 1
      [[__nodiscard__]]
a320 1
      [[__nodiscard__]]
a324 1
      [[__nodiscard__]]
a328 1
      [[__nodiscard__]]
a332 1
      [[__nodiscard__]]
a336 1
      [[__nodiscard__]]
a340 1
      [[__nodiscard__]]
a344 1
      [[__nodiscard__]]
a348 1
      [[__nodiscard__]]
a357 1
      [[__nodiscard__]]
a364 1
      [[__nodiscard__]]
d445 10
d459 1
a459 5

	_Base_const_iterator __next = std::next(__pos.base());
	this->_M_invalidate_if([__next](_Base_const_iterator __it)
			       { return __it == __next; });
	return { _Base::erase_after(__pos.base()), this };
d569 1
a569 1
	_Base::splice_after(__pos.base(), std::move(__list));
d598 2
a599 1
	_Base::splice_after(__pos.base(), std::move(__list), __i.base());
d654 1
a654 1
	_Base::splice_after(__pos.base(), std::move(__list),
d684 4
a687 4
	_Base __to_destroy(get_allocator());
	_Base_const_iterator __x = _Base::cbefore_begin();
	_Base_const_iterator __old = __x++;
	while (__x != _Base::cend())
d691 8
a698 7
		_Base_const_iterator __next = std::next(__old);
		this->_M_invalidate_if([__next](_Base_const_iterator __it)
				       { return __it == __next; });
		__to_destroy.splice_after(__to_destroy.cbefore_begin(),
					  *this, __old);
		__x = __old;
		_GLIBCXX20_ONLY( __removed++ );
d700 2
d703 4
a706 1
	    __old = __x++;
a719 1
	  _Base __to_destroy(get_allocator());
d723 6
a728 11
	    {
	      if (__pred(*__x))
		{
		  this->_M_invalidate_if([__x](_Base_const_iterator __it)
					 { return __it == __x; });
		  __to_destroy.splice_after(__to_destroy.cbefore_begin(),
					    *this, __old);
		  __x = __old;
		  _GLIBCXX20_ONLY( __removed++ );
		}

a729 1
	    }
d746 2
a747 2
	  _Base_const_iterator __first = _Base::cbegin();
	  _Base_const_iterator __last = _Base::cend();
d752 1
a752 2
	  _Base __to_destroy(get_allocator());
	  _Base_const_iterator __next = std::next(__first);
d757 1
a757 5
		  this->_M_invalidate_if([__next](_Base_const_iterator __it)
					 { return __it == __next; });
		  __to_destroy.splice_after(__to_destroy.cbefore_begin(),
					    *this, __first);
		  __next = __first;
d760 2
a761 2

	      __first = __next++;
d783 1
a783 1
	  _Base::merge(std::move(__list));
d806 1
a806 1
	    _Base::merge(std::move(__list), __comp);
a832 5

  template<typename _Tp, typename _Allocator = allocator<_Tp>,
	   typename = _RequireAllocator<_Allocator>>
    forward_list(size_t, _Tp, _Allocator = _Allocator())
      -> forward_list<_Tp, _Allocator>;
@


1.1.1.11
log
@initial import of GCC 14.3.0.

major changes in GCC 13:
- improved sanitizer
- zstd debug info compression
- LTO improvements
- SARIF based diagnostic support
- new warnings: -Wxor-used-as-pow, -Wenum-int-mismatch, -Wself-move,
  -Wdangling-reference
- many new -Wanalyzer* specific warnings
- enhanced warnings: -Wpessimizing-move, -Wredundant-move
- new attributes to mark file descriptors, c++23 "assume"
- several C23 features added
- several C++23 features added
- many new features for Arm, x86, RISC-V

major changes in GCC 14:
- more strict C99 or newer support
- ia64* marked deprecated (but seemingly still in GCC 15.)
- several new hardening features
- support for "hardbool", which can have user supplied values of true/false
- explicit support for stack scrubbing upon function exit
- better auto-vectorisation support
- added clang-compatible __has_feature and __has_extension
- more C23, including -std=c23
- several C++26 features added
- better diagnostics in C++ templates
- new warnings: -Wnrvo, Welaborated-enum-base
- many new features for Arm, x86, RISC-V
- possible ABI breaking change for SPARC64 and small structures with arrays
  of floats.
@
text
@d3 1
a3 1
// Copyright (C) 2010-2024 Free Software Foundation, Inc.
@


1.1.1.1.8.1
log
@file forward_list was added on branch tls-maxphys on 2014-08-19 23:54:50 +0000
@
text
@d1 801
@


1.1.1.1.8.2
log
@Rebase to HEAD as of a few days ago.
@
text
@a0 801
// <forward_list> -*- C++ -*-

// Copyright (C) 2010-2013 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 _GLIBCXX_VISIBILITY(default)
{
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_C::forward_list<_Tp, _Alloc>,
      public __gnu_debug::_Safe_sequence<forward_list<_Tp, _Alloc> >
    {
      typedef _GLIBCXX_STD_C::forward_list<_Tp, _Alloc> _Base;

      typedef typename _Base::iterator       _Base_iterator;
      typedef typename _Base::const_iterator _Base_const_iterator;

      typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
        rebind<_GLIBCXX_STD_C::_Fwd_list_node<_Tp>>::other _Node_alloc_type;

      typedef __gnu_cxx::__alloc_traits<_Node_alloc_type> _Node_alloc_traits;

    public:
      typedef typename _Base::reference             reference;
      typedef typename _Base::const_reference       const_reference;

      typedef __gnu_debug::_Safe_iterator<_Base_iterator,
					  forward_list> iterator;
      typedef __gnu_debug::_Safe_iterator<_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._M_base()), __al)
      {
	if (__list.get_allocator() == __al)
	  this->_M_swap(__list);
	else
	  __list._M_invalidate_all();
      }

      explicit
      forward_list(size_type __n, const _Alloc& __al = _Alloc())
      : _Base(__n, __al)
      { }

      forward_list(size_type __n, const _Tp& __value,
                   const _Alloc& __al = _Alloc())
      : _Base(__n, __value, __al)
      { }

      template<typename _InputIterator,
	       typename = std::_RequireInputIter<_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) noexcept
      : _Base(std::move(__list._M_base()))
      {
	this->_M_swap(__list);
      }

      forward_list(std::initializer_list<_Tp> __il,
                   const _Alloc& __al = _Alloc())
      : _Base(__il, __al)
      { }

      ~forward_list() noexcept
      { }

      forward_list&
      operator=(const forward_list& __list)
      {
	static_cast<_Base&>(*this) = __list;
	this->_M_invalidate_all();
	return *this;
      }

      forward_list&
      operator=(forward_list&& __list)
      noexcept(_Node_alloc_traits::_S_nothrow_move())
      {
	__glibcxx_check_self_move_assign(__list);
	bool xfer_memory = _Node_alloc_traits::_S_propagate_on_move_assign()
	    || __list.get_allocator() == this->get_allocator();
	static_cast<_Base&>(*this) = std::move(__list);
	if (xfer_memory)
	  this->_M_swap(__list);
	else
	  this->_M_invalidate_all();
	__list._M_invalidate_all();
	return *this;
      }

      forward_list&
      operator=(std::initializer_list<_Tp> __il)
      {
	static_cast<_Base&>(*this) = __il;
	this->_M_invalidate_all();
        return *this;
      }

      template<typename _InputIterator,
	       typename = std::_RequireInputIter<_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() noexcept
      { return iterator(_Base::before_begin(), this); }

      const_iterator
      before_begin() const noexcept
      { return const_iterator(_Base::before_begin(), this); }

      iterator
      begin() noexcept
      { return iterator(_Base::begin(), this); }

      const_iterator
      begin() const noexcept
      { return const_iterator(_Base::begin(), this); }

      iterator
      end() noexcept
      { return iterator(_Base::end(), this); }

      const_iterator
      end() const noexcept
      { return const_iterator(_Base::end(), this); }

      const_iterator
      cbegin() const noexcept
      { return const_iterator(_Base::cbegin(), this); }

      const_iterator
      cbefore_begin() const noexcept
      { return const_iterator(_Base::cbefore_begin(), this); }

      const_iterator
      cend() const noexcept
      { 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();
      }

      // modiﬁers:

      using _Base::emplace_front;
      using _Base::push_front;

      void
      pop_front()
      {
	__glibcxx_check_nonempty();
	this->_M_invalidate_if([this](_Base_const_iterator __it)
	  { return __it == this->_M_base().cbegin(); });
	_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,
	       typename = std::_RequireInputIter<_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);
      }

    private:
      _Base_iterator
      _M_erase_after(_Base_const_iterator __pos)
      {
	_Base_const_iterator __next = std::next(__pos);
	this->_M_invalidate_if([__next](_Base_const_iterator __it)
	  { return __it == __next; });
	return _Base::erase_after(__pos);
      }
    public:
      iterator
      erase_after(const_iterator __pos)
      {
	__glibcxx_check_erase_after(__pos);
	return iterator(_M_erase_after(__pos.base()), this);
      }

      iterator
      erase_after(const_iterator __pos, const_iterator __last)
      {
	__glibcxx_check_erase_range_after(__pos, __last);
	for (_Base_const_iterator __victim = std::next(__pos.base());
	    __victim != __last.base(); ++__victim)
	  {
	    _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
				  _M_message(__gnu_debug::__msg_valid_range2)
				  ._M_sequence(*this, "this")
				  ._M_iterator(__pos, "pos")
				  ._M_iterator(__last, "last"));
	    this->_M_invalidate_if([__victim](_Base_const_iterator __it)
	      { return __it == __victim; });
	  }
	return iterator(_Base::erase_after(__pos.base(), __last.base()), this);
      }

      void
      swap(forward_list& __list)
      noexcept(_Node_alloc_traits::_S_nothrow_swap())
      {
	if (!_Node_alloc_traits::_S_propagate_on_swap())
	  __glibcxx_check_equal_allocs(__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()
	_Base_iterator __victim = _Base::begin();
	_Base_iterator __end = _Base::end();
	for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
	  ++__victim;

	for (; __victim != __end; ++__victim)
	  {
	    this->_M_invalidate_if([__victim](_Base_const_iterator __it)
	      { return __it == __victim; });
	  }

	__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())
	_Base_iterator __victim = _Base::begin();
	_Base_iterator __end = _Base::end();
	for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
	  ++__victim;

	for (; __victim != __end; ++__victim)
	  {
	    this->_M_invalidate_if([__victim](_Base_const_iterator __it)
	      { return __it == __victim; });
	  }

	__try
	  {
	    _Base::resize(__sz, __val);
	  }
	__catch(...)
	  {
	    this->_M_revalidate_singular();
	    __throw_exception_again;
          }
      }

      void
      clear() noexcept
      {
	_Base::clear();
	this->_M_invalidate_all();
      }

      // 23.2.3.5 forward_list operations:
      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"));
	_GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
			      _M_message(__gnu_debug::__msg_splice_alloc)
			      ._M_sequence(*this)
			      ._M_sequence(__list, "__list"));
	this->_M_transfer_from_if(__list, [&__list](_Base_const_iterator __it)
	  {
	    return __it != __list._M_base().cbefore_begin()
		   && __it != __list._M_base().end();
	  });
	_Base::splice_after(__pos.base(), std::move(__list._M_base()));
      }

      void
      splice_after(const_iterator __pos, forward_list& __list)
      { splice_after(__pos, std::move(__list)); }

      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_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
			      _M_message(__gnu_debug::__msg_splice_alloc)
			      ._M_sequence(*this)
			      ._M_sequence(__list, "__list"));

	// _GLIBCXX_RESOLVE_LIB_DEFECTS
	// 250. splicing invalidates iterators
	_Base_const_iterator __next = std::next(__i.base());
	this->_M_transfer_from_if(__list, [__next](_Base_const_iterator __it)
	  { return __it == __next; });
	_Base::splice_after(__pos.base(), std::move(__list._M_base()),
			    __i.base());
      }

      void
      splice_after(const_iterator __pos, forward_list& __list,
		   const_iterator __i)
      { splice_after(__pos, std::move(__list), __i); }

      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"));
	_GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
			      _M_message(__gnu_debug::__msg_splice_alloc)
			      ._M_sequence(*this)
			      ._M_sequence(__list, "__list"));

	for (_Base_const_iterator __tmp = std::next(__before.base());
	     __tmp != __last.base(); ++__tmp)
	  {
	    _GLIBCXX_DEBUG_VERIFY(__tmp != __list._M_base().end(),
				  _M_message(__gnu_debug::__msg_valid_range2)
				  ._M_sequence(__list, "list")
				  ._M_iterator(__before, "before")
				  ._M_iterator(__last, "last"));
	    _GLIBCXX_DEBUG_VERIFY(&__list != this || __tmp != __pos.base(),
                                  _M_message(__gnu_debug::__msg_splice_overlap)
                                  ._M_iterator(__tmp, "position")
				  ._M_iterator(__before, "before")
				  ._M_iterator(__last, "last"));
	    // _GLIBCXX_RESOLVE_LIB_DEFECTS
	    // 250. splicing invalidates iterators
	    this->_M_transfer_from_if(__list, [__tmp](_Base_const_iterator __it)
	      { return __it == __tmp; });
	  }

	_Base::splice_after(__pos.base(), std::move(__list._M_base()),
			    __before.base(), __last.base());
      }

      void
      splice_after(const_iterator __pos, forward_list& __list,
		   const_iterator __before, const_iterator __last)
      { splice_after(__pos, std::move(__list), __before, __last); }

      void
      remove(const _Tp& __val)
      {
	_Base_iterator __x = _Base::before_begin();
	_Base_iterator __old = __x++;
	while (__x != _Base::end())
	  {
	    if (*__x == __val)
	      __x = _M_erase_after(__old);
	    else
	      __old = __x++;
	  }
      }

      template<typename _Pred>
        void
        remove_if(_Pred __pred)
	{
	  _Base_iterator __x = _Base::before_begin();
	  _Base_iterator __old = __x++;
	  while (__x != _Base::end())
	    {
	      if (__pred(*__x))
		__x = _M_erase_after(__old);
	      else
		__old = __x++;
	    }
	}

      void
      unique()
      {
	_Base_iterator __first = _Base::begin();
	_Base_iterator __last = _Base::end();
	if (__first == __last)
	  return;
	_Base_iterator __next = std::next(__first);
	while (__next != __last)
	  {
	    if (*__first == *__next)
	      __next = _M_erase_after(__first);
	    else
	      __first = __next++;
	  }
      }

      template<typename _BinPred>
        void
        unique(_BinPred __binary_pred)
	{
	  _Base_iterator __first = _Base::begin();
	  _Base_iterator __last = _Base::end();
	  if (__first == __last)
	    return;
	  _Base_iterator __next = std::next(__first);
	  while (__next != __last)
	    {
	      if (__binary_pred(*__first, *__next))
		__next = _M_erase_after(__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());
	  this->_M_transfer_from_if(__list, [&__list](_Base_const_iterator __it)
	    {
	      return __it != __list._M_base().cbefore_begin()
		     && __it != __list._M_base().cend();
	    });
	  _Base::merge(std::move(__list._M_base()));
	}
      }

      void
      merge(forward_list& __list)
      { merge(std::move(__list)); }

      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);
	    this->_M_transfer_from_if(__list,
				      [&__list](_Base_const_iterator __it)
	      {
	        return __it != __list._M_base().cbefore_begin()
		       && __it != __list._M_base().cend();
	      });
	    _Base::merge(std::move(__list._M_base()), __comp);
	  }
	}

      template<typename _Comp>
        void
        merge(forward_list& __list, _Comp __comp)
        { merge(std::move(__list), __comp); }

      using _Base::sort;
      using _Base::reverse;

      _Base&
      _M_base() noexcept       { return *this; }

      const _Base&
      _M_base() const noexcept { return *this; }

    private:
      void
      _M_invalidate_all()
      {
	this->_M_invalidate_if([this](_Base_const_iterator __it)
	  {
	    return __it != this->_M_base().cbefore_begin()
		   && __it != this->_M_base().cend();
	  });
      }
      typedef __gnu_debug::_Safe_iterator_base _Safe_iterator_base;
      static void
      _M_swap_aux(forward_list& __lhs,
		  _Safe_iterator_base*& __lhs_iterators,
		  forward_list& __rhs,
		  _Safe_iterator_base*& __rhs_iterators);
      void _M_swap(forward_list& __list);
    };

   template<typename _Tp, typename _Alloc>
    void
    forward_list<_Tp, _Alloc>::
    _M_swap_aux(forward_list<_Tp, _Alloc>& __lhs,
		__gnu_debug::_Safe_iterator_base*& __lhs_iterators,
		forward_list<_Tp, _Alloc>& __rhs,
		__gnu_debug::_Safe_iterator_base*& __rhs_iterators)
    {
      using __gnu_debug::_Safe_iterator_base;
      _Safe_iterator_base* __bbegin_its = 0;
      _Safe_iterator_base* __last_bbegin = 0;
      for (_Safe_iterator_base* __iter = __lhs_iterators; __iter;)
	{
	  // Even iterator are casted to const_iterator, not a problem.
	  const_iterator* __victim = static_cast<const_iterator*>(__iter);
	  __iter = __iter->_M_next;
	  if (__victim->base() == __rhs._M_base().cbefore_begin())
	    {
	      __victim->_M_unlink();
	      if (__lhs_iterators == __victim)
		__lhs_iterators = __victim->_M_next;
	      if (__bbegin_its)
		{
		  __victim->_M_next = __bbegin_its;
		  __bbegin_its->_M_prior = __victim;
		}
	      else
		__last_bbegin = __victim;
	      __bbegin_its = __victim;
	    }
	  else
	    __victim->_M_sequence = &__lhs;
	}

      if (__bbegin_its)
	{
	  if (__rhs_iterators)
	    {
	      __rhs_iterators->_M_prior = __last_bbegin;
	      __last_bbegin->_M_next = __rhs_iterators;
	    }
	  __rhs_iterators = __bbegin_its;
	}
    }

  /* Special forward_list _M_swap version that do not swap the
   * before-begin ownership.*/
  template<typename _Tp, typename _Alloc>
    void
    forward_list<_Tp, _Alloc>::
    _M_swap(forward_list<_Tp, _Alloc>& __list)
    {
      __gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());
      std::swap(this->_M_iterators, __list._M_iterators);
      std::swap(this->_M_const_iterators, __list._M_const_iterators);
      // Useless, always 1 on forward_list
      //std::swap(this->_M_version, __list._M_version);
      _Safe_iterator_base* __this_its = this->_M_iterators;
      _M_swap_aux(__list, __list._M_iterators, *this, this->_M_iterators);
      _Safe_iterator_base* __this_const_its = this->_M_const_iterators;
      _M_swap_aux(__list, __list._M_const_iterators, *this,
		  this->_M_const_iterators);
      _M_swap_aux(*this, __this_its, __list, __list._M_iterators);
      _M_swap_aux(*this, __this_const_its, __list, __list._M_const_iterators);
    }

  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 std::__debug::forward_list<_Tp, _Alloc> _Sequence;
      typedef typename _Sequence::const_iterator _It;
      typedef typename _It::iterator_type _BaseIt;

      static bool
      _S_Is(_BaseIt __it, const _Sequence* __seq)
      { return __it == __seq->_M_base().cbefore_begin(); }

      static bool
      _S_Is_Beginnest(_BaseIt __it, const _Sequence* __seq)
      { return _S_Is(__it, __seq); }
    };
}

#endif
@


1.1.1.1.4.1
log
@file forward_list was added on branch yamt-pagecache on 2014-05-22 16:37:48 +0000
@
text
@d1 801
@


1.1.1.1.4.2
log
@sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs.  ("Protocol error: too many arguments")
@
text
@a0 801
// <forward_list> -*- C++ -*-

// Copyright (C) 2010-2013 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 _GLIBCXX_VISIBILITY(default)
{
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_C::forward_list<_Tp, _Alloc>,
      public __gnu_debug::_Safe_sequence<forward_list<_Tp, _Alloc> >
    {
      typedef _GLIBCXX_STD_C::forward_list<_Tp, _Alloc> _Base;

      typedef typename _Base::iterator       _Base_iterator;
      typedef typename _Base::const_iterator _Base_const_iterator;

      typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
        rebind<_GLIBCXX_STD_C::_Fwd_list_node<_Tp>>::other _Node_alloc_type;

      typedef __gnu_cxx::__alloc_traits<_Node_alloc_type> _Node_alloc_traits;

    public:
      typedef typename _Base::reference             reference;
      typedef typename _Base::const_reference       const_reference;

      typedef __gnu_debug::_Safe_iterator<_Base_iterator,
					  forward_list> iterator;
      typedef __gnu_debug::_Safe_iterator<_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._M_base()), __al)
      {
	if (__list.get_allocator() == __al)
	  this->_M_swap(__list);
	else
	  __list._M_invalidate_all();
      }

      explicit
      forward_list(size_type __n, const _Alloc& __al = _Alloc())
      : _Base(__n, __al)
      { }

      forward_list(size_type __n, const _Tp& __value,
                   const _Alloc& __al = _Alloc())
      : _Base(__n, __value, __al)
      { }

      template<typename _InputIterator,
	       typename = std::_RequireInputIter<_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) noexcept
      : _Base(std::move(__list._M_base()))
      {
	this->_M_swap(__list);
      }

      forward_list(std::initializer_list<_Tp> __il,
                   const _Alloc& __al = _Alloc())
      : _Base(__il, __al)
      { }

      ~forward_list() noexcept
      { }

      forward_list&
      operator=(const forward_list& __list)
      {
	static_cast<_Base&>(*this) = __list;
	this->_M_invalidate_all();
	return *this;
      }

      forward_list&
      operator=(forward_list&& __list)
      noexcept(_Node_alloc_traits::_S_nothrow_move())
      {
	__glibcxx_check_self_move_assign(__list);
	bool xfer_memory = _Node_alloc_traits::_S_propagate_on_move_assign()
	    || __list.get_allocator() == this->get_allocator();
	static_cast<_Base&>(*this) = std::move(__list);
	if (xfer_memory)
	  this->_M_swap(__list);
	else
	  this->_M_invalidate_all();
	__list._M_invalidate_all();
	return *this;
      }

      forward_list&
      operator=(std::initializer_list<_Tp> __il)
      {
	static_cast<_Base&>(*this) = __il;
	this->_M_invalidate_all();
        return *this;
      }

      template<typename _InputIterator,
	       typename = std::_RequireInputIter<_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() noexcept
      { return iterator(_Base::before_begin(), this); }

      const_iterator
      before_begin() const noexcept
      { return const_iterator(_Base::before_begin(), this); }

      iterator
      begin() noexcept
      { return iterator(_Base::begin(), this); }

      const_iterator
      begin() const noexcept
      { return const_iterator(_Base::begin(), this); }

      iterator
      end() noexcept
      { return iterator(_Base::end(), this); }

      const_iterator
      end() const noexcept
      { return const_iterator(_Base::end(), this); }

      const_iterator
      cbegin() const noexcept
      { return const_iterator(_Base::cbegin(), this); }

      const_iterator
      cbefore_begin() const noexcept
      { return const_iterator(_Base::cbefore_begin(), this); }

      const_iterator
      cend() const noexcept
      { 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();
      }

      // modiﬁers:

      using _Base::emplace_front;
      using _Base::push_front;

      void
      pop_front()
      {
	__glibcxx_check_nonempty();
	this->_M_invalidate_if([this](_Base_const_iterator __it)
	  { return __it == this->_M_base().cbegin(); });
	_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,
	       typename = std::_RequireInputIter<_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);
      }

    private:
      _Base_iterator
      _M_erase_after(_Base_const_iterator __pos)
      {
	_Base_const_iterator __next = std::next(__pos);
	this->_M_invalidate_if([__next](_Base_const_iterator __it)
	  { return __it == __next; });
	return _Base::erase_after(__pos);
      }
    public:
      iterator
      erase_after(const_iterator __pos)
      {
	__glibcxx_check_erase_after(__pos);
	return iterator(_M_erase_after(__pos.base()), this);
      }

      iterator
      erase_after(const_iterator __pos, const_iterator __last)
      {
	__glibcxx_check_erase_range_after(__pos, __last);
	for (_Base_const_iterator __victim = std::next(__pos.base());
	    __victim != __last.base(); ++__victim)
	  {
	    _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
				  _M_message(__gnu_debug::__msg_valid_range2)
				  ._M_sequence(*this, "this")
				  ._M_iterator(__pos, "pos")
				  ._M_iterator(__last, "last"));
	    this->_M_invalidate_if([__victim](_Base_const_iterator __it)
	      { return __it == __victim; });
	  }
	return iterator(_Base::erase_after(__pos.base(), __last.base()), this);
      }

      void
      swap(forward_list& __list)
      noexcept(_Node_alloc_traits::_S_nothrow_swap())
      {
	if (!_Node_alloc_traits::_S_propagate_on_swap())
	  __glibcxx_check_equal_allocs(__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()
	_Base_iterator __victim = _Base::begin();
	_Base_iterator __end = _Base::end();
	for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
	  ++__victim;

	for (; __victim != __end; ++__victim)
	  {
	    this->_M_invalidate_if([__victim](_Base_const_iterator __it)
	      { return __it == __victim; });
	  }

	__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())
	_Base_iterator __victim = _Base::begin();
	_Base_iterator __end = _Base::end();
	for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
	  ++__victim;

	for (; __victim != __end; ++__victim)
	  {
	    this->_M_invalidate_if([__victim](_Base_const_iterator __it)
	      { return __it == __victim; });
	  }

	__try
	  {
	    _Base::resize(__sz, __val);
	  }
	__catch(...)
	  {
	    this->_M_revalidate_singular();
	    __throw_exception_again;
          }
      }

      void
      clear() noexcept
      {
	_Base::clear();
	this->_M_invalidate_all();
      }

      // 23.2.3.5 forward_list operations:
      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"));
	_GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
			      _M_message(__gnu_debug::__msg_splice_alloc)
			      ._M_sequence(*this)
			      ._M_sequence(__list, "__list"));
	this->_M_transfer_from_if(__list, [&__list](_Base_const_iterator __it)
	  {
	    return __it != __list._M_base().cbefore_begin()
		   && __it != __list._M_base().end();
	  });
	_Base::splice_after(__pos.base(), std::move(__list._M_base()));
      }

      void
      splice_after(const_iterator __pos, forward_list& __list)
      { splice_after(__pos, std::move(__list)); }

      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_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
			      _M_message(__gnu_debug::__msg_splice_alloc)
			      ._M_sequence(*this)
			      ._M_sequence(__list, "__list"));

	// _GLIBCXX_RESOLVE_LIB_DEFECTS
	// 250. splicing invalidates iterators
	_Base_const_iterator __next = std::next(__i.base());
	this->_M_transfer_from_if(__list, [__next](_Base_const_iterator __it)
	  { return __it == __next; });
	_Base::splice_after(__pos.base(), std::move(__list._M_base()),
			    __i.base());
      }

      void
      splice_after(const_iterator __pos, forward_list& __list,
		   const_iterator __i)
      { splice_after(__pos, std::move(__list), __i); }

      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"));
	_GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
			      _M_message(__gnu_debug::__msg_splice_alloc)
			      ._M_sequence(*this)
			      ._M_sequence(__list, "__list"));

	for (_Base_const_iterator __tmp = std::next(__before.base());
	     __tmp != __last.base(); ++__tmp)
	  {
	    _GLIBCXX_DEBUG_VERIFY(__tmp != __list._M_base().end(),
				  _M_message(__gnu_debug::__msg_valid_range2)
				  ._M_sequence(__list, "list")
				  ._M_iterator(__before, "before")
				  ._M_iterator(__last, "last"));
	    _GLIBCXX_DEBUG_VERIFY(&__list != this || __tmp != __pos.base(),
                                  _M_message(__gnu_debug::__msg_splice_overlap)
                                  ._M_iterator(__tmp, "position")
				  ._M_iterator(__before, "before")
				  ._M_iterator(__last, "last"));
	    // _GLIBCXX_RESOLVE_LIB_DEFECTS
	    // 250. splicing invalidates iterators
	    this->_M_transfer_from_if(__list, [__tmp](_Base_const_iterator __it)
	      { return __it == __tmp; });
	  }

	_Base::splice_after(__pos.base(), std::move(__list._M_base()),
			    __before.base(), __last.base());
      }

      void
      splice_after(const_iterator __pos, forward_list& __list,
		   const_iterator __before, const_iterator __last)
      { splice_after(__pos, std::move(__list), __before, __last); }

      void
      remove(const _Tp& __val)
      {
	_Base_iterator __x = _Base::before_begin();
	_Base_iterator __old = __x++;
	while (__x != _Base::end())
	  {
	    if (*__x == __val)
	      __x = _M_erase_after(__old);
	    else
	      __old = __x++;
	  }
      }

      template<typename _Pred>
        void
        remove_if(_Pred __pred)
	{
	  _Base_iterator __x = _Base::before_begin();
	  _Base_iterator __old = __x++;
	  while (__x != _Base::end())
	    {
	      if (__pred(*__x))
		__x = _M_erase_after(__old);
	      else
		__old = __x++;
	    }
	}

      void
      unique()
      {
	_Base_iterator __first = _Base::begin();
	_Base_iterator __last = _Base::end();
	if (__first == __last)
	  return;
	_Base_iterator __next = std::next(__first);
	while (__next != __last)
	  {
	    if (*__first == *__next)
	      __next = _M_erase_after(__first);
	    else
	      __first = __next++;
	  }
      }

      template<typename _BinPred>
        void
        unique(_BinPred __binary_pred)
	{
	  _Base_iterator __first = _Base::begin();
	  _Base_iterator __last = _Base::end();
	  if (__first == __last)
	    return;
	  _Base_iterator __next = std::next(__first);
	  while (__next != __last)
	    {
	      if (__binary_pred(*__first, *__next))
		__next = _M_erase_after(__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());
	  this->_M_transfer_from_if(__list, [&__list](_Base_const_iterator __it)
	    {
	      return __it != __list._M_base().cbefore_begin()
		     && __it != __list._M_base().cend();
	    });
	  _Base::merge(std::move(__list._M_base()));
	}
      }

      void
      merge(forward_list& __list)
      { merge(std::move(__list)); }

      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);
	    this->_M_transfer_from_if(__list,
				      [&__list](_Base_const_iterator __it)
	      {
	        return __it != __list._M_base().cbefore_begin()
		       && __it != __list._M_base().cend();
	      });
	    _Base::merge(std::move(__list._M_base()), __comp);
	  }
	}

      template<typename _Comp>
        void
        merge(forward_list& __list, _Comp __comp)
        { merge(std::move(__list), __comp); }

      using _Base::sort;
      using _Base::reverse;

      _Base&
      _M_base() noexcept       { return *this; }

      const _Base&
      _M_base() const noexcept { return *this; }

    private:
      void
      _M_invalidate_all()
      {
	this->_M_invalidate_if([this](_Base_const_iterator __it)
	  {
	    return __it != this->_M_base().cbefore_begin()
		   && __it != this->_M_base().cend();
	  });
      }
      typedef __gnu_debug::_Safe_iterator_base _Safe_iterator_base;
      static void
      _M_swap_aux(forward_list& __lhs,
		  _Safe_iterator_base*& __lhs_iterators,
		  forward_list& __rhs,
		  _Safe_iterator_base*& __rhs_iterators);
      void _M_swap(forward_list& __list);
    };

   template<typename _Tp, typename _Alloc>
    void
    forward_list<_Tp, _Alloc>::
    _M_swap_aux(forward_list<_Tp, _Alloc>& __lhs,
		__gnu_debug::_Safe_iterator_base*& __lhs_iterators,
		forward_list<_Tp, _Alloc>& __rhs,
		__gnu_debug::_Safe_iterator_base*& __rhs_iterators)
    {
      using __gnu_debug::_Safe_iterator_base;
      _Safe_iterator_base* __bbegin_its = 0;
      _Safe_iterator_base* __last_bbegin = 0;
      for (_Safe_iterator_base* __iter = __lhs_iterators; __iter;)
	{
	  // Even iterator are casted to const_iterator, not a problem.
	  const_iterator* __victim = static_cast<const_iterator*>(__iter);
	  __iter = __iter->_M_next;
	  if (__victim->base() == __rhs._M_base().cbefore_begin())
	    {
	      __victim->_M_unlink();
	      if (__lhs_iterators == __victim)
		__lhs_iterators = __victim->_M_next;
	      if (__bbegin_its)
		{
		  __victim->_M_next = __bbegin_its;
		  __bbegin_its->_M_prior = __victim;
		}
	      else
		__last_bbegin = __victim;
	      __bbegin_its = __victim;
	    }
	  else
	    __victim->_M_sequence = &__lhs;
	}

      if (__bbegin_its)
	{
	  if (__rhs_iterators)
	    {
	      __rhs_iterators->_M_prior = __last_bbegin;
	      __last_bbegin->_M_next = __rhs_iterators;
	    }
	  __rhs_iterators = __bbegin_its;
	}
    }

  /* Special forward_list _M_swap version that do not swap the
   * before-begin ownership.*/
  template<typename _Tp, typename _Alloc>
    void
    forward_list<_Tp, _Alloc>::
    _M_swap(forward_list<_Tp, _Alloc>& __list)
    {
      __gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());
      std::swap(this->_M_iterators, __list._M_iterators);
      std::swap(this->_M_const_iterators, __list._M_const_iterators);
      // Useless, always 1 on forward_list
      //std::swap(this->_M_version, __list._M_version);
      _Safe_iterator_base* __this_its = this->_M_iterators;
      _M_swap_aux(__list, __list._M_iterators, *this, this->_M_iterators);
      _Safe_iterator_base* __this_const_its = this->_M_const_iterators;
      _M_swap_aux(__list, __list._M_const_iterators, *this,
		  this->_M_const_iterators);
      _M_swap_aux(*this, __this_its, __list, __list._M_iterators);
      _M_swap_aux(*this, __this_const_its, __list, __list._M_const_iterators);
    }

  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 std::__debug::forward_list<_Tp, _Alloc> _Sequence;
      typedef typename _Sequence::const_iterator _It;
      typedef typename _It::iterator_type _BaseIt;

      static bool
      _S_Is(_BaseIt __it, const _Sequence* __seq)
      { return __it == __seq->_M_base().cbefore_begin(); }

      static bool
      _S_Is_Beginnest(_BaseIt __it, const _Sequence* __seq)
      { return _S_Is(__it, __seq); }
    };
}

#endif
@


