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 
16 template <class T>
17 class nasty_vector
18 {
19 public:
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 
nasty_vector()35     nasty_vector() : v_() {}
nasty_vector(size_type n)36     explicit nasty_vector(size_type n) : v_(n) {}
nasty_vector(size_type n,const value_type & value)37     nasty_vector(size_type n, const value_type& value) : v_(n, value) {}
nasty_vector(InputIterator first,InputIterator last)38     template <class InputIterator> nasty_vector(InputIterator first, InputIterator last) : v_(first, last) {}
39 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
nasty_vector(std::initializer_list<value_type> il)40     nasty_vector(std::initializer_list<value_type> il) : v_(il) {}
41 #endif
~nasty_vector()42     ~nasty_vector() {}
43 
44     template <class InputIterator>
assign(InputIterator first,InputIterator last)45         void assign(InputIterator first, InputIterator last) { v_.assign(first, last); }
assign(size_type n,const value_type & u)46     void assign(size_type n, const value_type& u) { v_.assign(n, u); }
47 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
assign(std::initializer_list<value_type> il)48     void assign(std::initializer_list<value_type> il)  { v_.assign(il); }
49 #endif
50 
begin()51     iterator               begin() _NOEXCEPT         { return v_.begin(); }
begin() const52     const_iterator         begin()   const _NOEXCEPT { return v_.begin(); }
end()53     iterator               end() _NOEXCEPT           { return v_.end(); }
end() const54     const_iterator         end()     const _NOEXCEPT { return v_.end(); }
55 
rbegin()56     reverse_iterator       rbegin() _NOEXCEPT        { return v_.rbegin(); }
rbegin() const57     const_reverse_iterator rbegin()  const _NOEXCEPT { return v_.rbegin(); }
rend()58     reverse_iterator       rend() _NOEXCEPT          { return v_.rend(); }
rend() const59     const_reverse_iterator rend()    const _NOEXCEPT { return v_.rend(); }
60 
cbegin() const61     const_iterator         cbegin()  const _NOEXCEPT { return v_.cbegin(); }
cend() const62     const_iterator         cend()    const _NOEXCEPT { return v_.cend(); }
crbegin() const63     const_reverse_iterator crbegin() const _NOEXCEPT { return v_.crbegin(); }
crend() const64     const_reverse_iterator crend()   const _NOEXCEPT { return v_.crend(); }
65 
size() const66     size_type size() const _NOEXCEPT      { return v_.size(); }
max_size() const67     size_type max_size() const _NOEXCEPT  { return v_.max_size(); }
capacity() const68     size_type capacity() const _NOEXCEPT  { return v_.capacity(); }
empty() const69     bool empty() const _NOEXCEPT          { return v_.empty(); }
reserve(size_type n)70     void reserve(size_type n)             { v_.reserve(n); };
shrink_to_fit()71     void shrink_to_fit() _NOEXCEPT        { v_.shrink_to_fit(); }
72 
operator [](size_type n)73     reference       operator[](size_type n)       { return v_[n]; }
operator [](size_type n) const74     const_reference operator[](size_type n) const { return v_[n]; }
at(size_type n)75     reference       at(size_type n)               { return v_.at(n); }
at(size_type n) const76     const_reference at(size_type n) const         { return v_.at(n); }
77 
front()78     reference       front()       { return v_.front(); }
front() const79     const_reference front() const { return v_.front(); }
back()80     reference       back()        { return v_.back(); }
back() const81     const_reference back() const  { return v_.back(); }
82 
data()83     value_type*       data() _NOEXCEPT       { return v_.data(); }
data() const84     const value_type* data() const _NOEXCEPT { return v_.data(); }
85 
push_back(const value_type & x)86     void push_back(const value_type& x)     { v_.push_back(x); }
87 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
push_back(value_type && x)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>
emplace_back(Args &&...args)91         void emplace_back(Args&&... args)   { v_.emplace_back(std::forward<Args>(args)...); }
92 #endif
93 #endif
pop_back()94     void pop_back()                         { v_.pop_back(); }
95 
96 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
97 #ifndef _LIBCPP_HAS_NO_VARIADICS
emplace(const_iterator pos,Args &&...args)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 
insert(const_iterator pos,const value_type & x)103     iterator insert(const_iterator pos, const value_type& x) { return v_.insert(pos, x); }
104 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
insert(const_iterator pos,value_type && x)105     iterator insert(const_iterator pos, value_type&& x)      { return v_.insert(pos, std::forward<value_type>(x)); }
106 #endif
insert(const_iterator pos,size_type n,const value_type & x)107     iterator insert(const_iterator pos, size_type n, const value_type& x) { return v_.insert(pos, n, x); }
108     template <class InputIterator>
insert(const_iterator pos,InputIterator first,InputIterator last)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
insert(const_iterator pos,std::initializer_list<value_type> il)113     iterator insert(const_iterator pos, std::initializer_list<value_type> il) { return v_.insert(pos, il); }
114 #endif
115 
erase(const_iterator pos)116     iterator erase(const_iterator pos)                        { return v_.erase(pos); }
erase(const_iterator first,const_iterator last)117     iterator erase(const_iterator first, const_iterator last) { return v_.erase(first, last); }
118 
clear()119     void clear() _NOEXCEPT { v_.clear(); }
120 
resize(size_type sz)121     void resize(size_type sz)                      { v_.resize(sz); }
resize(size_type sz,const value_type & c)122     void resize(size_type sz, const value_type& c) { v_.resize(sz, c); }
123 
swap(nasty_vector & nv)124     void swap(nasty_vector &nv) _NOEXCEPT_(std::__is_nothrow_swappable<nested_container>::value)
125     { v_.swap(nv.v_); }
126 
operator &()127     nasty_vector *operator &()             { return nullptr; }  // nasty
operator &() const128     const nasty_vector *operator &() const { return nullptr; }  // nasty
129 
130     nested_container v_;
131 };
132 
133 template <class T>
operator ==(const nasty_vector<T> & x,const nasty_vector<T> & y)134 bool operator==(const nasty_vector<T>& x, const nasty_vector<T>& y) { return x.v_ == y.v_; }
135 
136 template <class T>
137 class nasty_list
138 {
139 public:
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 
nasty_list()156     nasty_list() : l_() {}
nasty_list(size_type n)157     explicit nasty_list(size_type n)  : l_(n) {}
nasty_list(size_type n,const value_type & value)158     nasty_list(size_type n, const value_type& value)  : l_(n,value) {}
159     template <class Iter>
nasty_list(Iter first,Iter last)160         nasty_list(Iter first, Iter last)  : l_(first, last) {}
161 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
nasty_list(std::initializer_list<value_type> il)162     nasty_list(std::initializer_list<value_type> il) : l_(il) {}
163 #endif
164 
~nasty_list()165     ~nasty_list() {}
166 
167 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
operator =(std::initializer_list<value_type> il)168     nasty_list& operator=(std::initializer_list<value_type> il) { l_ = il; return *this; }
169 #endif
170     template <class Iter>
assign(Iter first,Iter last)171         void assign(Iter first, Iter last) { l_.assign(first, last); }
assign(size_type n,const value_type & t)172     void assign(size_type n, const value_type& t) { l_.assign(n, t); }
173 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
assign(std::initializer_list<value_type> il)174     void assign(std::initializer_list<value_type> il) { l_.assign(il); }
175 #endif
176 
177 
begin()178     iterator               begin() _NOEXCEPT         { return l_.begin(); }
begin() const179     const_iterator         begin()   const _NOEXCEPT { return l_.begin(); }
end()180     iterator               end() _NOEXCEPT           { return l_.end(); }
end() const181     const_iterator         end()     const _NOEXCEPT { return l_.end(); }
182 
rbegin()183     reverse_iterator       rbegin() _NOEXCEPT        { return l_.rbegin(); }
rbegin() const184     const_reverse_iterator rbegin()  const _NOEXCEPT { return l_.rbegin(); }
rend()185     reverse_iterator       rend() _NOEXCEPT          { return l_.rend(); }
rend() const186     const_reverse_iterator rend()    const _NOEXCEPT { return l_.rend(); }
187 
cbegin() const188     const_iterator         cbegin()  const _NOEXCEPT { return l_.cbegin(); }
cend() const189     const_iterator         cend()    const _NOEXCEPT { return l_.cend(); }
crbegin() const190     const_reverse_iterator crbegin() const _NOEXCEPT { return l_.crbegin(); }
crend() const191     const_reverse_iterator crend()   const _NOEXCEPT { return l_.crend(); }
192 
front()193     reference       front()       { return l_.front(); }
front() const194     const_reference front() const { return l_.front(); }
back()195     reference       back()        { return l_.back(); }
back() const196     const_reference back() const  { return l_.back(); }
197 
size() const198     size_type size() const _NOEXCEPT      { return l_.size(); }
max_size() const199     size_type max_size() const _NOEXCEPT  { return l_.max_size(); }
empty() const200     bool empty() const _NOEXCEPT          { return l_.empty(); }
201 
push_front(const value_type & x)202     void push_front(const value_type& x)    { l_.push_front(x); }
push_back(const value_type & x)203     void push_back(const value_type& x)     { l_.push_back(x); }
204 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
push_back(value_type && x)205     void push_back(value_type&& x)          { l_.push_back(std::forward<value_type&&>(x)); }
push_front(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>
emplace_back(Args &&...args)209         void emplace_back(Args&&... args)   { l_.emplace_back(std::forward<Args>(args)...); }
210     template <class... Args>
emplace_front(Args &&...args)211         void emplace_front(Args&&... args)  { l_.emplace_front(std::forward<Args>(args)...); }
212 #endif
213 #endif
pop_front()214     void pop_front()                        { l_.pop_front(); }
pop_back()215     void pop_back()                         { l_.pop_back(); }
216 
217 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
218 #ifndef _LIBCPP_HAS_NO_VARIADICS
emplace(const_iterator pos,Args &&...args)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 
insert(const_iterator pos,const value_type & x)224     iterator insert(const_iterator pos, const value_type& x) { return l_.insert(pos, x); }
225 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
insert(const_iterator pos,value_type && x)226     iterator insert(const_iterator pos, value_type&& x)      { return l_.insert(pos, std::forward<value_type>(x)); }
227 #endif
insert(const_iterator pos,size_type n,const value_type & x)228     iterator insert(const_iterator pos, size_type n, const value_type& x) { return l_.insert(pos, n, x); }
229     template <class InputIterator>
insert(const_iterator pos,InputIterator first,InputIterator last)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
insert(const_iterator pos,std::initializer_list<value_type> il)234     iterator insert(const_iterator pos, std::initializer_list<value_type> il) { return l_.insert(pos, il); }
235 #endif
236 
erase(const_iterator pos)237     iterator erase(const_iterator pos)                      { return l_.erase(pos); }
erase(const_iterator pos,const_iterator last)238     iterator erase(const_iterator pos, const_iterator last) { return l_.erase(pos, last); }
239 
resize(size_type sz)240     void resize(size_type sz)                      { l_.resize(); }
resize(size_type sz,const value_type & c)241     void resize(size_type sz, const value_type& c) { l_.resize(c); }
242 
swap(nasty_list & nl)243     void swap(nasty_list &nl) _NOEXCEPT_(std::__is_nothrow_swappable<nested_container>::value)
244     { l_.swap(nl.l_); }
245 
clear()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 
operator &()273     nasty_list *operator &()             { return nullptr; }  // nasty
operator &() const274     const nasty_list *operator &() const { return nullptr; }  // nasty
275 
276     nested_container l_;
277 };
278 
279 template <class T>
operator ==(const nasty_list<T> & x,const nasty_list<T> & y)280 bool operator==(const nasty_list<T>& x, const nasty_list<T>& y) { return x.l_ == y.l_; }
281 
282 #endif
283