7#include <initializer_list>
37 List(std::initializer_list<T> list)
49 _data.reserve(
static_cast<size_t>(
capacity));
66 : _data(std::move(
other._data))
91 _data = std::move(
other._data);
124 return static_cast<int>(_data.capacity());
152 _data.push_back(value);
161 _data.push_back(std::move(value));
172 throw std::out_of_range(
"Index out of range in List::RemoveAt.");
174 _data.erase(_data.begin() +
static_cast<size_t>(index));
186 throw std::out_of_range(
"Index out of range in List::Insert.");
188 _data.insert(_data.begin() +
static_cast<size_t>(index), value);
200 throw std::out_of_range(
"Index out of range in List::Insert.");
202 _data.insert(_data.begin() +
static_cast<size_t>(index), std::move(value));
212 auto it = std::find(_data.begin(), _data.end(), value);
213 return it != _data.end() ?
static_cast<int>(std::distance(_data.begin(),
it)) : -1;
223 auto it = std::find(_data.rbegin(), _data.rend(), value);
224 return it != _data.rend() ?
static_cast<int>(std::distance(
it, _data.rend()) - 1) : -1;
234 return std::find(_data.begin(), _data.end(), value) != _data.end();
287 template <
typename U = T>
288 auto SetAtImpl(
int index,
const T &value)
289 ->
typename std::enable_if<std::is_copy_assignable<U>::value>::type
292 throw std::out_of_range(
"Index out of range in List::SetAt.");
294 _data[
static_cast<size_t>(index)] = value;
303 template <
typename U = T>
304 auto SetAtImpl(
int index,
const T &value)
305 ->
typename std::enable_if<!std::is_copy_assignable<U>::value>::type
307 throw std::logic_error(
"Type T must be copy assignable to use SetAt in List.");
316 template <
typename U = T>
317 auto SetAtImpl(
int index,
T &&value)
318 ->
typename std::enable_if<std::is_move_assignable<U>::value>::type
320 if (index < 0 || index >=
Count()) {
321 throw std::out_of_range(
"Index out of range in List::SetAt.");
323 _data[
static_cast<size_t>(index)] = std::move(value);
332 template <
typename U = T>
333 auto SetAtImpl(
int index,
T &&value)
334 ->
typename std::enable_if<!std::is_move_assignable<U>::value>::type
336 throw std::logic_error(
"Type T must be move assignable to use move SetAt in List.");
346 return static_cast<int>(_data.size());
358 throw std::out_of_range(
"Index out of range in List::GetAt.");
360 return _data[
static_cast<size_t>(index)];
369 virtual const T &
GetAt(
int index)
const override
372 throw std::out_of_range(
"Index out of range in List::GetAt.");
374 return _data[
static_cast<size_t>(index)];
384 virtual void SetAt(
int index,
const T &value)
override
386 SetAtImpl(index, value);
396 virtual void SetAt(
int index,
T &&value)
override
398 SetAtImpl(index, std::move(value));
类型安全的列表接口,继承IList并提供类型化的元素访问
Definition IList.h:71
为支持ToString方法的类提供统一接口
Definition IToString.h:13
值转换器接口
Definition IValueConverter.h:14
基于std::vector的泛型列表,实现IListT接口
Definition List.h:20
void RemoveAt(int index)
移除指定索引处的元素
Definition List.h:169
const T & operator[](int index) const
获取指定索引处的const元素引用
Definition List.h:113
const std::vector< T > & GetInternalVector() const noexcept
获取底层std::vector的const引用
Definition List.h:275
void Reserve(int newCapacity)
预留至少指定数量的元素空间
Definition List.h:131
void Add(const T &value)
在列表末尾追加元素
Definition List.h:150
void Add(T &&value)
在列表末尾追加元素(移动语义)
Definition List.h:159
virtual T & GetAt(int index) override
获取指定索引处的元素引用
Definition List.h:355
virtual int Count() const noexcept override
返回列表中的元素数量
Definition List.h:344
bool Contains(const T &value) const
判断列表是否包含指定值
Definition List.h:232
T & operator[](int index)
获取指定索引处的元素引用
Definition List.h:102
virtual void SetAt(int index, const T &value) override
设置指定索引处的元素值
Definition List.h:384
List(int capacity)
指定初始容量构造
Definition List.h:46
int IndexOf(const T &value) const
查找指定值在列表中首次出现的索引
Definition List.h:210
void Insert(int index, const T &value)
在指定索引处插入元素
Definition List.h:183
List(List< T > &&other) noexcept
移动构造函数
Definition List.h:65
List()=default
默认构造函数,创建空列表
virtual const T & GetAt(int index) const override
获取指定索引处的const元素引用
Definition List.h:369
List< T > & operator=(List< T > &&other) noexcept
移动赋值运算符
Definition List.h:88
int LastIndexOf(const T &value) const
查找指定值在列表中最后出现的索引
Definition List.h:221
std::wstring ToString() const
将列表转换为字符串表示
Definition List.h:257
List(const List< T > &other)
拷贝构造函数
Definition List.h:56
bool Remove(const T &value)
移除列表中首次出现的指定值
Definition List.h:242
List(std::initializer_list< T > list)
使用初始化列表构造
Definition List.h:37
List< T > & operator=(const List< T > &other)
拷贝赋值运算符
Definition List.h:75
int Capacity() const noexcept
获取当前分配的容量
Definition List.h:122
std::vector< T > & GetInternalVector() noexcept
获取底层std::vector的引用
Definition List.h:266
void Insert(int index, T &&value)
在指定索引处插入元素(移动语义)
Definition List.h:197
virtual void SetAt(int index, T &&value) override
设置指定索引处的元素值(移动语义)
Definition List.h:396
void Clear()
清空列表中的所有元素
Definition List.h:141
static std::wstring BuildStr(const Args &...args)
拼接字符串,也可使用此函数将其他类型转为wstring
Definition Utils.h:139
SimpleWindow框架的顶级命名空间,所有公共类型、控件、枚举和工具函数均定义于此。
Definition Alignment.h:4