C++-Referenz/ Standardbibliothek/ Container-Klassen/ list

Alte Seite

Die Arbeit am Buch »C++-Referenz« wurde vom Hauptautor eingestellt. Ein Lehrbuch zum Thema C++ ist unter »C++-Programmierung« zu finden. Eine sehr umfangreiche und gute Referenz gibt es unter cppreference.com.

Diese Seite beschreibt C++98, einen stark veralteten Standard. Aktuelle Referenz.

// Header: list
template <typename T, typename Allocator = allocator<T> >
class list{
public:
    typedef typename Allocator::reference         reference;
    typedef typename Allocator::const_reference   const_reference;
    typedef implementation defined                iterator;
    typedef implementation defined                const_iterator;
    typedef typename Allocator::size_type         size_type;
    typedef typename Allocator::difference_type   difference_type;
    typedef T                                     value_type;
    typedef Allocator                             allocator_type;
    typedef typename Allocator::pointer           pointer;
    typedef typename Allocator::const_pointer     const_pointer;
    typedef std::reverse_iterator<iterator>       reverse_iterator;
    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;

// Konstruktoren, Destruktor, Kopieren
    explicit list(Allocator const& = Allocator());

    explicit list(size_type n, T const& value = T(), Allocator const& = Allocator());

    template <typename InputIterator>
    list(InputIterator first, InputIterator last, Allocator const& = Allocator());

    list(list<T,Allocator> const& x);

    ~list();

    list<T,Allocator>& operator=(list<T,Allocator> const& x);

    template <typename InputIterator>    void assign(InputIterator first, InputIterator last);
    template <typename Size, typename T> void assign(Size n, T const& t = T());

    allocator_type get_allocator()const;

// Iteratoren
    iterator       begin();
    const_iterator begin()const;
    iterator       end();
    const_iterator end()const;

    reverse_iterator       rbegin();
    const_reverse_iterator rbegin()const;
    reverse_iterator       rend();
    const_reverse_iterator rend()const;

// Kapazität
    bool      empty()const;
    size_type size()const;
    size_type max_size()const;

    void      resize(size_type sz, T c = T());

// Elementzugriff
    reference       front();
    const_reference front()const;
    reference       back();
    const_reference back()const;

// Modifizierer
    void push_front(T const& x);
    void pop_front();
    void push_back(T const& x);
    void pop_back();

    iterator  insert(iterator position, T const& x = T());
    void      insert(iterator position, size_type n, T const& x);
    template <typename InputIterator>
    void      insert(iterator position, InputIterator first, InputIterator last);

    iterator erase(iterator position);
    iterator erase(iterator position, iterator last);

    void swap(list<T,Allocator>&);

    void clear();

// Listenoperationen
    void splice(iterator position, list<T,Allocator>& x);
    void splice(iterator position, list<T,Allocator>& x, iterator i);
    void splice(iterator position, list<T,Allocator>& x, iterator first, iterator last);

    void                               remove(T const& value);
    template <typename Predicate> void remove_if(Predicate pred);

    void                                     unique();
    template <typename BinaryPredicate> void unique(BinaryPredicate binary_pred);

    void                             merge(list<T,Allocator>& x);
    template <typename Compare> void merge(list<T,Allocator>& x, Compare comp);

    void                             sort();
    template <typename Compare> void sort(Compare comp);

    void reverse();
};

// Vergleiche
template <typename T, typename Allocator>
bool operator==(list<T,Allocator> const& x, list<T,Allocator> const& y);

template <typename T, typename Allocator>
bool operator< (list<T,Allocator> const& x, list<T,Allocator> const& y);

template <typename T, typename Allocator>
bool operator!=(list<T,Allocator> const& x, list<T,Allocator> const& y);

template <typename T, typename Allocator>
bool operator> (list<T,Allocator> const& x, list<T,Allocator> const& y);

template <typename T, typename Allocator>
bool operator>=(list<T,Allocator> const& x, list<T,Allocator> const& y);

template <typename T, typename Allocator>
bool operator<=(list<T,Allocator> const& x, list<T,Allocator> const& y);

// Spezialisierte Algorithmen
template <typename T, typename Allocator>
void swap(list<T,Allocator>& x, list<T,Allocator>& y);