SimpleWindow
载入中...
搜索中...
未找到
sw::List< T > 模板类 参考final

基于std::vector的泛型列表,实现IListT接口 更多...

#include <List.h>

类 sw::List< T > 继承关系图:
sw::IListT< T > sw::IToString< List< T > > sw::IList

Public 成员函数

 List ()=default
 默认构造函数,创建空列表
 
 List (std::initializer_list< T > list)
 使用初始化列表构造
 
 List (int capacity)
 指定初始容量构造
 
 List (const List< T > &other)
 拷贝构造函数
 
 List (List< T > &&other) noexcept
 移动构造函数
 
List< T > & operator= (const List< T > &other)
 拷贝赋值运算符
 
List< T > & operator= (List< T > &&other) noexcept
 移动赋值运算符
 
Toperator[] (int index)
 获取指定索引处的元素引用
 
const Toperator[] (int index) const
 获取指定索引处的const元素引用
 
int Capacity () const noexcept
 获取当前分配的容量
 
void Reserve (int newCapacity)
 预留至少指定数量的元素空间
 
void Clear ()
 清空列表中的所有元素
 
void Add (const T &value)
 在列表末尾追加元素
 
void Add (T &&value)
 在列表末尾追加元素(移动语义)
 
void RemoveAt (int index)
 移除指定索引处的元素
 
void Insert (int index, const T &value)
 在指定索引处插入元素
 
void Insert (int index, T &&value)
 在指定索引处插入元素(移动语义)
 
int IndexOf (const T &value) const
 查找指定值在列表中首次出现的索引
 
int LastIndexOf (const T &value) const
 查找指定值在列表中最后出现的索引
 
bool Contains (const T &value) const
 判断列表是否包含指定值
 
bool Remove (const T &value)
 移除列表中首次出现的指定值
 
std::wstring ToString () const
 将列表转换为字符串表示
 
std::vector< T > & GetInternalVector () noexcept
 获取底层std::vector的引用
 
const std::vector< T > & GetInternalVector () const noexcept
 获取底层std::vector的const引用
 
virtual int Count () const noexcept override
 返回列表中的元素数量
 
virtual TGetAt (int index) override
 获取指定索引处的元素引用
 
virtual const TGetAt (int index) const override
 获取指定索引处的const元素引用
 
virtual void SetAt (int index, const T &value) override
 设置指定索引处的元素值
 
virtual void SetAt (int index, T &&value) override
 设置指定索引处的元素值(移动语义)
 
- Public 成员函数 继承自 sw::IListT< T >
virtual ~IListT ()=default
 虚析构函数
 
virtual std::type_index GetElementType () const noexcept override final
 获取列表元素的类型信息
 
virtual Variant GetVariantAt (int index) override final
 获取指定索引处元素的Variant引用
 
virtual Variant GetVariantAt (int index) const override final
 获取指定索引处元素的Variant副本
 
virtual void SetVariantAt (int index, const Variant &value) override final
 设置指定索引处的元素值
 
virtual void MoveVariantAt (int index, Variant &value) override final
 设置指定索引处的元素值(移动语义)
 
- Public 成员函数 继承自 sw::IList
virtual ~IList ()=default
 虚析构函数
 
- Public 成员函数 继承自 sw::IToString< List< T > >
std::wstring ToString () const
 获取描述当前对象的字符串
 

详细描述

template<typename T>
class sw::List< T >

基于std::vector的泛型列表,实现IListT接口

模板参数
T列表元素类型

构造及析构函数说明

◆ List() [1/4]

template<typename T >
sw::List< T >::List ( std::initializer_list< T list)
inline

使用初始化列表构造

参数
list初始化元素列表

◆ List() [2/4]

template<typename T >
sw::List< T >::List ( int  capacity)
inlineexplicit

指定初始容量构造

参数
capacity初始容量

◆ List() [3/4]

template<typename T >
sw::List< T >::List ( const List< T > &  other)
inline

拷贝构造函数

参数
other源列表

◆ List() [4/4]

template<typename T >
sw::List< T >::List ( List< T > &&  other)
inlinenoexcept

移动构造函数

参数
other源列表

成员函数说明

◆ Add() [1/2]

template<typename T >
void sw::List< T >::Add ( const T value)
inline

在列表末尾追加元素

参数
value要追加的值

◆ Add() [2/2]

template<typename T >
void sw::List< T >::Add ( T &&  value)
inline

在列表末尾追加元素(移动语义)

参数
value要追加的值

◆ Capacity()

template<typename T >
int sw::List< T >::Capacity ( ) const
inlinenoexcept

获取当前分配的容量

返回
容量大小

◆ Contains()

template<typename T >
bool sw::List< T >::Contains ( const T value) const
inline

