增加泛型列表,初步测试通过
This commit is contained in:
parent
2323911888
commit
27eaa35ebe
21
Core/List.h
21
Core/List.h
|
@ -9,7 +9,7 @@ class List
|
||||||
public:
|
public:
|
||||||
IComparer Comparer; // 比较器
|
IComparer Comparer; // 比较器
|
||||||
|
|
||||||
explicit List();
|
List();
|
||||||
List(const List& list);
|
List(const List& list);
|
||||||
List(List&& list);
|
List(List&& list);
|
||||||
~List();
|
~List();
|
||||||
|
@ -55,4 +55,23 @@ private:
|
||||||
bool CheckCapacity(int count);
|
bool CheckCapacity(int count);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class TList : public List
|
||||||
|
{
|
||||||
|
static_assert(sizeof(T) <= 4, "TList only support pointer or int");
|
||||||
|
public:
|
||||||
|
// 添加单个元素
|
||||||
|
void Add(T item) { List::Add(item); }
|
||||||
|
|
||||||
|
// 删除指定元素
|
||||||
|
int Remove(const T item) { return List::Remove(item); }
|
||||||
|
|
||||||
|
// 查找指定项。不存在时返回-1
|
||||||
|
int FindIndex(const T item) const { return List::FindIndex(item); }
|
||||||
|
|
||||||
|
// 重载索引运算符[],返回指定元素的第一个
|
||||||
|
T operator[](int i) const { return (T)List::operator[](i); }
|
||||||
|
T& operator[](int i) { return (T&)List::operator[](i); }
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,7 +13,7 @@ void List::Test()
|
||||||
byte buf2[] = {6,7,8,9};
|
byte buf2[] = {6,7,8,9};
|
||||||
byte buf3[] = {10,11,12,13,14,15,16,17,18,19,20};
|
byte buf3[] = {10,11,12,13,14,15,16,17,18,19,20};
|
||||||
|
|
||||||
List list;
|
TList<byte*> list;
|
||||||
list.Add(buf1);
|
list.Add(buf1);
|
||||||
list.Add(buf2);
|
list.Add(buf2);
|
||||||
list.Add(buf3);
|
list.Add(buf3);
|
||||||
|
|
|
@ -887,6 +887,8 @@ namespace NewLife.Reflection
|
||||||
ss.Add("argument is incompatible with corresponding format string conversion", "格式化字符串不兼容参数");
|
ss.Add("argument is incompatible with corresponding format string conversion", "格式化字符串不兼容参数");
|
||||||
ss.Add("no suitable constructor exists to convert from", "没有合适的构造函数去转换");
|
ss.Add("no suitable constructor exists to convert from", "没有合适的构造函数去转换");
|
||||||
ss.Add("nonstandard form for taking the address of a member function", "获取成员函数地址不标准(&Class::Method)");
|
ss.Add("nonstandard form for taking the address of a member function", "获取成员函数地址不标准(&Class::Method)");
|
||||||
|
ss.Add("argument of type", "实参类型");
|
||||||
|
ss.Add("is incompatible with parameter of type", "不兼容形参类型");
|
||||||
}
|
}
|
||||||
|
|
||||||
ss = Words;
|
ss = Words;
|
||||||
|
|
Loading…
Reference in New Issue