*添加array2

This commit is contained in:
2023-07-14 18:49:19 +08:00
parent 32f55f3820
commit 73979c2fde
2 changed files with 77 additions and 1 deletions
+76
View File
@@ -0,0 +1,76 @@
/**
* @file dl_array2.h
* @brief 2维array
*
*
* @version 1.0
* @author lveyou
* @date 23-07-09
*
* @note 提供行指针,避免乘法计算
* @note 设计为深拷贝,与std::array一致
*/
#pragma once
namespace dl
{
template<typename T, size_t W, size_t H>
class Array2
{
public:
/**
* @brief 填充值
*/
void Fill(const T& v)
{
for (auto& iter : _data)
iter = v;
}
std::byte* GetBuffer()
{
return (std::byte*)_data.data();
}
T* GetData()
{
return _data.data();
}
unsigned GetWidth()
{
return (unsigned)W;
}
unsigned GetHeight()
{
return (unsigned)H;
}
Size GetSize()
{
return { (unsigned)W, (unsigned)H };
}
size_t GetSizeByte()
{
return _data.size() * sizeof(T);
}
auto begin()
{
return _data.begin();
}
auto end()
{
return _data.end();
}
private:
std::array<T, W * H> _data;
std::array<T*, H> _ptrRow;
};
}
+1 -1
View File
@@ -34,7 +34,7 @@ consteval bool is_x64()
return sizeof(void*) == 8;
}
//! 是否小端
//! 字节序是否小端
consteval bool is_little_endian()
{
union