GNU Octave  6.2.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-2021 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 
35 namespace octave
36 {
37  template <typename elt_type>
38  class
39  base_list
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 (void) const { return m_lst.empty (); }
51 
52  size_t size (void) const { return m_lst.size (); }
53  size_t length (void) 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 (void) { m_lst.clear (); }
64 
65  iterator begin (void) { return iterator (m_lst.begin ()); }
66  const_iterator begin (void) const { return const_iterator (m_lst.begin ()); }
67 
68  iterator end (void) { return iterator (m_lst.end ()); }
69  const_iterator end (void) const { return const_iterator (m_lst.end ()); }
70 
71  reverse_iterator rbegin (void) { return reverse_iterator (m_lst.rbegin ()); }
73  { return const_reverse_iterator (m_lst.rbegin ()); }
74 
75  reverse_iterator rend (void) { return reverse_iterator (m_lst.rend ()); }
77  { return const_reverse_iterator (m_lst.rend ()); }
78 
79  elt_type& front (void) { return m_lst.front (); }
80  elt_type& back (void) { return m_lst.back (); }
81 
82  const elt_type& front (void) const { return m_lst.front (); }
83  const elt_type& back (void) 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 (void) { m_lst.pop_front (); }
89  void pop_back (void) { 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 (void) = 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 (void) = default;
103 
104  protected:
105 
106  std::list<elt_type> m_lst;
107  };
108 }
109 
110 #endif
void pop_front(void)
Definition: base-list.h:88
void append(const elt_type &s)
Definition: base-list.h:92
base_list(const base_list &bl)=default
bool empty(void) const
Definition: base-list.h:50
void remove_if(P pred)
Definition: base-list.h:58
const elt_type & front(void) const
Definition: base-list.h:82
void pop_back(void)
Definition: base-list.h:89
const_reverse_iterator rbegin(void) const
Definition: base-list.h:72
base_list(const std::list< elt_type > &l)
Definition: base-list.h:96
const_iterator end(void) const
Definition: base-list.h:69
virtual ~base_list(void)=default
size_t length(void) const
Definition: base-list.h:53
elt_type & front(void)
Definition: base-list.h:79
void clear(void)
Definition: base-list.h:63
std::list< elt_type > m_lst
Definition: base-list.h:106
iterator erase(iterator pos)
Definition: base-list.h:55
size_t size(void) const
Definition: base-list.h:52
std::list< elt_type >::reverse_iterator reverse_iterator
Definition: base-list.h:46
reverse_iterator rend(void)
Definition: base-list.h:75
void push_back(const elt_type &s)
Definition: base-list.h:86
std::list< elt_type >::iterator iterator
Definition: base-list.h:43
reverse_iterator rbegin(void)
Definition: base-list.h:71
std::list< elt_type >::const_reverse_iterator const_reverse_iterator
Definition: base-list.h:48
const elt_type & back(void) const
Definition: base-list.h:83
const_reverse_iterator rend(void) const
Definition: base-list.h:76
void push_front(const elt_type &s)
Definition: base-list.h:85
iterator begin(void)
Definition: base-list.h:65
elt_type & back(void)
Definition: base-list.h:80
iterator end(void)
Definition: base-list.h:68
const_iterator begin(void) const
Definition: base-list.h:66
base_list(void)=default
std::list< elt_type >::const_iterator const_iterator
Definition: base-list.h:44