/*  Copyright (C) 2015  Povilas Kanapickas <povilas@radix.lt>

    This file is part of cppreference-doc

    This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
    Unported License. To view a copy of this license, visit
    http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
    Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 1.3 or
    any later version published by the Free Software Foundation; with no
    Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
*/

#ifndef CPPREFERENCE_FORWARD_LIST_H
#define CPPREFERENCE_FORWARD_LIST_H

#if CPPREFERENCE_STDVER>= 2011

namespace std {

template<class T, class Allocator = allocator<T>>
class forward_list {
public:
    typedef T value_type;
    typedef Allocator allocator_type;
    typedef size_t size_type; // actual type unspecified
    typedef ptrdiff_t difference_type; // actual type not specified
#if CPPREFERENCE_SIMPLIFY_TYPEDEFS
    typedef T& reference;
    typedef const T& const_reference;
    typedef T* pointer;
    typedef const T* const_pointer;
#else
    typedef value_type& reference;
    typedef const value_type& const_reference;
    typedef std::allocator_traits<Allocator>::pointer pointer;
    typedef std::allocator_traits<Allocator>::const_pointer const_pointer;
#endif
    typedef T* iterator; // actual type is unspecified
    typedef const T* const_iterator; // actual type is unspecified

    // constructor
#if CPPREFERENCE_STDVER <2014
    explicit forward_list(const Allocator& alloc = Allocator());
#else
    forward_list();
    explicit forward_list(const Allocator&);
#endif

    forward_list(size_type count,
                 const T& value,
                 const Allocator& alloc = Allocator());

#if CPPREFERENCE_STDVER <2014
    explicit forward_list(size_type n);
#else
    explicit forward_list(size_type n, const Allocator& alloc = Allocator());
#endif

    template<class InputIt>
    forward_list(InputIt first, InputIt last,
                 const Allocator& alloc = Allocator());

    forward_list(const forward_list& other);
    forward_list(const forward_list& other, const Allocator& alloc);

    forward_list(forward_list&& other);
    forward_list(const forward_list&& other, const Allocator& alloc);

    forward_list(std::initializer_list<T> init,
                 const Allocator& alloc = Allocator());

    ~forward_list();

    forward_list& operator=(const forward_list& other);
    forward_list& operator=(forward_list&& other);
    forward_list& operator=(initializer_list<T> ilist);

    void assign(size_type count, const value_type& value);
    template <class InputIt>
    void assign(InputIt first, InputIt last);
    void assign(std::initializer_list<T> ilist);

    allocator_type get_allocator() const;

    // element access
    reference       front();
    const_reference front() const;

    // iterators
    iterator before_begin();
    const_iterator before_begin() const;
    iterator begin();
    const_iterator begin() const;
    iterator end();
    const_iterator end() const;

    const_iterator         cbefore_begin() const;
    const_iterator         cbefore_end() const;
    const_iterator         cbegin() const;
    const_iterator         cend() const;
    const_reverse_iterator crbegin() const;
    const_reverse_iterator crend() const;

    // copacity
    bool empty() const;
    size_type max_size() const;

    // modifiers
    void clear();

    iterator insert_after(const_iterator pos, const T& value);
    iterator insert_after(const_iterator pos, T&& value);
    iterator insert_after(const_iterator pos, size_type count, const T& value);
    template<class InputIt>
    iterator insert_after(const_iterator pos, InputIt first, InputIt last);
    iterator insert_after(const_iterator pos, std::initializer_list<T> ilist);

    template<class... Args>
    iterator emplace_after(const_iterator pos, Args&& ... args);

    iterator erase_after(const_iterator pos);
    iterator erase_after(const_iterator first, const_iterator last);

    void push_front(const T& value);
    void push_front(T&& value);

    template<class... Args>
    void emplace_front(Args&& ... args);

    void pop_front();

    void resize(size_type count);
    void resize(size_type count, const value_type& value);

    void swap(forward_list& other);

    // operations
    void merge(forward_list& other);
    void merge(forward_list&& other);

    template <class Compare>
    void merge(forward_list& other, Compare comp);
    template <class Compare>
    void merge(forward_list&& other, Compare comp);

    void splice_after(const_iterator pos, forward_list& other);
    void splice_after(const_iterator pos, forward_list& other, const_iterator it);
    void splice_after(const_iterator pos, forward_list& other,
                      const_iterator first, const_iterator last);
    void splice_after(const_iterator pos, forward_list&& other);
    void splice_after(const_iterator pos, forward_list&& other, const_iterator it);
    void splice_after(const_iterator pos, forward_list&& other,
                      const_iterator first, const_iterator last);

    void remove(const T& value);

    template<class UnaryPredicate>
    void remove_if(UnaryPredicate p);

    void reverse();

    void unique();

    template<class BinaryPredicate>
    void unique(BinaryPredicate p);

    void sort();

    template<class Compare>
    void sort(Compare comp);
};

template<class T, class Alloc>
bool operator==(const forward_list<T, Alloc>& lhs,
                const forward_list<T, Alloc>& rhs);

template<class T, class Alloc>
bool operator!=(const forward_list<T, Alloc>& lhs,
                const forward_list<T, Alloc>& rhs);

template<class T, class Alloc>
bool operator<(const forward_list<T, Alloc>& lhs,
               const forward_list<T, Alloc>& rhs);

template<class T, class Alloc>
bool operator<=(const forward_list<T, Alloc>& lhs,
                const forward_list<T, Alloc>& rhs);

template<class T, class Alloc>
bool operator>(const forward_list<T, Alloc>& lhs,
               const forward_list<T, Alloc>& rhs);

template<class T, class Alloc>
bool operator>=(const forward_list<T, Alloc>& lhs,
                const forward_list<T, Alloc>& rhs);

} // namespace std

#endif // CPPREFERENCE_STDVER>= 2011

#endif // CPPREFERENCE_FORWARD_LIST_H
