1
/*
2
 *
3
 * Copyright (c) 1994
4
 * Hewlett-Packard Company
5
 *
6
 * Copyright (c) 1996,1997
7
 * Silicon Graphics Computer Systems, Inc.
8
 *
9
 * Copyright (c) 1997
10
 * Moscow Center for SPARC Technology
11
 *
12
 * Copyright (c) 1999
13
 * Boris Fomitchev
14
 *
15
 * This material is provided "as is", with absolutely no warranty expressed
16
 * or implied. Any use is at your own risk.
17
 *
18
 * Permission to use or copy this software for any purpose is hereby granted
19
 * without fee, provided the above notices are retained on all copies.
20
 * Permission to modify the code and to distribute modified code is granted,
21
 * provided the above notices are retained, and a notice that the code was
22
 * modified is included with the above copyright notice.
23
 *
24
 */
25
26
#ifndef _STLP_STACK
27
#  define _STLP_STACK
28
29
#ifndef _STLP_OUTERMOST_HEADER_ID
30
#  define _STLP_OUTERMOST_HEADER_ID 0x60
31
#  include <stl/_prolog.h>
32
#endif
33
34
#include <deque>
35
36
_STLP_BEGIN_NAMESPACE
37
38
#  if !defined ( _STLP_LIMITED_DEFAULT_TEMPLATES )
39
template <class _Tp, class _Sequence = deque<_Tp> >
40
#  elif defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
41
#    define _STLP_STACK_ARGS _Tp
42
template <class _Tp>
43
#  else
44
template <class _Tp, class _Sequence>
45
#  endif
46
class stack
47
{
48
#  ifdef _STLP_STACK_ARGS
49
  typedef deque<_Tp> _Sequence;
50
  typedef stack<_Tp> _Self;
51
#  else
52
  typedef stack<_Tp, _Sequence> _Self;
53
#  endif
54
55
public:
56
  typedef typename _Sequence::value_type      value_type;
57
  typedef typename _Sequence::size_type       size_type;
58
  typedef          _Sequence                  container_type;
59
60
  typedef typename _Sequence::reference       reference;
61
  typedef typename _Sequence::const_reference const_reference;
62
protected:
63
  //c is a Standard name (23.2.3.3), do no make it STLport naming convention compliant.
64
  _Sequence c;
65
public:
66
  stack() : c() {}
67
  explicit stack(const _Sequence& __s) : c(__s) {}
68
69
#  if !defined (_STLP_NO_MOVE_SEMANTIC)
70
  stack(__move_source<_Self> src) :
71
      c(src.get().c)
72
    { }
73
#  endif
74
75
  bool empty() const { return c.empty(); }
76
  size_type size() const { return c.size(); }
77
  reference top() { return c.back(); }
78
  const_reference top() const { return c.back(); }
79
  void push(const value_type& __x) { c.push_back(__x); }
80
  void pop() { c.pop_back(); }
81
  const _Sequence& _Get_s() const { return c; }
82
#  if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
83
  void _M_swap_workaround(_Self& __x) {
84
    _Sequence __tmp = c;
85
    c = __x.c;
86
    __x.c = __tmp;
87
  }
88
#  endif
89
};
90
91
#  ifndef _STLP_STACK_ARGS
92
#    define _STLP_STACK_ARGS _Tp, _Sequence
93
#    define _STLP_STACK_HEADER_ARGS class _Tp, class _Sequence
94
#  else
95
#    define _STLP_STACK_HEADER_ARGS class _Tp
96
#  endif
97
98
template < _STLP_STACK_HEADER_ARGS >
99
inline bool _STLP_CALL  operator==(const stack< _STLP_STACK_ARGS >& __x,
100
                                   const stack< _STLP_STACK_ARGS >& __y)
101
{ return __x._Get_s() == __y._Get_s(); }
102
103
template < _STLP_STACK_HEADER_ARGS >
104
inline bool _STLP_CALL  operator<(const stack< _STLP_STACK_ARGS >& __x,
105
                                  const stack< _STLP_STACK_ARGS >& __y)
106
{ return __x._Get_s() < __y._Get_s(); }
107
108
_STLP_RELOPS_OPERATORS(template < _STLP_STACK_HEADER_ARGS >, stack< _STLP_STACK_ARGS >)
109
110
#  undef _STLP_STACK_ARGS
111
#  undef _STLP_STACK_HEADER_ARGS
112
113
#  if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_NO_MOVE_SEMANTIC)
114
115
template <class _Tp, class _Sequence>
116
struct __has_trivial_move<stack<_Tp, _Sequence> > :
117
  public integral_constant<bool, __has_trivial_move<_Sequence>::value>
118
{ };
119
120
template <class _Tp, class _Sequence>
121
struct __has_move_constructor<stack<_Tp, _Sequence> > :
122
    public integral_constant<bool, __has_move_constructor<_Sequence>::value>
123
{ };
124
125
#  endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
126
127
_STLP_END_NAMESPACE
128
129
#if (_STLP_OUTERMOST_HEADER_ID == 0x60)
130
#  include <stl/_epilog.h>
131
#  undef _STLP_OUTERMOST_HEADER_ID
132
#endif
133
134
#endif /* _STLP_STACK */
135
136
// Local Variables:
137
// mode:C++
138
// End: