GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
base-list.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2002-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_base_list_h)
27 #define octave_base_list_h 1
28 
29 #include "octave-config.h"
30 
31 #include <cstdlib>
32 
33 #include <list>
34 
36 
37 template <typename elt_type>
38 class
40 {
41 public:
42 
43  typedef typename std::list<elt_type>::iterator iterator;
44  typedef typename std::list<elt_type>::const_iterator const_iterator;
45 
46  typedef typename std::list<elt_type>::reverse_iterator reverse_iterator;
47  typedef typename std::list<elt_type>::const_reverse_iterator
49 
50  bool empty () const { return m_lst.empty (); }
51 
52  std::size_t size () const { return m_lst.size (); }
53  std::size_t length () const { return size (); }
54 
55  iterator erase (iterator pos) { return m_lst.erase (pos); }
56 
57  template <typename P>
58  void remove_if (P pred)
59  {
60  m_lst.remove_if (pred);
61  }
62 
63  void clear () { m_lst.clear (); }
64 
65  iterator begin () { return iterator (m_lst.begin ()); }
66  const_iterator begin () const { return const_iterator (m_lst.begin ()); }
67 
68  iterator end () { return iterator (m_lst.end ()); }
69  const_iterator end () const { return const_iterator (m_lst.end ()); }
70 
71  reverse_iterator rbegin () { return reverse_iterator (m_lst.rbegin ()); }
73  { return const_reverse_iterator (m_lst.rbegin ()); }
74 
75  reverse_iterator rend () { return reverse_iterator (m_lst.rend ()); }
77  { return const_reverse_iterator (m_lst.rend ()); }
78 
79  elt_type& front () { return m_lst.front (); }
80  elt_type& back () { return m_lst.back (); }
81 
82  const elt_type& front () const { return m_lst.front (); }
83  const elt_type& back () const { return m_lst.back (); }
84 
85  void push_front (const elt_type& s) { m_lst.push_front (s); }
86  void push_back (const elt_type& s) { m_lst.push_back (s); }
87 
88  void pop_front () { m_lst.pop_front (); }
89  void pop_back () { m_lst.pop_back (); }
90 
91  // For backward compatibility.
92  void append (const elt_type& s) { m_lst.push_back (s); }
93 
94  base_list () = default;
95 
96  base_list (const std::list<elt_type>& l) : m_lst (l) { }
97 
98  base_list (const base_list& bl) = default;
99 
100  base_list& operator = (const base_list& bl) = default;
101 
102  virtual ~base_list () = default;
103 
104 protected:
105 
106  std::list<elt_type> m_lst;
107 };
108 
109 OCTAVE_END_NAMESPACE(octave)
110 
111 #endif
std::size_t length() const
Definition: base-list.h:53
std::list< elt_type > m_lst
Definition: base-list.h:106
std::list< elt_type >::const_reverse_iterator const_reverse_iterator
Definition: base-list.h:48
iterator end()
Definition: base-list.h:68
void push_back(const elt_type &s)
Definition: base-list.h:86
const elt_type & front() const
Definition: base-list.h:82
virtual ~base_list()=default
base_list(const base_list &bl)=default
const elt_type & back() const
Definition: base-list.h:83
void append(const elt_type &s)
Definition: base-list.h:92
void pop_front()
Definition: base-list.h:88
std::list< elt_type >::const_iterator const_iterator
Definition: base-list.h:44
void clear()
Definition: base-list.h:63
reverse_iterator rend()
Definition: base-list.h:75
const_reverse_iterator rend() const
Definition: base-list.h:76
void push_front(const elt_type &s)
Definition: base-list.h:85
std::list< elt_type >::reverse_iterator reverse_iterator
Definition: base-list.h:46
base_list(const std::list< elt_type > &l)
Definition: base-list.h:96
elt_type & front()
Definition: base-list.h:79
const_iterator begin() const
Definition: base-list.h:66
const_reverse_iterator rbegin() const
Definition: base-list.h:72
std::size_t size() const
Definition: base-list.h:52
void remove_if(P pred)
Definition: base-list.h:58
elt_type & back()
Definition: base-list.h:80
void pop_back()
Definition: base-list.h:89
reverse_iterator rbegin()
Definition: base-list.h:71
const_iterator end() const
Definition: base-list.h:69
bool empty() const
Definition: base-list.h:50
iterator begin()
Definition: base-list.h:65
std::list< elt_type >::iterator iterator
Definition: base-list.h:43
base_list()=default
iterator erase(iterator pos)
Definition: base-list.h:55
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn