| 1 |
/* Copyright (C) 2015 Povilas Kanapickas <[email protected]> |
| 2 |
|
| 3 |
This file is part of cppreference-doc |
| 4 |
|
| 5 |
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 |
| 6 |
Unported License. To view a copy of this license, visit |
| 7 |
http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative |
| 8 |
Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. |
| 9 |
|
| 10 |
Permission is granted to copy, distribute and/or modify this document |
| 11 |
under the terms of the GNU Free Documentation License, Version 1.3 or |
| 12 |
any later version published by the Free Software Foundation; with no |
| 13 |
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. |
| 14 |
*/ |
| 15 |
|
| 16 |
#ifndef CPPREFERENCE_LIST_H |
| 17 |
#define CPPREFERENCE_LIST_H |
| 18 |
|
| 19 |
#if CPPREFERENCE_STDVER>= 2011 |
| 20 |
#include <initializer_list> |
| 21 |
#endif |
| 22 |
|
| 23 |
namespace std { |
| 24 |
|
| 25 |
template<class T, class Allocator = allocator<T>> |
| 26 |
class list { |
| 27 |
public: |
| 28 |
typedef T value_type; |
| 29 |
typedef Allocator allocator_type; |
| 30 |
typedef size_t size_type; // actual type unspecified |
| 31 |
typedef ptrdiff_t difference_type; // actual type not specified |
| 32 |
#if CPPREFERENCE_SIMPLIFY_TYPEDEFS |
| 33 |
typedef T& reference; |
| 34 |
typedef const T& const_reference; |
| 35 |
typedef T* pointer; |
| 36 |
typedef const T* const_pointer; |
| 37 |
#elif CPPREFERENCE_STDVER <2011 |
| 38 |
typedef typename Allocator::reference reference; |
| 39 |
typedef typename Allocator::const_reference const_reference; |
| 40 |
typedef typename Allocator::pointer pointer; |
| 41 |
typedef typename Allocator::const_pointer const_pointer; |
| 42 |
#else |
| 43 |
typedef value_type& reference; |
| 44 |
typedef const value_type& const_reference; |
| 45 |
typedef typename std::allocator_traits<Allocator>::pointer pointer; |
| 46 |
typedef typename std::allocator_traits<Allocator>::const_pointer const_pointer; |
| 47 |
#endif |
| 48 |
typedef T* iterator; // actual type is unspecified |
| 49 |
typedef const T* const_iterator; // actual type is unspecified |
| 50 |
typedef std::reverse_iterator<iterator> reverse_iterator; |
| 51 |
typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 52 |
|
| 53 |
// constructor |
| 54 |
#if CPPREFERENCE_STDVER <2014 |
| 55 |
explicit list(const Allocator& alloc = Allocator()); |
| 56 |
#else |
| 57 |
list(); |
| 58 |
explicit list(const Allocator& alloc); |
| 59 |
#endif |
| 60 |
|
| 61 |
#if CPPREFERENCE_STDVER <2011 |
| 62 |
explicit list(size_type count, |
| 63 |
const T& value = T(), |
| 64 |
const Allocator& alloc = Allocator()); |
| 65 |
#else |
| 66 |
list(size_type count, |
| 67 |
const T& value, |
| 68 |
const Allocator& alloc = Allocator()); |
| 69 |
|
| 70 |
#if CPPREFERENCE_STDVER <2014 |
| 71 |
explicit list(size_type n); |
| 72 |
#else |
| 73 |
explicit list(size_type n, const Allocator& alloc = Allocator()); |
| 74 |
#endif |
| 75 |
|
| 76 |
template<class InputIt> |
| 77 |
list(InputIt first, InputIt last, |
| 78 |
const Allocator& alloc = Allocator()); |
| 79 |
|
| 80 |
list(const list& other); |
| 81 |
#if CPPREFERENCE_STDVER>= 2011 |
| 82 |
list(const list& other, const Allocator& alloc); |
| 83 |
#endif |
| 84 |
|
| 85 |
list(list&& other); |
| 86 |
#if CPPREFERENCE_STDVER>= 2011 |
| 87 |
list(list&& other, const Allocator& alloc); |
| 88 |
|
| 89 |
list(std::initializer_list<T> init, |
| 90 |
const Allocator& alloc = Allocator()); |
| 91 |
#endif |
| 92 |
|
| 93 |
~list(); |
| 94 |
|
| 95 |
list& operator=(const list& other); |
| 96 |
#if CPPREFERENCE_STDVER>= 2011 |
| 97 |
list& operator=(list&& other); |
| 98 |
list& operator=(initializer_list<T> ilist); |
| 99 |
#endif |
| 100 |
|
| 101 |
void assign(size_type count, const value_type& value); |
| 102 |
template <class InputIt> |
| 103 |
void assign(InputIt first, InputIt last); |
| 104 |
#if CPPREFERENCE_STDVER>= 2011 |
| 105 |
void assign(std::initializer_list<T> ilist); |
| 106 |
#endif |
| 107 |
|
| 108 |
allocator_type get_allocator() const; |
| 109 |
|
| 110 |
// element access |
| 111 |
reference front(); |
| 112 |
const_reference front() const; |
| 113 |
reference back(); |
| 114 |
const_reference back() const; |
| 115 |
|
| 116 |
// iterators |
| 117 |
iterator begin(); |
| 118 |
const_iterator begin() const; |
| 119 |
iterator end(); |
| 120 |
const_iterator end() const; |
| 121 |
|
| 122 |
reverse_iterator rbegin(); |
| 123 |
const_reverse_iterator rbegin() const; |
| 124 |
reverse_iterator rend(); |
| 125 |
const_reverse_iterator rend() const; |
| 126 |
|
| 127 |
#if CPPREFERENCE_STDVER>= 2011 |
| 128 |
const_iterator cbegin() const; |
| 129 |
const_iterator cend() const; |
| 130 |
const_reverse_iterator crbegin() const; |
| 131 |
const_reverse_iterator crend() const; |
| 132 |
#endif |
| 133 |
|
| 134 |
bool empty() const; |
| 135 |
size_type size() const; |
| 136 |
size_type max_size() const; |
| 137 |
|
| 138 |
// modifiers |
| 139 |
void clear(); |
| 140 |
|
| 141 |
#if CPPREFERENCE_STDVER <2011 |
| 142 |
iterator insert(iterator pos, const T& value); |
| 143 |
void insert(iterator pos, size_type count, const T& value); |
| 144 |
template<class InputIt> |
| 145 |
void insert(iterator pos, InputIt first, InputIt last); |
| 146 |
#else |
| 147 |
iterator insert(const_iterator pos, const T& value); |
| 148 |
iterator insert(const_iterator pos, T&& value); |
| 149 |
iterator insert(const_iterator pos, size_type count, const T& value); |
| 150 |
template<class InputIt> |
| 151 |
iterator insert(const_iterator pos, InputIt first, InputIt last); |
| 152 |
iterator insert(const_iterator pos, std::initializer_list<T> ilist); |
| 153 |
#endif |
| 154 |
|
| 155 |
#if CPPREFERENCE_STDVER>= 2011 |
| 156 |
template<class... Args> |
| 157 |
iterator emplace(const_iterator pos, Args&& ... args); |
| 158 |
#endif |
| 159 |
|
| 160 |
#if CPPREFERENCE_STDVER <2011 |
| 161 |
iterator erase(iterator pos); |
| 162 |
iterator erase(iterator first, iterator last); |
| 163 |
#else |
| 164 |
iterator erase(const_iterator pos); |
| 165 |
iterator erase(const_iterator first, const_iterator last); |
| 166 |
#endif |
| 167 |
|
| 168 |
void push_back(const T& value); |
| 169 |
#if CPPREFERENCE_STDVER>= 2011 |
| 170 |
void push_back(T&& value); |
| 171 |
#endif |
| 172 |
|
| 173 |
#if CPPREFERENCE_STDVER>= 2011 |
| 174 |
template<class... Args> |
| 175 |
void emplace_back(Args&& ... args); |
| 176 |
#endif |
| 177 |
|
| 178 |
void pop_back(); |
| 179 |
|
| 180 |
void push_front(const T& value); |
| 181 |
#if CPPREFERENCE_STDVER>= 2011 |
| 182 |
void push_front(T&& value); |
| 183 |
#endif |
| 184 |
|
| 185 |
#if CPPREFERENCE_STDVER>= 2011 |
| 186 |
template<class... Args> |
| 187 |
void emplace_front(Args&& ... args); |
| 188 |
#endif |
| 189 |
|
| 190 |
void pop_front(); |
| 191 |
|
| 192 |
#if CPPREFERENCE_STDVER <2011 |
| 193 |
void resize(size_type count, T value = T()); |
| 194 |
#else |
| 195 |
void resize(size_type count); |
| 196 |
void resize(size_type count, const value_type& value); |
| 197 |
#endif |
| 198 |
|
| 199 |
void swap(list& other); |
| 200 |
|
| 201 |
// operations |
| 202 |
void merge(list& other); |
| 203 |
|
| 204 |
#if CPPREFERENCE_STDVER>= 2011 |
| 205 |
void merge(list&& other); |
| 206 |
#endif |
| 207 |
|
| 208 |
template <class Compare> |
| 209 |
void merge(list& other, Compare comp); |
| 210 |
|
| 211 |
#if CPPREFERENCE_STDVER>= 2011 |
| 212 |
template <class Compare> |
| 213 |
void merge(list&& other, Compare comp); |
| 214 |
#endif |
| 215 |
|
| 216 |
void splice(const_iterator pos, list& other); |
| 217 |
void splice(const_iterator pos, list& other, const_iterator it); |
| 218 |
void splice(const_iterator pos, list& other, |
| 219 |
const_iterator first, const_iterator last); |
| 220 |
#if CPPREFERENCE_STDVER>= 2011 |
| 221 |
void splice(const_iterator pos, list&& other); |
| 222 |
void splice(const_iterator pos, list&& other, const_iterator it); |
| 223 |
void splice(const_iterator pos, list&& other, |
| 224 |
const_iterator first, const_iterator last); |
| 225 |
#endif |
| 226 |
|
| 227 |
void remove(const T& value); |
| 228 |
|
| 229 |
template<class UnaryPredicate> |
| 230 |
void remove_if(UnaryPredicate p); |
| 231 |
|
| 232 |
void reverse(); |
| 233 |
|
| 234 |
void unique(); |
| 235 |
|
| 236 |
template<class BinaryPredicate> |
| 237 |
void unique(BinaryPredicate p); |
| 238 |
|
| 239 |
void sort(); |
| 240 |
|
| 241 |
template<class Compare> |
| 242 |
void sort(Compare comp); |
| 243 |
}; |
| 244 |
|
| 245 |
template<class T, class Alloc> |
| 246 |
bool operator==(const list<T, Alloc>& lhs, |
| 247 |
const list<T, Alloc>& rhs); |
| 248 |
|
| 249 |
template<class T, class Alloc> |
| 250 |
bool operator!=(const list<T, Alloc>& lhs, |
| 251 |
const list<T, Alloc>& rhs); |
| 252 |
|
| 253 |
template<class T, class Alloc> |
| 254 |
bool operator<(const list<T, Alloc>& lhs, |
| 255 |
const list<T, Alloc>& rhs); |
| 256 |
|
| 257 |
template<class T, class Alloc> |
| 258 |
bool operator<=(const list<T, Alloc>& lhs, |
| 259 |
const list<T, Alloc>& rhs); |
| 260 |
|
| 261 |
template<class T, class Alloc> |
| 262 |
bool operator>(const list<T, Alloc>& lhs, |
| 263 |
const list<T, Alloc>& rhs); |
| 264 |
|
| 265 |
template<class T, class Alloc> |
| 266 |
bool operator>=(const list<T, Alloc>& lhs, |
| 267 |
const list<T, Alloc>& rhs); |
| 268 |
|
| 269 |
} // namespace std |
| 270 |
|
| 271 |
#endif // CPPREFERENCE_LIST_H |