3#include "IComparable.h"
19 using StrList = List<std::wstring>;
32 std::shared_ptr<std::vector<T>> _pVec;
39 : _pVec(std::make_shared<std::vector<T>>())
46 List(std::initializer_list<T> list)
47 : _pVec(std::make_shared<std::vector<T>>(list))
54 explicit List(
int capacity)
57 this->_pVec->reserve(capacity);
65 return this->_pVec->begin();
73 return this->_pVec->end();
81 return this->_pVec->rbegin();
89 return this->_pVec->rend();
97 return this->_pVec->at(index);
105 return this->_pVec == other._pVec;
113 return (
int)this->_pVec->capacity();
121 return (
int)this->_pVec->size();
129 return this->_pVec->empty();
138 this->_pVec->push_back(value);
148 this->_pVec->push_back(std::forward<T>(value));
156 auto Insert(
int index,
const T &value)
const
158 this->_pVec->insert(this->_pVec->begin() + index, value);
168 this->_pVec->insert(this->_pVec->begin() + index, std::forward<T>(value));
178 return std::find(this->_pVec->begin(), this->_pVec->end(), value) != this->_pVec->end();
188 auto it = std::find(this->_pVec->begin(), this->_pVec->end(), value);
189 return it == this->_pVec->end() ? -1 : int(it - this->_pVec->begin());
199 auto it = std::find(this->_pVec->begin(), this->_pVec->end(), value);
200 if (it == this->_pVec->end())
202 this->_pVec->erase(it);
212 this->_pVec->erase(this->_pVec->begin() + index);
220 this->_pVec->clear();
228 List list((
int)this->_pVec->capacity());
229 list._pVec->assign(this->_pVec->begin(), this->_pVec->end());
相等性比较接口
Definition IComparable.h:14
为支持ToString方法的类提供统一接口
Definition IToString.h:13
列表类,内部维护了一个指向std::vector的智能指针
Definition List.h:27
auto Insert(int index, const T &value) const
在指定位置插入值
Definition List.h:156
auto begin() const
正向迭代器开始
Definition List.h:63
auto Append(T &&value) const
添加一个值到列表末尾
Definition List.h:146
bool Equals(const List &other) const
判断是否为同一个列表
Definition List.h:103
bool Contains(const T &value) const
列表是否包含某个值
Definition List.h:176
List(int capacity)
初始化列表并指定容量
Definition List.h:54
int IndexOf(const T &value) const
查找值在列表中的索引
Definition List.h:186
auto & operator[](int index) const
获取或设置列表中指定位置的值
Definition List.h:95
auto rbegin() const
反向迭代器开始
Definition List.h:79
void RemoveAt(int index) const
移除指定索引处的值
Definition List.h:210
int Capacity() const
列表当前的容量
Definition List.h:111
List Copy() const
复制当前列表
Definition List.h:226
std::wstring ToString() const
获取描述当前对象的字符串
Definition List.h:244
auto rend() const
反向迭代器结束
Definition List.h:87
auto end() const
正向迭代器结束
Definition List.h:71
void Clear() const
清空列表
Definition List.h:218
List(std::initializer_list< T > list)
使用初始化列表
Definition List.h:46
int Count() const
获取元素个数
Definition List.h:119
std::vector< T > & GetStdVector() const
获取列表内部维护的std::vector
Definition List.h:236
auto Append(const T &value) const
添加一个值到列表末尾
Definition List.h:136
auto Insert(int index, T &&value) const
在指定位置插入值
Definition List.h:166
List()
初始化列表
Definition List.h:38
bool Remove(const T &value) const
移除列表中第一个指定的值
Definition List.h:197
bool IsEmpty() const
列表是否为空
Definition List.h:127
static std::wstring BuildStr(const Args &...args)
拼接字符串,也可使用此函数将其他类型转为wstring
Definition Utils.h:113