/*  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_DEQUE_H
#define CPPREFERENCE_DEQUE_H

#if CPPREFERENCE_STDVER>= 2011
#include <initializer_list>
#endif

namespace std {

template<class T, class Allocator = allocator<T>>
class deque {
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;
#elif CPPREFERENCE_STDVER <2011
    typedef typename Allocator::reference reference;
    typedef typename Allocator::const_reference const_reference;
    typedef typename Allocator::pointer pointer;
    typedef typename Allocator::const_pointer const_pointer;
#else
    typedef value_type& reference;
    typedef const value_type& const_reference;
    typedef typename std::allocator_traits<Allocator>::pointer pointer;
    typedef typename 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
    typedef std::reverse_iterator<iterator> reverse_iterator;
    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;

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

#if CPPREFERENCE_STDVER <2011
    explicit deque(size_type count,
                   const T& value = T(),
                   const Allocator& alloc = Allocator());
#else
    deque(size_type count,
          const T& value,
          const Allocator& alloc = Allocator());

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

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

    deque(const deque& other);
#if CPPREFERENCE_STDVER>= 2011
    deque(const deque& other, const Allocator& alloc);
#endif

    deque(deque&& other);
#if CPPREFERENCE_STDVER>= 2011
    deque(deque&& other, const Allocator& alloc);

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

    ~deque();

    deque& operator=(const deque& other);
#if CPPREFERENCE_STDVER>= 2011
    deque& operator=(deque&& other);
    deque& operator=(initializer_list<T> ilist);
#endif

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

    allocator_type get_allocator() const;

    // element access
    reference       at(size_type n);
    const_reference at(size_type n) const;
    reference       operator[](size_type n);
    const_reference operator[](size_type n) const;

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

    // iterators
    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;

#if CPPREFERENCE_STDVER>= 2011
    const_iterator         cbegin() const;
    const_iterator         cend() const;
    const_reverse_iterator crbegin() const;
    const_reverse_iterator crend() const;
#endif

    bool empty() const;
    size_type size() const;
    size_type max_size() const;
    void reserve(size_type n);
    size_type capacity() const;

#if CPPREFERENCE_STDVER>= 2011
    void shrink_to_fit();
#endif

    // modifiers
    void clear();

#if CPPREFERENCE_STDVER <2011
    iterator insert(iterator pos, const T& value);
    void insert(iterator pos, size_type count, const T& value);
    template<class InputIt>
    void insert(iterator pos, InputIt first, InputIt last);
#else
    iterator insert(const_iterator pos, const T& value);
    iterator insert(const_iterator pos, T&& value);
    iterator insert(const_iterator pos, size_type count, const T& value);
    template<class InputIt>
    iterator insert(const_iterator pos, InputIt first, InputIt last);
    iterator insert(const_iterator pos, std::initializer_list<T> ilist);
#endif

#if CPPREFERENCE_STDVER>= 2011
    template<class... Args>
    iterator emplace(const_iterator pos, Args&& ... args);
#endif

#if CPPREFERENCE_STDVER <2011
    iterator erase(iterator pos);
    iterator erase(iterator first, iterator last);
#else
    iterator erase(const_iterator pos);
    iterator erase(const_iterator first, const_iterator last);
#endif

    void push_back(const T& value);
#if CPPREFERENCE_STDVER> 2011
    void push_back(T&& value);
#endif

#if CPPREFERENCE_STDVER>= 2011
    template<class... Args>
    void emplace_back(Args&& ... args);
#endif

    void pop_back();

    void push_front(const T& value);
#if CPPREFERENCE_STDVER>= 2011
    void push_front(T&& value);
#endif

#if CPPREFERENCE_STDVER>= 2011
    template<class... Args>
    void emplace_front(Args&& ... args);
#endif

    void pop_front();

#if CPPREFERENCE_STDVER <2011
    void resize(size_type count, T value = T());
#else
    void resize(size_type count);
    void resize(size_type count, const value_type& value);
#endif

    void swap(deque& other);
};

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

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

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

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

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

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

} // namespace std

#endif // CPPREFERENCE_DEQUE_H
