1 # C++ skeleton for Bison
3 # Copyright (C) 2002-2012 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 m4_pushdef([b4_copyright_years],
21 # We do want M4 expansion after # for CPP macros.
24 @output(b4_dir_prefix[]stack.hh@)@
25 b4_copyright([Stack handling for Bison parsers in C++],
29 ** \file ]b4_dir_prefix[stack.hh
30 ** Define the ]b4_namespace_ref[::stack class.
33 ]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[
38 template <class T, class S = std::deque<T> >
42 // Hide our reversed order.
43 typedef typename S::reverse_iterator iterator;
44 typedef typename S::const_reverse_iterator const_iterator;
50 stack (unsigned int n) : seq_ (n)
56 operator [] (unsigned int i)
63 operator [] (unsigned int i) const
77 pop (unsigned int n = 1)
90 inline const_iterator begin () const { return seq_.rbegin (); }
91 inline const_iterator end () const { return seq_.rend (); }
97 /// Present a slice of the top of a stack.
98 template <class T, class S = stack<T> >
102 slice (const S& stack, unsigned int range)
110 operator [] (unsigned int i) const
112 return stack_[range_ - i];
121 ]b4_cpp_guard_close([b4_dir_prefix[]stack.hh])
123 m4_popdef([b4_copyright_years])dnl