代码拉取完成,页面将自动刷新
#pragma once
#include <windows.h>
#include <vector>
#include <helper.h>
template <typename T, class _Alloc = std::allocator<T>>
class List : public std::vector<T, _Alloc>
{
public:
List() {}
List(T *val, int len)
{
for (int i = 0; i < len; i++)
{
this->push_back(val[i]);
}
}
List(std::initializer_list<T> val)
{
for (int i = 0; i < val.size(); i++)
{
this->push_back(val.begin()[i]);
}
}
List(std::vector<T> val)
{
for (int i = 0; i < val.size(); i++)
{
this->push_back(val[i]);
}
}
~List() {}
T &operator[](int index)
{
return this->data()[index];
}
PROPERTY(int, Count);
GET(int, Count)
{
return this->size();
}
SET(int, Count)
{
this->resize(value);
}
void Add(T val)
{
this->push_back(val);
}
void Clear()
{
this->clear();
}
void AddRange(T *val, int len)
{
int ldx = this->Count;
this->resize(this->size() + len);
memcpy(&this->operator[](ldx), &val[0], sizeof(T) * len);
}
void AddRange(std::initializer_list<T> val)
{
int ldx = this->Count;
this->resize(this->size() + val.size());
memcpy(&this->data()[ldx], &val.begin()[0], sizeof(T) * val.size());
}
void AddRange(List<T> &val)
{
int ldx = this->Count;
this->resize(this->size() + val.size());
memcpy(&this->data()[ldx], &val[0], sizeof(T) * val.size());
}
void AddRange(List<T> *val)
{
int ldx = this->Count;
this->resize(this->size() + val->size());
memcpy(&this->data()[ldx], &val->data()[0], sizeof(T) * val->size());
}
void AddRange(std::vector<T> &val)
{
int ldx = this->Count;
this->resize(this->size() + val.size());
memcpy(&this->data()[ldx], &val[0], sizeof(T) * val.size());
}
void AddRange(std::vector<T> *val)
{
int ldx = this->Count;
this->resize(this->size() + val->size());
memcpy(&this->data()[ldx], &val->data()[0], sizeof(T) * val->size());
}
void Insert(int index, T val)
{
if (index >= this->size())
{
this->push_back(val);
}
else if (index >= 0)
{
this->insert(this->begin() + index, val);
}
}
void Insert(int index, std::initializer_list<T> &val)
{
if (index >= this->size())
{
this->AddRange(val);
}
else if (index >= 0)
{
this->insert(this->begin() + index, val.begin(), val.end() - 1);
}
}
void Insert(int index, std::vector<T> &val)
{
if (index >= this->size())
{
this->AddRange(val);
}
else if (index >= 0)
{
this->insert(this->begin() + index, val.begin(), val.end() - 1);
}
}
void Insert(int index, std::vector<T> *val)
{
if (index >= this->size())
{
this->AddRange(val);
}
else if (index >= 0)
{
this->insert(this->begin() + index, val->begin(), val->end() - 1);
}
}
void Insert(int index, List<T> &val)
{
if (index >= this->size())
{
this->AddRange(val);
}
else if (index >= 0)
{
this->insert(this->begin() + index, val.begin(), val.end() - 1);
}
}
void Insert(int index, List<T> *val)
{
if (index >= this->size())
{
this->AddRange(val);
}
else if (index >= 0)
{
this->insert(this->begin() + index, val->begin(), val->end() - 1);
}
}
void RemoveAt(int index)
{
if (index >= 0 && index < this->size())
{
this->erase(this->begin() + index);
}
}
int IndexOf(T &value)
{
for (int i = 0; i < this->Count; i++)
{
if (this->at(i) == value)
{
return i;
}
}
return -1;
}
bool Contains(T &value)
{
return IndexOf(value) >= 0;
}
int LastIndexOf(T &value)
{
for (int i = this->Count - 1; i >= 0; i--)
{
if (this->at(i) == value)
{
return i;
}
}
return -1;
}
int Remove(T item)
{
int num = 0;
for (int i = this->Count; i >= 0; i--)
{
if (this->data()[i] == item)
{
RemoveAt(i);
num += 1;
}
}
return num;
}
std::vector<T> &GetVector()
{
return *(std::vector<T> *)this;
}
T *Pointer()
{
return this->data();
}
T &get(int i)
{
return this->data()[i];
}
void set(int i, T val)
{
this->data()[i] = val;
}
T &First()
{
return this->data()[0];
}
T &Last()
{
return this->data()[this->size() - 1];
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。