File: stack

package info (click to toggle)
cppreference-doc 20170409-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 259,872 kB
  • sloc: xml: 570,184; python: 1,923; php: 520; makefile: 168; sh: 25; cpp: 9; ansic: 9
file content (125 lines) | stat: -rw-r--r-- 3,295 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*  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_STACK_H
#define CPPREFERENCE_STACK_H

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

namespace std {

template <
    class T,
    class Container = std::deque<T>
    > class stack {
public:
    typedef Container container_type;
    typedef typename Container::value_type value_type;
    typedef typename Container::size_type size_type;
    typedef typename Container::reference reference;
    typedef typename Container::const_reference const_reference;

#if CPPREFERENCE_STDVER <2011
    explicit stack(const Container& cont = Container());
#else
    explicit stack(const Container& cont);
    explicit stack(Container&& cont = Container());
    stack(const stack& other);
    stack(stack&& other);

    template<class Alloc>
    explicit stack(const Alloc& alloc);

    template<class Alloc>
    stack(const Container& cont, const Alloc& alloc);

    template<class Alloc>
    stack(Container&& cont, const Alloc& alloc);

    template<class Alloc>
    stack(const stack& other, const Alloc& alloc);

    template<class Alloc>
    stack(stack&& other, const Alloc& alloc);
#endif

    ~stack();

    stack<T, Container>&
    operator=(const stack<T, Container>& other);

#if CPPREFERENCE_STDVER>= 2011
    stack<T, Container>&
    operator=(stack<T, Container>&& other);
#endif

    reference top();
    const_reference top() const;

    bool empty() const;
    size_type size() const;

    void push(const T& value);

#if CPPREFERENCE_STDVER>= 2011
    void push(T&& value);
    template<class... Args>
    void emplace(Args&& ... args);
#endif

    void pop();

#if CPPREFERENCE_STDVER>= 2011
    void swap(stack& other);
#endif

protected:
    Container c;
};

template<class T, class Container>
bool operator==(stack<T, Container>& lhs,
                stack<T, Container>& rhs);

template<class T, class Container>
bool operator!=(stack<T, Container>& lhs,
                stack<T, Container>& rhs);

template<class T, class Container>
bool operator<(stack<T, Container>& lhs,
               stack<T, Container>& rhs);

template<class T, class Container>
bool operator<=(stack<T, Container>& lhs,
                stack<T, Container>& rhs);

template<class T, class Container>
bool operator>(stack<T, Container>& lhs,
               stack<T, Container>& rhs);

template<class T, class Container>
bool operator>=(stack<T, Container>& lhs,
                stack<T, Container>& rhs);

template<class T, class Container>
void swap(stack<T, Container>& lhs,
          stack<T, Container>& rhs);


} // namespace std

#endif // CPPREFERENCE_STACK_H