判断列表是否包含指定值

参数
value要查找的值
返回
包含返回true,否则返回false

◆ Count()

template<typename T >
virtual int sw::List< T >::Count ( ) const
inlineoverridevirtualnoexcept

返回列表中的元素数量

返回
元素数量

实现了 sw::IListT< T >.

◆ GetAt() [1/2]

template<typename T >
virtual const T & sw::List< T >::GetAt ( int  index) const
inlineoverridevirtual

获取指定索引处的const元素引用

参数
index元素索引
返回
const元素引用
异常
std::out_of_range索引超出范围

实现了 sw::IListT< T >.

◆ GetAt() [2/2]

template<typename T >
virtual T & sw::List< T >::GetAt ( int  index)
inlineoverridevirtual

获取指定索引处的元素引用

参数
index元素索引
返回
元素引用
异常
std::out_of_range索引超出范围

实现了 sw::IListT< T >.

◆ GetInternalVector() [1/2]

template<typename T >
const std::vector< T > & sw::List< T >::GetInternalVector ( ) const
inlinenoexcept

获取底层std::vector的const引用

返回
std::vector的const引用

◆ GetInternalVector() [2/2]

template<typename T >
std::vector< T > & sw::List< T >::GetInternalVector ( )
inlinenoexcept

获取底层std::vector的引用

返回
std::vector的引用

◆ IndexOf()

template<typename T >
int sw::List< T >::IndexOf ( const T value) const
inline

查找指定值在列表中首次出现的索引

参数
value要查找的值
返回
首次出现的索引,未找到返回-1

◆ Insert() [1/2]

template<typename T >
void sw::List< T >::Insert ( int  index,
const T value 
)
inline

在指定索引处插入元素

参数
index插入位置
value要插入的值
异常
std::out_of_range索引超出范围

◆ Insert() [2/2]

template<typename T >
void sw::List< T >::Insert ( int  index,
T &&  value 
)
inline

在指定索引处插入元素(移动语义)

参数
index插入位置
value要插入的值
异常
std::out_of_range索引超出范围

◆ LastIndexOf()

template<typename T >
int sw::List< T >::LastIndexOf ( const T value) const
inline

查找指定值在列表中最后出现的索引

参数
value要查找的值
返回
最后出现的索引,未找到返回-1

◆ operator=() [1/2]

template<typename T >
List< T > & sw::List< T >::operator= ( const List< T > &  other)
inline

拷贝赋值运算符

参数
other源列表
返回
当前列表的引用

◆ operator=() [2/2]

template<typename T >
List< T > & sw::List< T >::operator= ( List< T > &&  other)
inlinenoexcept

移动赋值运算符

参数
other源列表
返回
当前列表的引用

◆ operator[]() [1/2]

template<typename T >
T & sw::List< T >::operator[] ( int  index)
inline

获取指定索引处的元素引用

参数
index元素索引
返回
元素引用
异常
std::out_of_range索引超出范围

◆ operator[]() [2/2]

template<typename T >
const T & sw::List< T >::operator[] ( int  index) const
inline

获取指定索引处的const元素引用

参数
index元素索引
返回
const元素引用
异常
std::out_of_range索引超出范围

◆ Remove()

template<typename T >
bool sw::List< T >::Remove ( const T value)
inline

移除列表中首次出现的指定值

参数
value要移除的值
返回
成功移除返回true,未找到返回false

◆ RemoveAt()

template<typename T >
void sw::List< T >::RemoveAt ( int  index)
inline

移除指定索引处的元素

参数
index要移除的元素索引
异常
std::out_of_range索引超出范围

◆ Reserve()

template<typename T >
void sw::List< T >::Reserve ( int  newCapacity)
inline

预留至少指定数量的元素空间

参数
newCapacity要预留的容量,仅在大于当前容量时生效

◆ SetAt() [1/2]

template<typename T >
virtual void sw::List< T >::SetAt ( int  index,
const T value 
)
inlineoverridevirtual

设置指定索引处的元素值

参数
index元素索引
value要设置的值
异常
std::out_of_range索引超出范围
std::logic_errorT不可拷贝赋值时

实现了 sw::IListT< T >.

◆ SetAt() [2/2]

template<typename T >
virtual void sw::List< T >::SetAt ( int  index,
T &&  value 
)
inlineoverridevirtual

设置指定索引处的元素值(移动语义)

参数
index元素索引
value要设置的值
异常
std::out_of_range索引超出范围
std::logic_errorT不可移动赋值时

实现了 sw::IListT< T >.

◆ ToString()

template<typename T >
std::wstring sw::List< T >::ToString ( ) const
inline

将列表转换为字符串表示

返回
列表的字符串表示

该类的文档由以下文件生成: