Commit 3a63c9cd by Edward Smith-Rowland Committed by Paolo Carlini

forward_list: New.

2008-10-15  Edward Smith-Rowland  <3dw4rd@verizon.net>

	* include/std/forward_list: New.
	* include/bits/forward_list.h: Likewise.
	* include/bits/forward_list.tcc: Likewise.
	* include/precompiled/stdc++.h: Modified to include forward_list.
	* include/Makefile.am: Add forward_list, forward_list.h, and
	forward_list.tcc.
	* include/Makefile.in: Regenerate.
	* testsuite/23_containers/forward_list/modifiers/1.cc: New.
	* testsuite/23_containers/forward_list/modifiers/2.cc: Likewise.
	* testsuite/23_containers/forward_list/modifiers/3.cc: Likewise.
	* testsuite/23_containers/forward_list/modifiers/4.cc: Likewise.
	* testsuite/23_containers/forward_list/modifiers/5.cc: Likewise.
	* testsuite/23_containers/forward_list/cons/1.cc: Likewise.
	* testsuite/23_containers/forward_list/cons/2.cc: Likewise.
	* testsuite/23_containers/forward_list/cons/3.cc: Likewise.
	* testsuite/23_containers/forward_list/cons/4.cc: Likewise.
	* testsuite/23_containers/forward_list/cons/5.cc: Likewise.
	* testsuite/23_containers/forward_list/cons/6.cc: Likewise.
	* testsuite/23_containers/forward_list/cons/7.cc: Likewise.
	* testsuite/23_containers/forward_list/cons/8.cc: Likewise.
	* testsuite/23_containers/forward_list/cons/9.cc: Likewise.
	* testsuite/23_containers/forward_list/requirements/1.cc: Likewise.
	* testsuite/23_containers/forward_list/operations/1.cc: Likewise.
	* testsuite/23_containers/forward_list/operations/2.cc: Likewise.
	* testsuite/23_containers/forward_list/operations/3.cc: Likewise.
	* testsuite/23_containers/forward_list/operations/4.cc: Likewise.
	* testsuite/23_containers/forward_list/operations/5.cc: Likewise.
	* testsuite/23_containers/forward_list/operations/6.cc: Likewise.
	* testsuite/23_containers/forward_list/operations/7.cc: Likewise.
	* testsuite/23_containers/forward_list/capacity/1.cc: Likewise.
	* testsuite/23_containers/forward_list/comparable.cc: Likewise.
	* testsuite/23_containers/forward_list/moveable.cc: Likewise.
	* testsuite/23_containers/headers/forward_list/synopsis.cc: Likewise.
	* testsuite/17_intro/headers/c++200x/all_multiple_inclusion.cc: Update.
	* testsuite/17_intro/headers/c++200x/all: Likewise.

