1 # C++ skeleton for Bison
3 # Copyright (C) 2002-2015 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],
23 m4_define([b4_stack_define],
24 [[ /// A stack with random access from its top.
25 template <class T, class S = std::vector<T> >
29 // Hide our reversed order.
30 typedef typename S::reverse_iterator iterator;
31 typedef typename S::const_reverse_iterator const_iterator;
45 /// Index 0 returns the topmost element.
47 operator[] (unsigned i)
49 return seq_[seq_.size () - 1 - i];
54 /// Index 0 returns the topmost element.
56 operator[] (unsigned i) const
58 return seq_[seq_.size () - 1 - i];
61 /// Steal the contents of \a t.
63 /// Close to move-semantics.
68 operator[](0).move (t);
93 return seq_.rbegin ();
103 stack (const stack&);
104 stack& operator= (const stack&);
105 /// The wrapped container.
109 /// Present a slice of the top of a stack.
110 template <class T, class S = stack<T> >
114 slice (const S& stack, unsigned range)
120 operator [] (unsigned i) const
122 return stack_[range_ - i];
132 [b4_output_begin([b4_dir_prefix[]stack.hh])
133 b4_copyright([Stack handling for Bison parsers in C++])[
136 ** \file ]b4_dir_prefix[stack.hh
137 ** Define the ]b4_namespace_ref[::stack class.
140 ]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[
148 ]b4_cpp_guard_close([b4_dir_prefix[]stack.hh])
152 m4_popdef([b4_copyright_years])