LRDE Tiger Compiler  1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
list.hxx
Go to the documentation of this file.
1 
6 #ifndef MISC_LIST_HXX
7 # define MISC_LIST_HXX
8 
9 # include <algorithm>
10 # include <ostream>
11 
12 # include <misc/list.hh>
13 # include <misc/contract.hh>
14 
15 namespace misc
16 {
17  template <class T>
19  {
20  }
21 
22  template <class T>
24  {
25  }
26 
27  template <class T>
28  list<T>::list(const T& t1)
29  {
30  this->push_back(t1);
31  }
32 
33  template <class T>
34  list<T>::list(const T& t1, const T& t2)
35  {
36  this->push_back(t1);
37  this->push_back(t2);
38  }
39 
40  template <class T>
41  list<T>::list(const T& t1, const list<T>& l2)
42  {
43  this->insert(this->begin(), l2.begin(), l2.end());
44  this->push_front(t1);
45  }
46 
47  template <class T>
48  template <class InputIterator>
49  list<T>::list(InputIterator f, InputIterator l)
50  : super_type(f, l)
51  {
52  }
53 
54  template <class T>
55  template <class C>
56  list<T>::list(const C& c)
57  : super_type(c.begin(), c.end())
58  {
59  }
60 
61  template <class T>
62  bool
63  list<T>::has(const T& data) const
64  {
65  return std::find(this->begin(), this->end(), data) != this->end();
66  }
67 
68  // Concatenation.
69  template <class T>
70  inline
71  list<T>
72  list<T>::operator+(const list<T>& s) const
73  {
74  list<T> res = *this;
75  return res += s;
76  }
77 
78  template <class T>
79  inline
80  list<T>&
82  {
83  this->insert(this->end(), s.begin(), s.end());
84  return *this;
85  }
86 
87  template <class T>
88  inline
89  list<T>&
91  {
92  return this->append(s);
93  }
94 
95  template <class T>
96  inline
97  list<T>&
98  list<T>::operator-=(const T& data)
99  {
100  precondition(has(data));
101  this->erase(std::find(this->begin(), this->end(), data));
102  return *this;
103  }
104 
105  template <class T>
106  std::ostream&
107  list<T>::dump(std::ostream& ostr) const
108  {
109  for (typename super_type::const_iterator i = this->begin();
110  i != this->end(); ++i)
111  ostr << (i == this->begin() ? "" : ", ") << *i;
112  return ostr;
113  }
114 
115  template <class T>
116  std::ostream&
117  operator<<(std::ostream& ostr, const list<T>& l)
118  {
119  return l.dump(ostr);
120  }
121 
122  template <class T>
123  bool
124  operator%(const T& data, const list<T>& l)
125  {
126  return l.has(data);
127  }
128 
129 } // namespace misc
130 
131 #endif // !MISC_LIST_HXX