From-SVN: r141146
parent 21c74256
2008-10-15 Edward Smith-Rowland <3dw4rd@verizon.net>
* include/std/forward_list: New.
* include/bits/forward_list.h: Likewise.
* include/bits/forward_list.tcc: Likewise.
* include/precompiled/stdc++.h: Modified to include forward_list.
* include/Makefile.am: Add forward_list, forward_list.h, and
forward_list.tcc.
* include/Makefile.in: Regenerate.
* testsuite/23_containers/forward_list/modifiers/1.cc: New.
* testsuite/23_containers/forward_list/modifiers/2.cc: Likewise.
* testsuite/23_containers/forward_list/modifiers/3.cc: Likewise.
* testsuite/23_containers/forward_list/modifiers/4.cc: Likewise.
* testsuite/23_containers/forward_list/modifiers/5.cc: Likewise.
* testsuite/23_containers/forward_list/cons/1.cc: Likewise.
* testsuite/23_containers/forward_list/cons/2.cc: Likewise.
* testsuite/23_containers/forward_list/cons/3.cc: Likewise.
* testsuite/23_containers/forward_list/cons/4.cc: Likewise.
* testsuite/23_containers/forward_list/cons/5.cc: Likewise.
* testsuite/23_containers/forward_list/cons/6.cc: Likewise.
* testsuite/23_containers/forward_list/cons/7.cc: Likewise.
* testsuite/23_containers/forward_list/cons/8.cc: Likewise.
* testsuite/23_containers/forward_list/cons/9.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/1.cc: Likewise.
* testsuite/23_containers/forward_list/operations/1.cc: Likewise.
* testsuite/23_containers/forward_list/operations/2.cc: Likewise.
* testsuite/23_containers/forward_list/operations/3.cc: Likewise.
* testsuite/23_containers/forward_list/operations/4.cc: Likewise.
* testsuite/23_containers/forward_list/operations/5.cc: Likewise.
* testsuite/23_containers/forward_list/operations/6.cc: Likewise.
* testsuite/23_containers/forward_list/operations/7.cc: Likewise.
* testsuite/23_containers/forward_list/capacity/1.cc: Likewise.
* testsuite/23_containers/forward_list/comparable.cc: Likewise.
* testsuite/23_containers/forward_list/moveable.cc: Likewise.
* testsuite/23_containers/headers/forward_list/synopsis.cc: Likewise.
* testsuite/17_intro/headers/c++200x/all_multiple_inclusion.cc: Update.
* testsuite/17_intro/headers/c++200x/all: Likewise.
2008-10-14 Paolo Carlini <paolo.carlini@oracle.com> 2008-10-14 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/stl_list.h (_List_node<>::_List_node<>(_Args&&...)): * include/bits/stl_list.h (_List_node<>::_List_node<>(_Args&&...)):
......
...@@ -36,6 +36,7 @@ std_headers = \ ...@@ -36,6 +36,7 @@ std_headers = \
${std_srcdir}/complex \ ${std_srcdir}/complex \
${std_srcdir}/condition_variable \ ${std_srcdir}/condition_variable \
${std_srcdir}/deque \ ${std_srcdir}/deque \
${std_srcdir}/forward_list \
${std_srcdir}/fstream \ ${std_srcdir}/fstream \
${std_srcdir}/functional \ ${std_srcdir}/functional \
${std_srcdir}/iomanip \ ${std_srcdir}/iomanip \
...@@ -87,6 +88,8 @@ bits_headers = \ ...@@ -87,6 +88,8 @@ bits_headers = \
${bits_srcdir}/concept_check.h \ ${bits_srcdir}/concept_check.h \
${bits_srcdir}/cpp_type_traits.h \ ${bits_srcdir}/cpp_type_traits.h \
${bits_srcdir}/deque.tcc \ ${bits_srcdir}/deque.tcc \
${bits_srcdir}/forward_list.h \
${bits_srcdir}/forward_list.tcc \
${bits_srcdir}/fstream.tcc \ ${bits_srcdir}/fstream.tcc \
${bits_srcdir}/functexcept.h \ ${bits_srcdir}/functexcept.h \
${bits_srcdir}/functional_hash.h \ ${bits_srcdir}/functional_hash.h \
......
...@@ -302,6 +302,7 @@ std_headers = \ ...@@ -302,6 +302,7 @@ std_headers = \
${std_srcdir}/complex \ ${std_srcdir}/complex \
${std_srcdir}/condition_variable \ ${std_srcdir}/condition_variable \
${std_srcdir}/deque \ ${std_srcdir}/deque \
${std_srcdir}/forward_list \
${std_srcdir}/fstream \ ${std_srcdir}/fstream \
${std_srcdir}/functional \ ${std_srcdir}/functional \
${std_srcdir}/iomanip \ ${std_srcdir}/iomanip \
...@@ -353,6 +354,8 @@ bits_headers = \ ...@@ -353,6 +354,8 @@ bits_headers = \
${bits_srcdir}/concept_check.h \ ${bits_srcdir}/concept_check.h \
${bits_srcdir}/cpp_type_traits.h \ ${bits_srcdir}/cpp_type_traits.h \
${bits_srcdir}/deque.tcc \ ${bits_srcdir}/deque.tcc \
${bits_srcdir}/forward_list.h \
${bits_srcdir}/forward_list.tcc \
${bits_srcdir}/fstream.tcc \ ${bits_srcdir}/fstream.tcc \
${bits_srcdir}/functexcept.h \ ${bits_srcdir}/functexcept.h \
${bits_srcdir}/functional_hash.h \ ${bits_srcdir}/functional_hash.h \
......
// <forward_list.h> -*- C++ -*-
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/** @file forward_list.h
* This is a Standard C++ Library header.
*/
#ifndef _GLIBCXX_FORWARD_LIST_H
#define _GLIBCXX_FORWARD_LIST_H 1
#pragma GCC system_header
#ifndef __GXX_EXPERIMENTAL_CXX0X__
# include <c++0x_warning.h>
#else
#include <memory>
#include <initializer_list>
_GLIBCXX_BEGIN_NAMESPACE(std)
/**
* @brief A helper basic node class for @forward_list.
* This is just a linked list with nothing inside it.
* There are purely list shuffling utility methods here.
*/
struct _Fwd_list_node_base
{
_Fwd_list_node_base() : _M_next(0) { }
_Fwd_list_node_base* _M_next;
static void
swap(_Fwd_list_node_base& __x, _Fwd_list_node_base& __y)
{ std::swap(__x._M_next, __y._M_next); }
void
_M_transfer_after(_Fwd_list_node_base* __bbegin,
_Fwd_list_node_base* __bend)
{
_Fwd_list_node_base* __keep = __bbegin->_M_next;
if (__bend)
{
__bbegin->_M_next = __bend->_M_next;
__bend->_M_next = this->_M_next;
}
else
__bbegin->_M_next = 0;
this->_M_next = __keep;
}
void
_M_transfer_after(_Fwd_list_node_base* __bbegin)
{
_Fwd_list_node_base* __bend = __bbegin;
while (__bend && __bend->_M_next)
__bend = __bend->_M_next;
_M_transfer_after(__bbegin, __bend);
}
void
_M_reverse_after()
{
_Fwd_list_node_base* __tail = this->_M_next;
if (! __tail)
return;
while (_Fwd_list_node_base* __temp = __tail->_M_next)
{
_Fwd_list_node_base* __keep = this->_M_next;
this->_M_next = __temp;
__tail->_M_next = __temp->_M_next;
this->_M_next->_M_next = __keep;
}
}
};
/**
* @brief A helper node class for @forward_list.
* This is just a linked list with a data value in each node.
* There is a sorting utility method.
*/
template<typename _Tp>
struct _Fwd_list_node : public _Fwd_list_node_base
{
template<typename... _Args>
_Fwd_list_node(_Args&&... __args)
: _Fwd_list_node_base(), _M_value(std::forward<_Args>(__args)...) { }
template<typename _Comp>
void
_M_sort_after(_Comp __comp);
_Tp _M_value;
};
/**
* @brief A forward_list::iterator.
*
* All the functions are op overloads.
*/
template<typename _Tp>
struct _Fwd_list_iterator
{
typedef _Fwd_list_iterator<_Tp> _Self;
typedef _Fwd_list_node<_Tp> _Node;
typedef _Tp value_type;
typedef _Tp* pointer;
typedef _Tp& reference;
typedef ptrdiff_t difference_type;
typedef std::forward_iterator_tag iterator_category;
_Fwd_list_iterator() : _M_node() { }
explicit
_Fwd_list_iterator(_Fwd_list_node_base* __n) : _M_node(__n) { }
reference
operator*() const
{ return static_cast<_Node*>(this->_M_node)->_M_value; }
pointer
operator->() const
{ return &static_cast<_Node*>(this->_M_node)->_M_value; }
_Self&
operator++()
{
this->_M_node = this->_M_node->_M_next;
return *this;
}
_Self
operator++(int)
{
_Self __tmp(*this);
this->_M_node = this->_M_node->_M_next;
return __tmp;
}
bool
operator==(const _Self& __x) const
{ return this->_M_node == __x._M_node; }
bool
operator!=(const _Self& __x) const
{ return this->_M_node != __x._M_node; }
const _Self&
_M_next() const
{
if (_M_node)
return _Fwd_list_iterator(this->_M_node->_M_next);
else
return _Fwd_list_iterator(0);
}
_Fwd_list_node_base* _M_node;
};
/**
* @brief A forward_list::const_iterator.
*
* All the functions are op overloads.
*/
template<typename _Tp>
struct _Fwd_list_const_iterator
{
typedef _Fwd_list_const_iterator<_Tp> _Self;
typedef const _Fwd_list_node<_Tp> _Node;
typedef _Fwd_list_iterator<_Tp> iterator;
typedef _Tp value_type;
typedef const _Tp* pointer;
typedef const _Tp& reference;
typedef ptrdiff_t difference_type;
typedef std::forward_iterator_tag iterator_category;
_Fwd_list_const_iterator() : _M_node() { }
explicit
_Fwd_list_const_iterator(const _Fwd_list_node_base* __n)
: _M_node(__n) { }
_Fwd_list_const_iterator(const iterator& __iter)
: _M_node(__iter._M_node) { }
reference
operator*() const
{ return static_cast<_Node*>(this->_M_node)->_M_value; }
pointer
operator->() const
{ return &static_cast<_Node*>(this->_M_node)->_M_value; }
_Self&
operator++()
{
this->_M_node = this->_M_node->_M_next;
return *this;
}
_Self
operator++(int)
{
_Self __tmp(*this);
this->_M_node = this->_M_node->_M_next;
return __tmp;
}
bool
operator==(const _Self& __x) const
{ return this->_M_node == __x._M_node; }
bool
operator!=(const _Self& __x) const
{ return this->_M_node != __x._M_node; }
const _Self&
_M_next() const
{
if (this->_M_node)
return _Fwd_list_const_iterator(this->_M_node->_M_next);
else
return _Fwd_list_const_iterator(0);
}
const _Fwd_list_node_base* _M_node;
};
/**
* @brief Forward list iterator equality comparison.
*/
template<typename _Tp>
inline bool
operator==(const _Fwd_list_iterator<_Tp>& __x,
const _Fwd_list_const_iterator<_Tp>& __y)
{ return __x._M_node == __y._M_node; }
/**
* @brief Forward list iterator inequality comparison.
*/
template<typename _Tp>
inline bool
operator!=(const _Fwd_list_iterator<_Tp>& __x,
const _Fwd_list_const_iterator<_Tp>& __y)
{ return __x._M_node != __y._M_node; }
/**
* @brief Base class for @forward_list.
*/
template<typename _Tp, typename _Alloc>
struct _Fwd_list_base
{
protected:
typedef typename _Alloc::template rebind<_Fwd_list_node<_Tp>>::other
_Node_alloc_type;
struct _Fwd_list_impl
: public _Node_alloc_type
{
_Fwd_list_node_base _M_head;
_Fwd_list_impl()
: _Node_alloc_type(), _M_head()
{ }
explicit
_Fwd_list_impl(const _Node_alloc_type& __a)
: _Node_alloc_type(__a), _M_head()
{ }
};
_Fwd_list_impl _M_impl;
public:
typedef _Alloc allocator_type;
typedef _Fwd_list_iterator<_Tp> iterator;
typedef _Fwd_list_const_iterator<_Tp> const_iterator;
typedef _Fwd_list_node<_Tp> _Node;
_Node_alloc_type&
_M_get_Node_allocator()
{ return *static_cast<_Node_alloc_type*>(&this->_M_impl); }
const _Node_alloc_type&
_M_get_Node_allocator() const
{ return *static_cast<const _Node_alloc_type*>(&this->_M_impl); }
allocator_type
get_allocator() const
{ return this->_M_get_Node_allocator(); }
_Fwd_list_base()
: _M_impl()
{ this->_M_impl._M_head._M_next = 0; }
_Fwd_list_base(const allocator_type& __a)
: _M_impl(__a)
{ this->_M_impl._M_head._M_next = 0; }
_Fwd_list_base(const _Fwd_list_base& __lst, const _Alloc& __a);
_Fwd_list_base(_Fwd_list_base&& __lst, const _Alloc& __a)
: _M_impl(__a)
{ _Fwd_list_node_base::swap(this->_M_impl._M_head,
__lst._M_impl._M_head); }
_Fwd_list_base(_Fwd_list_base&& __lst)
: _M_impl(__lst._M_get_Node_allocator())
{ _Fwd_list_node_base::swap(this->_M_impl._M_head,
__lst._M_impl._M_head); }
~_Fwd_list_base()
{ _M_erase_after(&_M_impl._M_head, 0); }
protected:
_Node*
_M_get_node()
{ return _M_get_Node_allocator().allocate(1); }
template<typename... _Args>
_Node*
_M_create_node(_Args&&... __args)
{
_Node* __node = this->_M_get_node();
try
{
_M_get_Node_allocator().construct(__node,
std::forward<_Args>(__args)...);
__node->_M_next = 0;
}
catch(...)
{
this->_M_put_node(__node);
__throw_exception_again;
}
return __node;
}
template<typename... _Args>
void
_M_insert_after(const_iterator __pos, _Args&&... __args)
{
_Fwd_list_node_base* __to
= const_cast<_Fwd_list_node_base* const>(__pos._M_node);
_Node* __thing = _M_create_node(std::forward<_Args>(__args)...);
__thing->_M_next = __to->_M_next;
__to->_M_next = __thing;
}
void
_M_put_node(_Node* __p)
{ _M_get_Node_allocator().deallocate(__p, 1); }
_Fwd_list_node_base*
_M_erase_after(_Fwd_list_node_base* __pos);
_Fwd_list_node_base*
_M_erase_after(_Fwd_list_node_base* __pos,
_Fwd_list_node_base* __last);
};
/**
* @brief A standard container with linear time access to elements,
* and fixed time insertion/deletion at any point in the sequence.
*
* @ingroup Containers
* @ingroup Sequences
*
* Meets the requirements of a <a href="tables.html#65">container</a>, a
* <a href="tables.html#67">sequence</a>, including the
* <a href="tables.html#68">optional sequence requirements</a> with the
* %exception of @c at and @c operator[].
*
* This is a @e singly @e linked %list. Traversal up the
* %list requires linear time, but adding and removing elements (or
* @e nodes) is done in constant time, regardless of where the
* change takes place. Unlike std::vector and std::deque,
* random-access iterators are not provided, so subscripting ( @c
* [] ) access is not allowed. For algorithms which only need
* sequential access, this lack makes no difference.
*
* Also unlike the other standard containers, std::forward_list provides
* specialized algorithms %unique to linked lists, such as
* splicing, sorting, and in-place reversal.
*
* A couple points on memory allocation for forward_list<Tp>:
*
* First, we never actually allocate a Tp, we allocate
* Fwd_list_node<Tp>'s and trust [20.1.5]/4 to DTRT. This is to ensure
* that after elements from %forward_list<X,Alloc1> are spliced into
* %forward_list<X,Alloc2>, destroying the memory of the second %list is a
* valid operation, i.e., Alloc1 giveth and Alloc2 taketh away.
*/
template<typename _Tp, typename _Alloc = allocator<_Tp> >
class forward_list : private _Fwd_list_base<_Tp, _Alloc>
{
private:
typedef _Fwd_list_base<_Tp, _Alloc> _Base;
typedef _Fwd_list_node<_Tp> _Node;
public:
// types:
typedef typename _Alloc::reference reference;
typedef typename _Alloc::const_reference const_reference;
typedef _Fwd_list_iterator<_Tp> iterator;
typedef _Fwd_list_const_iterator<_Tp> const_iterator;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef _Tp value_type;
typedef typename _Base::allocator_type allocator_type;
typedef typename _Alloc::pointer pointer;
typedef typename _Alloc::const_pointer const_pointer;
// 23.2.3.1 construct/copy/destroy:
/**
* @brief Creates a %forward_list with no elements.
* @param al An allocator object.
*/
explicit
forward_list(const _Alloc& __al = _Alloc())
: _Base(__al)
{ }
/**
* @brief Copy constructor with allocator argument.
* @param list Input list to copy.
* @param al An allocator object.
*/
forward_list(const forward_list& __list, const _Alloc& __al)
: _Base(__list, __al)
{ }
/**
* @brief Move constructor with allocator argument.
* @param list Input list to move.
* @param al An allocator object.
*/
forward_list(forward_list&& __list, const _Alloc& __al)
: _Base(std::forward<_Base>(__list), __al)
{ }
/**
* @brief Creates a %forward_list with copies of the default element
* type.
* @param n The number of elements to initially create.
*
* This constructor fills the %forward_list with @a n copies of
* the default value.
*/
explicit
forward_list(size_type __n);
/**
* @brief Creates a %forward_list with copies of an exemplar element.
* @param n The number of elements to initially create.
* @param value An element to copy.
* @param al An allocator object.
*
* This constructor fills the %forward_list with @a n copies of @a
* value.
*/
forward_list(size_type __n, const _Tp& __value,
const _Alloc& __al = _Alloc());
/**
* @brief Builds a %forward_list from a range.
* @param first An input iterator.
* @param last An input iterator.
* @param al An allocator object.
*
* Create a %forward_list consisting of copies of the elements from
* [@a first,@a last). This is linear in N (where N is
* distance(@a first,@a last)).
*/
template<typename _InputIterator>
forward_list(_InputIterator __first, _InputIterator __last,
const _Alloc& __al = _Alloc());
/**
* @brief The %forward_list copy constructor.
* @param list A %forward_list of identical element and allocator
* types.
*
* The newly-created %forward_list uses a copy of the allocation
* object used by @a list.
*/
forward_list(const forward_list& __list);
/**
* @brief The %forward_list move constructor.
* @param list A %forward_list of identical element and allocator
* types.
*
* The newly-created %forward_list contains the exact contents of @a
* forward_list. The contents of @a list are a valid, but unspecified
* %forward_list.
*/
forward_list(forward_list&& __list)
: _Base(std::forward<_Base>(__list)) { }
/**
* @brief Builds a %forward_list from an initializer_list
* @param il An initializer_list of value_type.
* @param al An allocator object.
*
* Create a %forward_list consisting of copies of the elements
* in the initializer_list @a il. This is linear in il.size().
*/
forward_list(std::initializer_list<_Tp> __il,
const _Alloc& __al = _Alloc());
/**
* @brief The forward_list dtor.
*/
~forward_list()
{ _M_erase_after(&this->_M_impl._M_head, 0); }
/**
* @brief The %forward_list assignment operator.
* @param list A %forward_list of identical element and allocator
* types.
*
* All the elements of @a list are copied, but unlike the copy
* constructor, the allocator object is not copied.
*/
forward_list&
operator=(const forward_list& __list);
/**
* @brief The %forward_list move assignment operator.
* @param list A %forward_list of identical element and allocator
* types.
*
* The contents of @a list are moved into this %forward_list
* (without copying). @a list is a valid, but unspecified
* %forward_list
*/
forward_list&
operator=(forward_list&& __list)
{
if (&__list != this)
{
this->clear();
this->swap(__list);
}
return *this;
}
/**
* @brief The %forward_list initializer list assignment operator.
* @param il An initializer_list of value_type.
*
* Replace the contents of the %forward_list with copies of the
* elements in the initializer_list @a il. This is linear in
* il.size().
*/
forward_list
operator=(std::initializer_list<_Tp> __il)
{
assign(__il);
return *this;
}
/**
* @brief Assigns a range to a %forward_list.
* @param first An input iterator.
* @param last An input iterator.
*
* This function fills a %forward_list with copies of the elements
* in the range [@a first,@a last).
*
* Note that the assignment completely changes the %forward_list and
* that the resulting %forward_list's size is the same as the number
* of elements assigned. Old data may be lost.
*/
template<typename InputIterator>
void
assign(InputIterator __first, InputIterator __last)
{
clear();
insert_after(cbefore_begin(), __first, __last);
}
/**
* @brief Assigns a given value to a %forward_list.
* @param n Number of elements to be assigned.
* @param val Value to be assigned.
*
* This function fills a %forward_list with @a n copies of the given
* value. Note that the assignment completely changes the
* %forward_list and that the resulting %forward_list's size is the
* same as the number of elements assigned. Old data may be lost.
*/
void
assign(size_type __n, const _Tp& __val)
{
clear();
insert_after(cbefore_begin(), __n, __val);
}
/**
* @brief Assigns an initializer_list to a %forward_list.
* @param il An initializer_list of value_type.
*
* Replace the contents of the %forward_list with copies of the
* elements in the initializer_list @a il. This is linear in
* il.size().
*/
void
assign(std::initializer_list<_Tp> __il)
{
clear();
insert_after(cbefore_begin(), __il);
}
/// Get a copy of the memory allocation object.
allocator_type
get_allocator() const
{ return _Base::get_allocator(); }
// 23.2.3.2 iterators:
/**
* Returns a read/write iterator that points before the first element
* in the %forward_list. Iteration is done in ordinary element order.
*/
iterator
before_begin()
{ return iterator(&this->_M_impl._M_head); }
/**
* Returns a read-only (constant) iterator that points before the
* first element in the %forward_list. Iteration is done in ordinary
* element order.
*/
const_iterator
before_begin() const
{ return const_iterator(&this->_M_impl._M_head); }
/**
* Returns a read/write iterator that points to the first element
* in the %forward_list. Iteration is done in ordinary element order.
*/
iterator
begin()
{ return iterator(this->_M_impl._M_head._M_next); }
/**
* Returns a read-only (constant) iterator that points to the first
* element in the %forward_list. Iteration is done in ordinary
* element order.
*/
const_iterator
begin() const
{ return const_iterator(this->_M_impl._M_head._M_next); }
/**
* Returns a read/write iterator that points one past the last
* element in the %forward_list. Iteration is done in ordinary
* element order.
*/
iterator
end()
{ return iterator(0); }
/**
* Returns a read-only iterator that points one past the last
* element in the %forward_list. Iteration is done in ordinary
* element order.
*/
const_iterator
end() const
{ return const_iterator(0); }
/**
* Returns a read-only (constant) iterator that points to the
* first element in the %forward_list. Iteration is done in ordinary
* element order.
*/
const_iterator
cbegin() const
{ return const_iterator(this->_M_impl._M_head._M_next); }
/**
* Returns a read-only (constant) iterator that points before the
* first element in the %forward_list. Iteration is done in ordinary
* element order.
*/
const_iterator
cbefore_begin() const
{ return const_iterator(&this->_M_impl._M_head); }
/**
* Returns a read-only (constant) iterator that points one past
* the last element in the %forward_list. Iteration is done in
* ordinary element order.
*/
const_iterator
cend() const
{ return const_iterator(0); }
/**
* Returns true if the %forward_list is empty. (Thus begin() would
* equal end().)
*/
bool
empty() const
{ return this->_M_impl._M_head._M_next == 0; }
/**
* Returns the largest possible size of %forward_list.
*/
size_type
max_size() const
{ return _Alloc().max_size(); }
// 23.2.3.3 element access:
/**
* Returns a read/write reference to the data at the first
* element of the %forward_list.
*/
reference
front()
{
_Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
return __front->_M_value;
}
/**
* Returns a read-only (constant) reference to the data at the first
* element of the %forward_list.
*/
const_reference
front() const
{
_Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
return __front->_M_value;
}
// 23.2.3.4 modifiers:
/**
* @brief Constructs object in %forward_list at the front of the
* list.
* @param args Arguments.
*
* This function will insert an object of type Tp constructed
* with Tp(std::forward<Args>(args)...) at the front of the list
* Due to the nature of a %forward_list this operation can
* be done in constant time, and does not invalidate iterators
* and references.
*/
template<typename... _Args>
void
emplace_front(_Args&&... __args)
{ _M_insert_after(cbefore_begin(), std::forward<_Args>(__args)...); }
/**
* @brief Add data to the front of the %forward_list.
* @param val Data to be added.
*
* This is a typical stack operation. The function creates an
* element at the front of the %forward_list and assigns the given
* data to it. Due to the nature of a %forward_list this operation
* can be done in constant time, and does not invalidate iterators
* and references.
*/
void
push_front(const _Tp& __val)
{ _M_insert_after(cbefore_begin(), __val); }
/**
*
*/
void
push_front(_Tp&& __val)
{ _M_insert_after(cbefore_begin(), std::move(__val)); }
/**
* @brief Removes first element.
*
* This is a typical stack operation. It shrinks the %forward_list
* by one. Due to the nature of a %forward_list this operation can
* be done in constant time, and only invalidates iterators/references
* to the element being removed.
*
* Note that no data is returned, and if the first element's data
* is needed, it should be retrieved before pop_front() is
* called.
*/
void
pop_front()
{ _M_erase_after(&this->_M_impl._M_head); }
/**
* @brief Constructs object in %forward_list after the specified
* iterator.
* @param pos A const_iterator into the %forward_list.
* @param args Arguments.
* @return An iterator that points to the inserted data.
*
* This function will insert an object of type T constructed
* with T(std::forward<Args>(args)...) after the specified
* location. Due to the nature of a %forward_list this operation can
* be done in constant time, and does not invalidate iterators
* and references.
*/
template<typename... _Args>
iterator
emplace_after(const_iterator __pos, _Args&&... __args)
{ _M_insert_after(__pos, std::forward<_Args>(__args)...); }
/**
* @brief Inserts given value into %forward_list after specified
* iterator.
* @param pos An iterator into the %forward_list.
* @param val Data to be inserted.
* @return An iterator that points to the inserted data.
*
* This function will insert a copy of the given value after
* the specified location. Due to the nature of a %forward_list this
* operation can be done in constant time, and does not
* invalidate iterators and references.
*/
iterator
insert_after(const_iterator __pos, const _Tp& __val)
{
_Fwd_list_node_base* __to
= const_cast<_Fwd_list_node_base* const>(__pos._M_node);
_Node* __thing = _M_create_node(__val);
__thing->_M_next = __to->_M_next;
__to->_M_next = __thing;
return iterator(__to->_M_next);
}
/**
*
*/
iterator
insert_after(const_iterator __pos, _Tp&& __val)
{
_Fwd_list_node_base* __to
= const_cast<_Fwd_list_node_base* const>(__pos._M_node);
_Node* __thing = _M_create_node(std::move(__val));
__thing->_M_next = __to->_M_next;
__to->_M_next = __thing;
return iterator(__to->_M_next);
}
/**
* @brief Inserts a number of copies of given data into the
* %forward_list.
* @param pos An iterator into the %forward_list.
* @param n Number of elements to be inserted.
* @param val Data to be inserted.
*
* This function will insert a specified number of copies of the
* given data after the location specified by @a pos.
*
* This operation is linear in the number of elements inserted and
* does not invalidate iterators and references.
*/
void
insert_after(const_iterator __pos,
size_type __n, const _Tp& __val);
/**
* @brief Inserts a range into the %forward_list.
* @param position An iterator into the %forward_list.
* @param first An input iterator.
* @param last An input iterator.
*
* This function will insert copies of the data in the range [@a
* first,@a last) into the %forward_list after the location specified
* by @a pos.
*
* This operation is linear in the number of elements inserted and
* does not invalidate iterators and references.
*/
template<typename _InputIterator>
void
insert_after(const_iterator __pos,
_InputIterator __first, _InputIterator __last);
/**
* @brief Inserts the contents of an initializer_list into
* %forward_list after the specified iterator.
* @param pos An iterator into the %forward_list.
* @param il An initializer_list of value_type.
*
* This function will insert copies of the data in the
* initializer_list @a il into the %forward_list before the location
* specified by @a pos.
*
* This operation is linear in the number of elements inserted and
* does not invalidate iterators and references.
*/
void
insert_after(const_iterator __pos, std::initializer_list<_Tp> __il);
/**
* @brief Removes the element pointed to by the iterator following
* @c pos.
* @param pos Iterator pointing to element to be erased.
* @return An iterator pointing to the next element (or end()).
*
* This function will erase the element at the given position and
* thus shorten the %forward_list by one.
*
* Due to the nature of a %forward_list this operation can be done
* in constant time, and only invalidates iterators/references to
* the element being removed. The user is also cautioned that
* this function only erases the element, and that if the element
* is itself a pointer, the pointed-to memory is not touched in
* any way. Managing the pointer is the user's responsibility.
*/
iterator
erase_after(const_iterator __pos)
{
_Fwd_list_node_base* __tmp
= const_cast<_Fwd_list_node_base* const>(__pos._M_node);
if (__tmp)
return iterator(_Base::_M_erase_after(__tmp));
else
return end();
}
/**
* @brief Remove a range of elements.
* @param pos Iterator pointing before the first element to be
* erased.
* @param last Iterator pointing to one past the last element to be
* erased.
* @return An iterator pointing to the element pointed to by @a last
* prior to erasing (or end()).
*
* This function will erase the elements in the range @a
* (pos,last) and shorten the %forward_list accordingly.
*
* This operation is linear time in the size of the range and only
* invalidates iterators/references to the element being removed.
* The user is also cautioned that this function only erases the
* elements, and that if the elements themselves are pointers, the
* pointed-to memory is not touched in any way. Managing the pointer
* is the user's responsibility.
*/
iterator
erase_after(const_iterator __pos, iterator __last)
{
_Fwd_list_node_base* __tmp
= const_cast<_Fwd_list_node_base* const>(__pos._M_node);
return iterator(_M_erase_after(__tmp, __last._M_node));
}
/**
* @brief Swaps data with another %forward_list.
* @param list A %forward_list of the same element and allocator
* types.
*
* This exchanges the elements between two lists in constant
* time. Note that the global std::swap() function is
* specialized such that std::swap(l1,l2) will feed to this
* function.
*/
void
swap(forward_list&& __list)
{ _Fwd_list_node_base::swap(this->_M_impl._M_head,
__list._M_impl._M_head); }
/**
* @brief Resizes the %forward_list to the specified number of
* elements.
* @param sz Number of elements the %forward_list should contain.
*
* This function will %resize the %forward_list to the specified
* number of elements. If the number is smaller than the
* %forward_list's current size the %forward_list is truncated,
* otherwise the %forward_list is extended and new elements are
* populated with given data.
*/
void
resize(size_type __sz)
{ resize(__sz, _Tp(0)); }
/**
* @brief Resizes the %forward_list to the specified number of
* elements.
* @param sz Number of elements the %forward_list should contain.
* @param val Data with which new elements should be populated.
*
* This function will %resize the %forward_list to the specified
* number of elements. If the number is smaller than the
* %forward_list's current size the %forward_list is truncated,
* otherwise the %forward_list is extended and new elements are
* populated with given data.
*/
void
resize(size_type __sz, value_type __val);
/**
* @brief Erases all the elements.
*
* Note that this function only erases
* the elements, and that if the elements themselves are
* pointers, the pointed-to memory is not touched in any way.
* Managing the pointer is the user's responsibility.
*/
void
clear()
{ _M_erase_after(&this->_M_impl._M_head, 0); }
// 23.2.3.5 forward_list operations:
/**
* @brief Insert contents of another %forward_list.
* @param pos Iterator referencing the element to insert after.
* @param list Source list.
*
* The elements of @a list are inserted in constant time after
* the element referenced by @a pos. @a list becomes an empty
* list.
*
* Requires this != @a x.
*/
void
splice_after(const_iterator __pos,
forward_list&& __list)
{
if (!__list.empty() && &__list != this)
{
_Fwd_list_node_base* __tmp
= const_cast<_Fwd_list_node_base* const>(__pos._M_node);
const_iterator __before = __list.cbefore_begin();
__tmp->_M_transfer_after(const_cast<_Fwd_list_node_base* const>
(__before._M_node));
}
}
/**
* @brief Insert element from another %forward_list.
* @param pos Iterator referencing the element to insert after.
* @param list Source list.
* @param it Iterator referencing the element before the element
* to move.
*
* Removes the element in list @a list referenced by @a i and
* inserts it into the current list after @a pos.
*/
void
splice_after(const_iterator __pos,
forward_list&& __list,
const_iterator __it)
{ this->splice_after(__pos, __list, __it, __it._M_next()); }
/**
* @brief Insert range from another %forward_list.
* @param pos Iterator referencing the element to insert after.
* @param list Source list.
* @param before Iterator referencing before the start of range
* in list.
* @param last Iterator referencing the end of range in list.
*
* Removes elements in the range (before,last) and inserts them
* after @a pos in constant time.
*
* Undefined if @a pos is in (before,last).
*/
void
splice_after(const_iterator __pos,
forward_list&& __list,
const_iterator __before,
const_iterator __last)
{
_Fwd_list_node_base* __tmp
= const_cast<_Fwd_list_node_base* const>(__pos._M_node);
__tmp->_M_transfer_after(const_cast<_Fwd_list_node_base* const>
(__before._M_node),
const_cast<_Fwd_list_node_base* const>
(__last._M_node));
}
/**
* @brief Remove all elements equal to value.
* @param val The value to remove.
*
* Removes every element in the list equal to @a value.
* Remaining elements stay in list order. Note that this
* function only erases the elements, and that if the elements
* themselves are pointers, the pointed-to memory is not
* touched in any way. Managing the pointer is the user's
* responsibility.
*/
void
remove(const _Tp& __val);
/**
* @brief Remove all elements satisfying a predicate.
* @param pred Unary predicate function or object.
*
* Removes every element in the list for which the predicate
* returns true. Remaining elements stay in list order. Note
* that this function only erases the elements, and that if the
* elements themselves are pointers, the pointed-to memory is
* not touched in any way. Managing the pointer is the user's
* responsibility.
*/
template<typename _Pred>
void
remove_if(_Pred __pred);
/**
* @brief Remove consecutive duplicate elements.
*
* For each consecutive set of elements with the same value,
* remove all but the first one. Remaining elements stay in
* list order. Note that this function only erases the
* elements, and that if the elements themselves are pointers,
* the pointed-to memory is not touched in any way. Managing
* the pointer is the user's responsibility.
*/
void
unique();
/**
* @brief Remove consecutive elements satisfying a predicate.
* @param binary_pred Binary predicate function or object.
*
* For each consecutive set of elements [first,last) that
* satisfy predicate(first,i) where i is an iterator in
* [first,last), remove all but the first one. Remaining
* elements stay in list order. Note that this function only
* erases the elements, and that if the elements themselves are
* pointers, the pointed-to memory is not touched in any way.
* Managing the pointer is the user's responsibility.
*/
template<typename _BinPred>
void
unique(_BinPred __binary_pred);
/**
* @brief Merge sorted lists.
* @param list Sorted list to merge.
*
* Assumes that both @a list and this list are sorted according to
* operator<(). Merges elements of @a list into this list in
* sorted order, leaving @a list empty when complete. Elements in
* this list precede elements in @a list that are equal.
*/
void
merge(forward_list&& __list)
{ this->merge(__list, std::less<_Tp>()); }
/**
* @brief Merge sorted lists according to comparison function.
* @param list Sorted list to merge.
* @param comp Comparison function defining sort order.
*
* Assumes that both @a list and this list are sorted according to
* comp. Merges elements of @a list into this list
* in sorted order, leaving @a list empty when complete. Elements
* in this list precede elements in @a list that are equivalent
* according to comp().
*/
template<typename _Comp>
void
merge(forward_list&& __list, _Comp __comp);
/**
* @brief Sort the elements of the list.
*
* Sorts the elements of this list in NlogN time. Equivalent
* elements remain in list order.
*/
void
sort()
{
_Node* __tmp = static_cast<_Node*>(&this->_M_impl._M_head);
__tmp->_M_sort_after(std::less<_Tp>());
}
/**
* @brief Sort the forward_list using a comparison function.
*
* Sorts the elements of this list in NlogN time. Equivalent
* elements remain in list order.
*/
template<typename _Comp>
void
sort(_Comp __comp)
{
_Node* __tmp = static_cast<_Node*>(&this->_M_impl._M_head);
__tmp->_M_sort_after(__comp);
}
/**
* @brief Reverse the elements in list.
*
* Reverse the order of elements in the list in linear time.
*/
void
reverse()
{ this->_M_impl._M_head._M_reverse_after(); }
};
/**
* @brief Forward list equality comparison.
* @param lx A %forward_list
* @param ly A %forward_list of the same type as @a lx.
* @return True iff the size and elements of the forward lists are equal.
*
* This is an equivalence relation. It is linear in the size of the
* forward lists. Deques are considered equivalent if corresponding
* elements compare equal.
*/
template<typename _Tp, typename _Alloc>
bool
operator==(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly)
{
// We don't have size() so we need to walk through both lists
// making sure both iterators are valid.
typename std::forward_list<_Tp, _Alloc>::const_iterator __ix
= __lx.cbegin();
typename std::forward_list<_Tp, _Alloc>::const_iterator __iy
= __ly.cbegin();
while (__ix != __lx.cend() && __iy != __ly.cend())
{
if (*__ix != *__iy)
return false;
++__ix;
++__iy;
}
if (__ix == __lx.cend() && __iy == __ly.cend())
return true;
else
return false;
}
/**
* @brief Forward list ordering relation.
* @param lx A %forward_list.
* @param ly A %forward_list of the same type as @a lx.
* @return True iff @a lx is lexicographically less than @a ly.
*
* This is a total ordering relation. It is linear in the size of the
* forward lists. The elements must be comparable with @c <.
*
* See std::lexicographical_compare() for how the determination is made.
*/
template<typename _Tp, typename _Alloc>
inline bool
operator<(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly)
{ return std::lexicographical_compare(__lx.cbegin(), __lx.cend(),
__ly.cbegin(), __ly.cend()); }
/// 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); }
/// 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::forward_swap().
template<typename _Tp, typename _Alloc>
inline void
swap(forward_list<_Tp, _Alloc>& __lx,
forward_list<_Tp, _Alloc>& __ly)
{ __lx.swap(__ly); }
/// See std::forward_list::forward_swap().
template<typename _Tp, typename _Alloc>
inline void
swap(forward_list<_Tp, _Alloc>&& __lx,
forward_list<_Tp, _Alloc>& __ly)
{ __lx.swap(__ly); }
/// See std::forward_list::forward_swap().
template<typename _Tp, typename _Alloc>
inline void
swap(forward_list<_Tp, _Alloc>& __lx,
forward_list<_Tp, _Alloc>&& __ly)
{ __lx.swap(__ly); }
_GLIBCXX_END_NAMESPACE // namespace std
#endif // __GXX_EXPERIMENTAL_CXX0X__
#endif // _GLIBCXX_FORWARD_LIST_H
// <forward_list.tcc> -*- C++ -*-
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/** @file forward_list.tcc
* This is a Standard C++ Library header.
*/
#ifndef _FORWARD_LIST_TCC
#define _FORWARD_LIST_TCC 1
_GLIBCXX_BEGIN_NAMESPACE(std)
/**
* @brief Sort the singly linked list starting after this node.
* This node is assumed to be an empty head node (of type
* _Fwd_list_node_base).
*/
template<typename _Tp>
template<typename _Comp>
void
_Fwd_list_node<_Tp>::
_M_sort_after(_Comp __comp)
{
// If `next' is 0, return immediately.
_Fwd_list_node* __list = static_cast<_Fwd_list_node*>(this->_M_next);
if (!__list)
return;
unsigned long __insize = 1;
while (1)
{
_Fwd_list_node* __p = __list;
__list = 0;
_Fwd_list_node* __tail = 0;
// Count number of merges we do in this pass.
unsigned long __nmerges = 0;
while (__p)
{
++__nmerges;
// There exists a merge to be done.
// Step `insize' places along from p.
_Fwd_list_node* __q = __p;
unsigned long __psize = 0;
for (unsigned long __i = 0; __i < __insize; ++__i)
{
++__psize;
__q = static_cast<_Fwd_list_node*>(__q->_M_next);
if (!__q)
break;
}
// If q hasn't fallen off end, we have two lists to merge.
unsigned long __qsize = __insize;
// Now we have two lists; merge them.
while (__psize > 0 || (__qsize > 0 && __q))
{
// Decide whether next node of merge comes from p or q.
_Fwd_list_node<_Tp>* __e;
if (__psize == 0)
{
// p is empty; e must come from q.
__e = __q;
__q = static_cast<_Fwd_list_node*>(__q->_M_next);
--__qsize;
}
else if (__qsize == 0 || !__q)
{
// q is empty; e must come from p.
__e = __p;
__p = static_cast<_Fwd_list_node*>(__p->_M_next);
--__psize;
}
else if (__comp(__p->_M_value, __q->_M_value))
{
// First node of p is lower; e must come from p.
__e = __p;
__p = static_cast<_Fwd_list_node*>(__p->_M_next);
--__psize;
}
else
{
// First node of q is lower; e must come from q.
__e = __q;
__q = static_cast<_Fwd_list_node*>(__q->_M_next);
--__qsize;
}
// Add the next node to the merged list.
if (__tail)
__tail->_M_next = __e;
else
__list = __e;
__tail = __e;
}
// Now p has stepped `insize' places along, and q has too.
__p = __q;
}
__tail->_M_next = 0;
// If we have done only one merge, we're finished.
// Allow for nmerges == 0, the empty list case.
if (__nmerges <= 1)
{
this->_M_next = __list;
return;
}
// Otherwise repeat, merging lists twice the size.
__insize *= 2;
}
}
template<typename _Tp, typename _Alloc>
_Fwd_list_base<_Tp, _Alloc>::
_Fwd_list_base(const _Fwd_list_base& __lst, const _Alloc& __a)
: _M_impl(__a)
{
this->_M_impl._M_head._M_next = 0;
_Fwd_list_node_base* __to = &this->_M_impl._M_head;
_Node* __curr = static_cast<_Node*>(__lst._M_impl._M_head._M_next);
while (__curr)
{
__to->_M_next = _M_create_node(__curr->_M_value);
__to = __to->_M_next;
__curr = static_cast<_Node*>(__curr->_M_next);
}
}
template<typename _Tp, typename _Alloc>
_Fwd_list_node_base*
_Fwd_list_base<_Tp, _Alloc>::
_M_erase_after(_Fwd_list_node_base* __pos)
{
_Node* __curr = static_cast<_Node*>(__pos->_M_next);
if (__curr)
{
_Fwd_list_node_base* __next = __curr->_M_next;
__pos->_M_next = __next;
_M_get_Node_allocator().destroy(__curr);
_M_put_node(__curr);
}
return __pos;
}
template<typename _Tp, typename _Alloc>
_Fwd_list_node_base*
_Fwd_list_base<_Tp, _Alloc>::
_M_erase_after(_Fwd_list_node_base* __pos, _Fwd_list_node_base* __last)
{
_Node* __curr = static_cast<_Node*>(__pos->_M_next);
while (__curr)
{
_Node* __temp = __curr;
__curr = static_cast<_Node*>(__curr->_M_next);
_M_get_Node_allocator().destroy(__temp);
_M_put_node(__temp);
__pos->_M_next = __curr;
if (__temp == __last)
break;
}
return __pos;
}
template<typename _Tp, typename _Alloc>
forward_list<_Tp, _Alloc>::
forward_list(size_type __n)
: _Base()
{
_Fwd_list_node_base* __to = &this->_M_impl._M_head;
for (size_type __i = 0; __i < __n; ++__i)
{
__to->_M_next = _M_create_node(_Tp());
__to = __to->_M_next;
}
}
template<typename _Tp, typename _Alloc>
forward_list<_Tp, _Alloc>::
forward_list(size_type __n, const _Tp& __value, const _Alloc& __al)
: _Base(__al)
{
_Fwd_list_node_base* __to = &this->_M_impl._M_head;
for (size_type __i = 0; __i < __n; ++__i)
{
__to->_M_next = _M_create_node(__value);
__to = __to->_M_next;
}
}
template<typename _Tp, typename _Alloc>
template<typename _InputIterator>
forward_list<_Tp, _Alloc>::
forward_list(_InputIterator __first, _InputIterator __last,
const _Alloc& __al)
: _Base(__al)
{
_Fwd_list_node_base* __to = &this->_M_impl._M_head;
_InputIterator __curr = __first;
while (__curr != __last)
{
__to->_M_next = _M_create_node(*__curr);
__to = __to->_M_next;
++__curr;
}
}
template<typename _Tp, typename _Alloc>
forward_list<_Tp, _Alloc>::
forward_list(const forward_list& __list)
: _Base(__list._M_get_Node_allocator())
{
const _Fwd_list_node_base* __from = &__list._M_impl._M_head;
_Fwd_list_node_base* __to = &this->_M_impl._M_head;
while (__from->_M_next != 0)
{
const _Node* __temp = static_cast<_Node*>(__from->_M_next);
__to->_M_next = _M_create_node(__temp->_M_value);
__from = __from->_M_next;
__to = __to->_M_next;
}
}
template<typename _Tp, typename _Alloc>
forward_list<_Tp, _Alloc>::
forward_list(std::initializer_list<_Tp> __il, const _Alloc& __al)
: _Base(__al)
{
_Fwd_list_node_base* __to = &this->_M_impl._M_head;
for (const _Tp* __item = __il.begin();
__item != __il.end(); ++__item)
{
__to->_M_next = _M_create_node(*__item);
__to = __to->_M_next;
}
}
template<typename _Tp, typename _Alloc>
forward_list<_Tp, _Alloc>&
forward_list<_Tp, _Alloc>::
operator=(const forward_list& __list)
{
if (&__list != this)
{
iterator __prev1 = before_begin();
iterator __curr1 = begin();
iterator __last1 = end();
const_iterator __first2 = __list.cbegin();
const_iterator __last2 = __list.cend();
while (__curr1 != __last1 && __first2 != __last2)
{
*__curr1 = *__first2;
++__prev1;
++__curr1;
++__first2;
}
if (__first2 == __last2)
erase_after(__prev1, __last1);
else
insert_after(__prev1, __first2, __last2);
}
return *this;
}
template<typename _Tp, typename _Alloc>
void
forward_list<_Tp, _Alloc>::
insert_after(const_iterator __pos,
size_type __n, const _Tp& __val)
{
_Fwd_list_node_base* __to
= const_cast<_Fwd_list_node_base* const>(__pos._M_node);
_Fwd_list_node_base* __keep = __to->_M_next;
for (size_type __i = 0; __i < __n; ++__i)
{
__to->_M_next = _M_create_node(__val);
__to = __to->_M_next;
}
__to->_M_next = __keep;
}
template<typename _Tp, typename _Alloc>
template<typename _InputIterator>
void
forward_list<_Tp, _Alloc>::
insert_after(const_iterator __pos,
_InputIterator __first, _InputIterator __last)
{
_Fwd_list_node_base* __to
= const_cast<_Fwd_list_node_base* const>(__pos._M_node);
_Fwd_list_node_base* __keep = __to->_M_next;
_InputIterator __curr = __first;
while (__curr != __last)
{
__to->_M_next = _M_create_node(*__curr);
__to = __to->_M_next;
++__curr;
}
__to->_M_next = __keep;
}
template<typename _Tp, typename _Alloc>
void
forward_list<_Tp, _Alloc>::
insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
{
_Fwd_list_node_base* __to
= const_cast<_Fwd_list_node_base* const>(__pos._M_node);
_Fwd_list_node_base* __keep = __to->_M_next;
const _Tp* __item = __il.begin();
while (__item != __il.end())
{
__to->_M_next = _M_create_node(*__item);
__to = __to->_M_next;
++__item;
}
__to->_M_next = __keep;
}
template<typename _Tp, typename _Alloc>
void
forward_list<_Tp, _Alloc>::
resize(size_type __sz, value_type __val)
{
iterator __k = before_begin();
size_type __len = 0;
while (__k._M_next() != end() && __len < __sz)
{
++__k;
++__len;
}
if (__len == __sz)
erase_after(__k, end());
else
insert_after(__k, __sz - __len, __val);
}
template<typename _Tp, typename _Alloc>
void
forward_list<_Tp, _Alloc>::
remove(const _Tp& __val)
{
_Node* __curr = static_cast<_Node*>(&this->_M_impl._M_head);
while (_Node* __temp = static_cast<_Node*>(__curr->_M_next))
{
if (__temp->_M_value == __val)
_M_erase_after(__curr);
else
__curr = static_cast<_Node*>(__curr->_M_next);
}
}
template<typename _Tp, typename _Alloc>
template<typename _Pred>
void
forward_list<_Tp, _Alloc>::
remove_if(_Pred __pred)
{
_Node* __curr = static_cast<_Node*>(&this->_M_impl._M_head);
while (_Node* __temp = static_cast<_Node*>(__curr->_M_next))
{
if (__pred(__temp->_M_value))
_M_erase_after(__curr);
else
__curr = static_cast<_Node*>(__curr->_M_next);
}
}
template<typename _Tp, typename _Alloc>
void
forward_list<_Tp, _Alloc>::
unique()
{
iterator __first = begin();
iterator __last = end();
if (__first == __last)
return;
iterator __next = __first;
while (++__next != __last)
{
if (*__first == *__next)
erase_after(__first);
else
__first = __next;
__next = __first;
}
}
template<typename _Tp, typename _Alloc>
template<typename _BinPred>
void
forward_list<_Tp, _Alloc>::
unique(_BinPred __binary_pred)
{
iterator __first = begin();
iterator __last = end();
if (__first == __last)
return;
iterator __next = __first;
while (++__next != __last)
{
if (__binary_pred(*__first, *__next))
erase_after(__first);
else
__first = __next;
__next = __first;
}
}
template<typename _Tp, typename _Alloc>
template<typename _Comp>
void
forward_list<_Tp, _Alloc>::
merge(forward_list&& __list, _Comp __comp)
{
_Fwd_list_node_base* __node = &this->_M_impl._M_head;
while (__node->_M_next && __list._M_impl._M_head._M_next)
{
if (__comp(static_cast<_Node*>
(__list._M_impl._M_head._M_next)->_M_value,
static_cast<_Node*>
(__node->_M_next)->_M_value))
__node->_M_transfer_after(&__list._M_impl._M_head,
__list._M_impl._M_head._M_next);
__node = __node->_M_next;
}
if (__list._M_impl._M_head._M_next)
{
__node->_M_next = __list._M_impl._M_head._M_next;
__list._M_impl._M_head._M_next = 0;
}
}
_GLIBCXX_END_NAMESPACE // namespace std
#endif /* _FORWARD_LIST_TCC */
// C++ includes used for precompiling -*- C++ -*- // C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003, 2007 Free Software Foundation, Inc. // Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
// Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -99,6 +100,7 @@ ...@@ -99,6 +100,7 @@
#ifdef __GXX_EXPERIMENTAL_CXX0X__ #ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array> #include <array>
#include <chrono> #include <chrono>
#include <forward_list>
#include <random> #include <random>
#include <ratio> #include <ratio>
#include <regex> #include <regex>
......
// <forward_list> -*- C++ -*-
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/** @file forward_list
* This is a Standard C++ Library header.
*/
#ifndef _GLIBCXX_FORWARD_LIST
#define _GLIBCXX_FORWARD_LIST 1
#pragma GCC system_header
#ifndef __GXX_EXPERIMENTAL_CXX0X__
# include <c++0x_warning.h>
#else
#include <bits/forward_list.h>
#ifndef _GLIBCXX_EXPORT_TEMPLATE
# include <bits/forward_list.tcc>
#endif
#endif // __GXX_EXPERIMENTAL_CXX0X__
#endif // _GLIBCXX_FORWARD_LIST
...@@ -100,6 +100,7 @@ ...@@ -100,6 +100,7 @@
#include <condition_variable> #include <condition_variable>
#include <deque> #include <deque>
#include <exception> #include <exception>
#include <forward_list>
#include <fstream> #include <fstream>
#include <functional> #include <functional>
#include <iomanip> #include <iomanip>
......
...@@ -98,6 +98,7 @@ ...@@ -98,6 +98,7 @@
#include <condition_variable> #include <condition_variable>
#include <deque> #include <deque>
#include <exception> #include <exception>
#include <forward_list>
#include <fstream> #include <fstream>
#include <functional> #include <functional>
#include <iomanip> #include <iomanip>
...@@ -213,6 +214,7 @@ ...@@ -213,6 +214,7 @@
#include <condition_variable> #include <condition_variable>
#include <deque> #include <deque>
#include <exception> #include <exception>
#include <forward_list>
#include <fstream> #include <fstream>
#include <functional> #include <functional>
#include <iomanip> #include <iomanip>
......
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list capacity [lib.forward_list.capacity]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following.
//
void
test01()
{
std::forward_list<double> fld;
VERIFY(fld.empty() == true);
fld.push_front(1.0);
VERIFY(fld.empty() == false);
fld.resize(0);
VERIFY(fld.empty() == true);
VERIFY(fld.max_size() == fld.get_allocator().max_size());
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// NOTE: This makes use of the fact that we know how moveable
// is implemented on list (via swap). If the implementation changed
// this test may begin to fail.
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
int main()
{
std::forward_list<double> a = {0.0, 1.0, 2.0, 3.0, 4.0};
std::forward_list<double> b = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
VERIFY((a == b) == false);
VERIFY((a < b) == true);
VERIFY((a != b) == true);
VERIFY((a > b) == false);
VERIFY((a >= b) == false);
VERIFY((a <= b) == true);
VERIFY((b == a) == false);
VERIFY((b < a) == false);
VERIFY((b != a) == true);
VERIFY((b > a) == true);
VERIFY((b >= a) == true);
VERIFY((b <= a) == false);
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// Default construction
void
test01()
{
std::forward_list<double> fld;
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// Construction from iterator range
// Copy construction with allocator
void
test01()
{
const int ni = 10;
int i[ni] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
std::forward_list<int> flccin(i, i+ni);
std::forward_list<int> flcc(flccin, std::allocator<int>());
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// Move construction with allocator
void
test01()
{
const int ni = 10;
int i[ni] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
std::forward_list<int> flmc(std::forward_list<int>(i, i+ni), std::allocator<int>());
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// Construction from given number of default item
void
test01()
{
std::forward_list<double> flvd(10);
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// Construction from given number of given item
void
test01()
{
std::forward_list<float> flv(10, 5.0F);
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// Construction from iterator range
void
test01()
{
const int ni = 10;
int i[ni] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
std::forward_list<int> fl(i, i+ni);
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// Copy construction
void
test01()
{
const int ni = 10;
int i[ni] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
std::forward_list<int> fl(i, i+ni);
std::forward_list<int> flc(fl);
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// Move construction
void
test01()
{
const int ni = 10;
int i[ni] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
std::forward_list<int> fl(i, i+ni);
std::forward_list<int> flm(std::move(fl));
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following.
// Construction from initializer list
void
test01()
{
std::forward_list<double> flil({1.0, 2.0, 3.0, 4.0, 5.0});
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
#include <array>
bool test __attribute__((unused)) = true;
class PathPoint
{
public:
PathPoint(char t, std::array<double, 3> & c)
: type(t), coord(c) { }
char getType() const { return type; }
private:
char type;
std::array<double, 3> coord;
};
// This test verifies the following.
// emplace_front
// pop_front
// emplace_after
void
test01()
{
std::forward_list<PathPoint> path;
std::array<double, 3> coord1 = { { 0.0, 1.0, 2.0 } };
path.emplace_front('a', coord1);
std::forward_list<PathPoint>::const_iterator pos = path.cbegin();
std::array<double, 3> coord2 = { { 3.0, 4.0, 5.0 } };
path.emplace_after(pos, 'b', coord2);
VERIFY(path.front().getType() == 'a');
path.pop_front();
VERIFY(path.front().getType() == 'b');
path.pop_front();
VERIFY(path.empty() == true);
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
#include <string>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// insert_after single item
// before_begin iterator
void
test01()
{
std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
fl.insert_after(fl.before_begin(), 42);
VERIFY(fl.front() == 42);
}
// This test verifies the following:
void
test02()
{
std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
std::forward_list<int>::const_iterator pos = fl.cbegin();
++pos;
VERIFY(*pos == 1);
// Note: Calling l.insert_after(pos, 5, 42); without the long five
// gets resolved to the iterator range version and fails to compile!
fl.insert_after(pos, 5L, 42);
VERIFY(*pos == 1);
++pos;
VERIFY(*pos == 42);
++pos;
++pos;
++pos;
++pos;
VERIFY(*pos == 42);
}
// This test verifies the following:
void
test03()
{
std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
std::forward_list<int>::const_iterator pos = fl.cbegin();
++pos;
VERIFY(*pos == 1);
int i[3] = {666, 777, 888};
fl.insert_after(pos, i, i+3);
VERIFY(*pos == 1);
++pos;
++pos;
++pos;
VERIFY(*pos == 888);
++pos;
VERIFY(*pos == 2);
}
// This test verifies the following:
void
test04()
{
std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
std::forward_list<int>::const_iterator pos = fl.cbegin();
++pos;
VERIFY(*pos == 1);
fl.insert_after(pos, {-1, -2, -3, -4, -5});
VERIFY(*pos == 1);
++pos;
++pos;
++pos;
VERIFY(*pos == -3);
}
// This test verifies the following:
void
test05()
{
std::forward_list<std::string> fl({"AAA", "BBB", "CCC"});
std::forward_list<std::string>::const_iterator pos = fl.cbegin();
++pos;
VERIFY(*pos == "BBB");
std::string x( "XXX" );
fl.insert_after(pos, std::move(x));
VERIFY(*pos == "BBB");
++pos;
VERIFY(*pos == "XXX");
++pos;
VERIFY(*pos == "CCC");
}
int
main()
{
test01();
test02();
test03();
test04();
test05();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// cbegin
// erase_after one iterator
// pos is useable and points to current element
void
test01()
{
std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
std::forward_list<int>::const_iterator pos = fl.cbegin();
++pos;
VERIFY(*pos == 1);
std::forward_list<int>::iterator next = fl.erase_after(pos);
VERIFY(*next == 1);
VERIFY(*pos == 1);
++pos;
VERIFY(*pos == 3);
}
// This test verifies the following:
// cbegin
// erase_after iterator range
// pos is useable and points to current element
void
test02()
{
std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
std::forward_list<int>::const_iterator pos = fl.cbegin();
++pos;
VERIFY(*pos == 1);
std::forward_list<int>::iterator stop = fl.begin();
++stop;
++stop;
++stop;
++stop;
VERIFY(*stop == 4);
std::forward_list<int>::iterator next = fl.erase_after(pos, stop);
VERIFY(*next == 1);
VERIFY(*pos == 1);
++pos;
VERIFY(*pos == 5);
}
int
main()
{
test01();
test02();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// swap
void
test01()
{
std::forward_list<int> fl1({0, 1, 2, 3, 4, 5});
std::forward_list<int> fl2({666, 777, 888});
fl1.swap(fl2);
VERIFY(fl1.front() == 666);
VERIFY(fl2.front() == 0);
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// clear
void
test01()
{
std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
VERIFY(fl.empty() == false);
fl.clear();
VERIFY(fl.empty() == true);
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// NOTE: This makes use of the fact that we know how moveable
// is implemented on list (via swap). If the implementation changed
// this test may begin to fail.
#include <forward_list>
#include <utility>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
int main()
{
std::forward_list<int> a, b;
a.push_front(1);
b = std::move(a);
VERIFY(b.empty() == false);
VERIFY(*b.begin() == 1);
VERIFY(a.empty() == true);
std::forward_list<int> c(std::move(b));
VERIFY(c.empty() == false);
(*c.begin() == 1 );
VERIFY( b.empty() == true );
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
//
void
test01()
{
std::forward_list<double> a = {0.0, 1.0, 2.0, 3.0, 4.0};
std::forward_list<double>::const_iterator posa = a.cbefore_begin();
std::forward_list<double> x = {666.0, 777.0, 888.0};
a.splice_after(posa, x);
++posa;
VERIFY(*posa == 666.0);
VERIFY(x.empty() == true);
}
// This test verifies the following:
//
void
test02()
{
std::forward_list<double> a = {0.0, 1.0, 2.0, 3.0, 4.0};
std::forward_list<double>::const_iterator posa = a.cbefore_begin();
++posa;
VERIFY(*posa == 0.0);
std::forward_list<double> y = {10.0, 11.0, 12.0, 13.0, 14.0, 15.0};
std::forward_list<double>::const_iterator befy = y.cbefore_begin();
++befy;
VERIFY(*befy == 10.0);
std::forward_list<double>::const_iterator endy = befy;
++endy;
++endy;
++endy;
++endy;
VERIFY(*endy == 14.0);
a.splice_after(posa, y, befy, endy);
VERIFY(*posa == 0.0);
VERIFY(*befy == 10.0);
++befy;
VERIFY(*befy == 15.0);
}
// This test verifies the following:
//
void
test03()
{
std::forward_list<double> a = {0.0, 1.0, 2.0, 3.0, 4.0};
std::forward_list<double>::const_iterator posa = a.cbefore_begin();
++posa;
++posa;
VERIFY(*posa == 1.0);
std::forward_list<double> z = {42.0, 43.0, 44.0};
std::forward_list<double>::const_iterator posz = z.begin();
VERIFY(*posz == 42.0);
a.splice_after(posa, z, posz);
VERIFY(*posa == 1.0);
++posa;
VERIFY(*posa == 43.0);
VERIFY(*posz == 42.0);
++posz;
VERIFY(*posz == 44.0);
}
int
main()
{
test01();
test02();
test03();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// remove
void
test01()
{
std::forward_list<int> fl ={0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
fl.remove(7);
std::forward_list<int>::const_iterator pos = fl.cbefore_begin();
for (std::size_t i = 0; i < 7; ++i)
++pos;
VERIFY(*pos == 6);
++pos;
VERIFY(*pos == 8);
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
#include <algorithm>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// remove_if
void
test01()
{
std::forward_list<int> fl ={0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
fl.remove_if(std::bind2nd(std::less<int>(),5));
std::forward_list<int>::const_iterator pos = fl.cbegin();
VERIFY(*pos == 5);
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
// unique
void
test01()
{
std::forward_list<int> fl = {99, 5, 99, 6, -5, 666, 777, 888,
42, 42, 42, 42, 42, 7, 0, 0, 0, 9, 9, 9};
fl.unique();
std::forward_list<int> fl2 = {99, 5, 99, 6, -5, 666, 777, 888, 42, 7, 0, 9};
VERIFY(fl == fl2);
}
// Test comparison predicate.
template<typename Num>
class Mod
{
public:
Mod(const Num & mod)
{
m = mod;
}
bool operator()(const Num i, const Num j)
{
return i%m == j%m;
}
private:
Num m;
};
// This test verifies the following:
// unique with predicate
void
test02()
{
std::forward_list<int> fl = {99, 5, 99, 6, -5, 666, 777, 888, 42, 7, 0, 9};
fl.unique(Mod<int>(111));
std::forward_list<int> fl2 = {99, 5, 99, 6, -5, 666, 42, 7, 0, 9};
VERIFY(fl == fl2);
}
int
main()
{
test01();
test02();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// This test verifies the following:
//
void
test01()
{
std::forward_list<double> a = {0.0, 1.0, 2.0, 3.0, 4.0};
std::forward_list<double> b = {1.0, 2.0, 3.0, 4.0, 4.0, 5.0};
a.merge(b);
std::forward_list<double> r = {0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0,
4.0, 4.0, 4.0, 5.0};
VERIFY(a == r);
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// Comparison functor.
template<typename Num>
class Comp
{
public:
Comp(const Num & num)
{
n = num;
}
bool operator()(const Num i, const Num j)
{
return (n * i) < (n * j);
}
private:
Num n;
};
// This test verifies the following:
//
void
test01()
{
const unsigned int n = 13;
int order[][n] = {
{ 0,1,2,3,4,5,6,7,8,9,10,11,12 },
{ 6,2,8,4,11,1,12,7,3,9,5,0,10 },
{ 12,11,10,9,8,7,6,5,4,3,2,1,0 },
};
std::forward_list<int> sorted(order[0], order[0] + n);
for (unsigned int i = 0; i < sizeof(order)/sizeof(*order); ++i)
{
std::forward_list<int> head(order[i], order[i] + n);
head.sort();
VERIFY(head == sorted);
}
std::forward_list<int> reversed(order[2], order[2] + n);
for (unsigned int i = 0; i < sizeof(order)/sizeof(*order); ++i)
{
std::forward_list<int> head(order[i], order[i] + n);
Comp<int> comp(-1);
head.sort( comp );
VERIFY(head == reversed);
}
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
#include <algorithm>
bool test __attribute__((unused)) = true;
// This test verifies the following:
//
void
test01()
{
const unsigned int n = 13;
int order[n] = {0,1,2,3,4,5,6,7,8,9,10,11,12};
std::forward_list<int> fl(order, order + n);
std::forward_list<int> fl2;
for (std::size_t i = 0; i < n; ++i)
fl2.push_front(order[i]);
fl.reverse();
VERIFY(std::lexicographical_compare(fl.begin(), fl.end(),
fl2.begin(), fl2.end()) == false);
}
int
main()
{
test01();
return 0;
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
#include <forward_list>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
// A nontrivial type.
template<typename T>
struct A { };
// Another nontrivial type
struct B { };
// A nontrivial type convertible from an int
struct C
{
C(int i) : i_(i) { }
bool operator==(const C& rhs) { return i_ == rhs.i_; }
int i_;
};
// This test verifies the following.
//
void
test01()
{
std::forward_list< A<B> > lst;
VERIFY(lst.begin() == lst.end());
VERIFY(std::distance(lst.begin(), lst.end()) == 0);
// check type definitions -- will fail compile if missing
typedef std::forward_list< A<B> >::reference reference;
typedef std::forward_list< A<B> >::const_reference const_reference;
typedef std::forward_list< A<B> >::iterator iterator;
typedef std::forward_list< A<B> >::const_iterator const_iterator;
typedef std::forward_list< A<B> >::size_type size_type;
typedef std::forward_list< A<B> >::difference_type difference_type;
typedef std::forward_list< A<B> >::value_type value_type;
typedef std::forward_list< A<B> >::allocator_type allocator_type;
typedef std::forward_list< A<B> >::pointer pointer;
typedef std::forward_list< A<B> >::const_pointer const_pointer;
}
int
main()
{
test01();
return 0;
}
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
#include <forward_list>
namespace std {
template <class T, class Allocator> class forward_list;
template <class T, class Allocator>
bool operator==(const forward_list<T,Allocator>& x, const forward_list<T,Allocator>&);
template <class T, class Allocator>
bool operator< (const forward_list<T,Allocator>& x, const forward_list<T,Allocator>&);
template <class T, class Allocator>
bool operator!=(const forward_list<T,Allocator>& x, const forward_list<T,Allocator>&);
template <class T, class Allocator>
bool operator> (const forward_list<T,Allocator>& x, const forward_list<T,Allocator>&);
template <class T, class Allocator>
bool operator>=(const forward_list<T,Allocator>& x, const forward_list<T,Allocator>&);
template <class T, class Allocator>
bool operator<=(const forward_list<T,Allocator>& x, const forward_list<T,Allocator>&);
template <class T, class Allocator>
void swap(forward_list<T,Allocator>& x, forward_list<T,Allocator>& y);
template <class T, class Allocator>
void swap(forward_list<T,Allocator>&& x, forward_list<T,Allocator>& y);
template <class T, class Allocator>
void swap(forward_list<T,Allocator>& x, forward_list<T,Allocator>&& y);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment