1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef NASTY_VECTOR_H
11#define NASTY_VECTOR_H
12
13#include <vector>
14#include <list>
15
16template <class T>
17class nasty_vector
18{
19public:
20    typedef typename std::vector<T>                           nested_container;
21    typedef typename nested_container::value_type             value_type;
22    typedef typename nested_container::reference              reference;
23    typedef typename nested_container::const_reference        const_reference;
24    typedef typename nested_container::iterator               iterator;
25    typedef typename nested_container::const_iterator         const_iterator;
26
27    typedef typename nested_container::size_type              size_type;
28    typedef typename nested_container::difference_type        difference_type;
29    typedef typename nested_container::pointer                pointer;
30    typedef typename nested_container::const_pointer          const_pointer;
31
32    typedef typename nested_container::reverse_iterator       reverse_iterator;
33    typedef typename nested_container::const_reverse_iterator const_reverse_iterator;
34
35    nasty_vector() : v_() {}
36    explicit nasty_vector(size_type n) : v_(n) {}
37    nasty_vector(size_type n, const value_type& value) : v_(n, value) {}
38    template <class InputIterator> nasty_vector(InputIterator first, InputIterator last) : v_(first, last) {}
39#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
40    nasty_vector(std::initializer_list<value_type> il) : v_(il) {}
41#endif
42    ~nasty_vector() {}
43
44    template <class InputIterator>
45        void assign(InputIterator first, InputIterator last) { v_.assign(first, last); }
46    void assign(size_type n, const value_type& u) { v_.assign(n, u); }
47#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
48    void assign(std::initializer_list<value_type> il)  { v_.assign(il); }
49#endif
50
51    iterator               begin() _NOEXCEPT         { return v_.begin(); }
52    const_iterator         begin()   const _NOEXCEPT { return v_.begin(); }
53    iterator               end() _NOEXCEPT           { return v_.end(); }
54    const_iterator         end()     const _NOEXCEPT { return v_.end(); }
55
56    reverse_iterator       rbegin() _NOEXCEPT        { return v_.rbegin(); }
57    const_reverse_iterator rbegin()  const _NOEXCEPT { return v_.rbegin(); }
58    reverse_iterator       rend() _NOEXCEPT          { return v_.rend(); }
59    const_reverse_iterator rend()    const _NOEXCEPT { return v_.rend(); }
60
61    const_iterator         cbegin()  const _NOEXCEPT { return v_.cbegin(); }
62    const_iterator         cend()    const _NOEXCEPT { return v_.cend(); }
63    const_reverse_iterator crbegin() const _NOEXCEPT { return v_.crbegin(); }
64    const_reverse_iterator crend()   const _NOEXCEPT { return v_.crend(); }
65
66    size_type size() const _NOEXCEPT      { return v_.size(); }
67    size_type max_size() const _NOEXCEPT  { return v_.max_size(); }
68    size_type capacity() const _NOEXCEPT  { return v_.capacity(); }
69    bool empty() const _NOEXCEPT          { return v_.empty(); }
70    void reserve(size_type n)             { v_.reserve(n); };
71    void shrink_to_fit() _NOEXCEPT        { v_.shrink_to_fit(); }
72
73    reference       operator[](size_type n)       { return v_[n]; }
74    const_reference operator[](size_type n) const { return v_[n]; }
75    reference       at(size_type n)               { return v_.at(n); }
76    const_reference at(size_type n) const         { return v_.at(n); }
77
78    reference       front()       { return v_.front(); }
79    const_reference front() const { return v_.front(); }
80    reference       back()        { return v_.back(); }
81    const_reference back() const  { return v_.back(); }
82
83    value_type*       data() _NOEXCEPT       { return v_.data(); }
84    const value_type* data() const _NOEXCEPT { return v_.data(); }
85
86    void push_back(const value_type& x)     { v_.push_back(x); }
87#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
88    void push_back(value_type&& x)          { v_.push_back(std::forward<value_type&&>(x)); }
89#ifndef _LIBCPP_HAS_NO_VARIADICS
90    template <class... Args>
91        void emplace_back(Args&&... args)   { v_.emplace_back(std::forward<Args>(args)...); }
92#endif
93#endif
94    void pop_back()                         { v_.pop_back(); }
95
96#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
97#ifndef _LIBCPP_HAS_NO_VARIADICS
98    template <class... Args> iterator emplace(const_iterator pos, Args&&... args)
99    { return v_.emplace(pos, std::forward<Args>(args)...); }
100#endif
101#endif
102
103    iterator insert(const_iterator pos, const value_type& x) { return v_.insert(pos, x); }
104#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
105    iterator insert(const_iterator pos, value_type&& x)      { return v_.insert(pos, std::forward<value_type>(x)); }
106#endif
107    iterator insert(const_iterator pos, size_type n, const value_type& x) { return v_.insert(pos, n, x); }
108    template <class InputIterator>
109        iterator insert(const_iterator pos, InputIterator first, InputIterator last)
110    { return v_.insert(pos, first, last); }
111
112#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
113    iterator insert(const_iterator pos, std::initializer_list<value_type> il) { return v_.insert(pos, il); }
114#endif
115
116    iterator erase(const_iterator pos)                        { return v_.erase(pos); }
117    iterator erase(const_iterator first, const_iterator last) { return v_.erase(first, last); }
118
119    void clear() _NOEXCEPT { v_.clear(); }
120
121    void resize(size_type sz)                      { v_.resize(sz); }
122    void resize(size_type sz, const value_type& c) { v_.resize(sz, c); }
123
124    void swap(nasty_vector &nv) _NOEXCEPT_(std::__is_nothrow_swappable<nested_container>::value)
125    { v_.swap(nv.v_); }
126
127    nasty_vector *operator &()             { return nullptr; }  // nasty
128    const nasty_vector *operator &() const { return nullptr; }  // nasty
129
130    nested_container v_;
131};
132
133template <class T>
134bool operator==(const nasty_vector<T>& x, const nasty_vector<T>& y) { return x.v_ == y.v_; }
135
136template <class T>
137class nasty_list
138{
139public:
140
141    typedef typename std::list<T>                             nested_container;
142    typedef typename nested_container::value_type             value_type;
143    typedef typename nested_container::reference              reference;
144    typedef typename nested_container::const_reference        const_reference;
145    typedef typename nested_container::iterator               iterator;
146    typedef typename nested_container::const_iterator         const_iterator;
147
148    typedef typename nested_container::size_type              size_type;
149    typedef typename nested_container::difference_type        difference_type;
150    typedef typename nested_container::pointer                pointer;
151    typedef typename nested_container::const_pointer          const_pointer;
152
153    typedef typename nested_container::reverse_iterator       reverse_iterator;
154    typedef typename nested_container::const_reverse_iterator const_reverse_iterator;
155
156    nasty_list() : l_() {}
157    explicit nasty_list(size_type n)  : l_(n) {}
158    nasty_list(size_type n, const value_type& value)  : l_(n,value) {}
159    template <class Iter>
160        nasty_list(Iter first, Iter last)  : l_(first, last) {}
161#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
162    nasty_list(std::initializer_list<value_type> il) : l_(il) {}
163#endif
164
165    ~nasty_list() {}
166
167#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
168    nasty_list& operator=(std::initializer_list<value_type> il) { l_ = il; return *this; }
169#endif
170    template <class Iter>
171        void assign(Iter first, Iter last) { l_.assign(first, last); }
172    void assign(size_type n, const value_type& t) { l_.assign(n, t); }
173#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
174    void assign(std::initializer_list<value_type> il) { l_.assign(il); }
175#endif
176
177
178    iterator               begin() _NOEXCEPT         { return l_.begin(); }
179    const_iterator         begin()   const _NOEXCEPT { return l_.begin(); }
180    iterator               end() _NOEXCEPT           { return l_.end(); }
181    const_iterator         end()     const _NOEXCEPT { return l_.end(); }
182
183    reverse_iterator       rbegin() _NOEXCEPT        { return l_.rbegin(); }
184    const_reverse_iterator rbegin()  const _NOEXCEPT { return l_.rbegin(); }
185    reverse_iterator       rend() _NOEXCEPT          { return l_.rend(); }
186    const_reverse_iterator rend()    const _NOEXCEPT { return l_.rend(); }
187
188    const_iterator         cbegin()  const _NOEXCEPT { return l_.cbegin(); }
189    const_iterator         cend()    const _NOEXCEPT { return l_.cend(); }
190    const_reverse_iterator crbegin() const _NOEXCEPT { return l_.crbegin(); }
191    const_reverse_iterator crend()   const _NOEXCEPT { return l_.crend(); }
192
193    reference       front()       { return l_.front(); }
194    const_reference front() const { return l_.front(); }
195    reference       back()        { return l_.back(); }
196    const_reference back() const  { return l_.back(); }
197
198    size_type size() const _NOEXCEPT      { return l_.size(); }
199    size_type max_size() const _NOEXCEPT  { return l_.max_size(); }
200    bool empty() const _NOEXCEPT          { return l_.empty(); }
201
202    void push_front(const value_type& x)    { l_.push_front(x); }
203    void push_back(const value_type& x)     { l_.push_back(x); }
204#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
205    void push_back(value_type&& x)          { l_.push_back(std::forward<value_type&&>(x)); }
206    void push_front(value_type&& x)         { l_.push_back(std::forward<value_type&&>(x)); }
207#ifndef _LIBCPP_HAS_NO_VARIADICS
208    template <class... Args>
209        void emplace_back(Args&&... args)   { l_.emplace_back(std::forward<Args>(args)...); }
210    template <class... Args>
211        void emplace_front(Args&&... args)  { l_.emplace_front(std::forward<Args>(args)...); }
212#endif
213#endif
214    void pop_front()                        { l_.pop_front(); }
215    void pop_back()                         { l_.pop_back(); }
216
217#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
218#ifndef _LIBCPP_HAS_NO_VARIADICS
219    template <class... Args> iterator emplace(const_iterator pos, Args&&... args)
220    { return l_.emplace(pos, std::forward<Args>(args)...); }
221#endif
222#endif
223
224    iterator insert(const_iterator pos, const value_type& x) { return l_.insert(pos, x); }
225#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
226    iterator insert(const_iterator pos, value_type&& x)      { return l_.insert(pos, std::forward<value_type>(x)); }
227#endif
228    iterator insert(const_iterator pos, size_type n, const value_type& x) { return l_.insert(pos, n, x); }
229    template <class InputIterator>
230        iterator insert(const_iterator pos, InputIterator first, InputIterator last)
231    { return l_.insert(pos, first, last); }
232
233#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
234    iterator insert(const_iterator pos, std::initializer_list<value_type> il) { return l_.insert(pos, il); }
235#endif
236
237    iterator erase(const_iterator pos)                      { return l_.erase(pos); }
238    iterator erase(const_iterator pos, const_iterator last) { return l_.erase(pos, last); }
239
240    void resize(size_type sz)                      { l_.resize(); }
241    void resize(size_type sz, const value_type& c) { l_.resize(c); }
242
243    void swap(nasty_list &nl) _NOEXCEPT_(std::__is_nothrow_swappable<nested_container>::value)
244    { l_.swap(nl.l_); }
245
246    void clear() _NOEXCEPT { l_.clear(); }
247
248//     void splice(const_iterator position, list& x);
249//     void splice(const_iterator position, list&& x);
250//     void splice(const_iterator position, list& x, const_iterator i);
251//     void splice(const_iterator position, list&& x, const_iterator i);
252//     void splice(const_iterator position, list& x, const_iterator first,
253//                                                   const_iterator last);
254//     void splice(const_iterator position, list&& x, const_iterator first,
255//                                                   const_iterator last);
256//
257//     void remove(const value_type& value);
258//     template <class Pred> void remove_if(Pred pred);
259//     void unique();
260//     template <class BinaryPredicate>
261//         void unique(BinaryPredicate binary_pred);
262//     void merge(list& x);
263//     void merge(list&& x);
264//     template <class Compare>
265//         void merge(list& x, Compare comp);
266//     template <class Compare>
267//         void merge(list&& x, Compare comp);
268//     void sort();
269//     template <class Compare>
270//         void sort(Compare comp);
271//     void reverse() noexcept;
272
273    nasty_list *operator &()             { return nullptr; }  // nasty
274    const nasty_list *operator &() const { return nullptr; }  // nasty
275
276    nested_container l_;
277};
278
279template <class T>
280bool operator==(const nasty_list<T>& x, const nasty_list<T>& y) { return x.l_ == y.l_; }
281
282#endif
283