summaryrefslogtreecommitdiff
path: root/libcult/cult/containers/stack.hxx
blob: 930bfe885eeaed39c8fd18abcc5be7380df3e435 (plain)
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
// file      : cult/containers/stack.hxx
// author    : Boris Kolpackov <boris@kolpackov.net>
// copyright : Copyright (c) 2005-2010 Boris Kolpackov
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#ifndef CULT_CONTAINERS_STACK_HXX
#define CULT_CONTAINERS_STACK_HXX

#include <cult/types.hxx>

#include <cult/containers/deque.hxx>

namespace Cult
{
  namespace Containers
  {
    template <typename T, typename C = Deque<T> >
    class Stack
    {
    public:
      typedef C Container;
      typedef typename Container::Value Value;


    public:
      explicit
      Stack (Container const& c = Container())
          : c_ (c)
      {
      }

      Boolean
      empty () const
      {
        return c_.empty();
      }

      Size
      size () const
      {
        return c_.size();
      }

      Value&
      top ()
      {
        return c_.back();
      }

      Value const&
      top () const
      {
        return c_.back();
      }

      Void
      push (const Value& x)
      {
        c_.push_back(x);
      }

      Void
      pop()
      {
        c_.pop_back();
      }

    protected:
      Container c_;
    };

    /*
    template <class T, class Container>
    bool operator==(const stack<T, Container>& x,
                    const stack<T, Container>& y);
    template <class T, class Container>
    bool operator< (const stack<T, Container>& x,
                    const stack<T, Container>& y);
    template <class T, class Container>
    bool operator!=(const stack<T, Container>& x,
                    const stack<T, Container>& y);
    template <class T, class Container>
    bool operator> (const stack<T, Container>& x,
                    const stack<T, Container>& y);
    template <class T, class Container>
    bool operator>=(const stack<T, Container>& x,
                    const stack<T, Container>& y);
    template <class T, class Container>
    bool operator<=(const stack<T, Container>& x,
                    const stack<T, Container>& y);
    */
  }
}

#endif  // CULT_CONTAINERS_STACK_HXX