DAWorkbench 0.0.1
DAWorkbench API
载入中...
搜索中...
未找到
DA::da_array_table< T, RowN, ColN > 模板类 参考

基于 std::array 的固定大小二维表格数据结构 更多...

#include <da_array_table.hpp>

Public 类型

using value_type = T
 
using row_type = std::array< T, ColN >
 
using table_index_type = std::pair< std::size_t, std::size_t >
 
using iterator = typename std::array< row_type, RowN >::iterator
 
using const_iterator = typename std::array< row_type, RowN >::const_iterator
 
using reverse_iterator = typename std::array< row_type, RowN >::reverse_iterator
 
using const_reverse_iterator = typename std::array< row_type, RowN >::const_reverse_iterator
 
using size_type = typename std::array< row_type, RowN >::size_type
 

Public 成员函数

 da_array_table ()
 默认构造函数
 
T & operator() (std::size_t row, std::size_t col)
 函数调用运算符访问元素
 
const T & operator() (std::size_t row, std::size_t col) const
 函数调用运算符访问元素(常量版本)
 
T & at (std::size_t row, std::size_t col)
 带边界检查的元素访问
 
const T & at (std::size_t row, std::size_t col) const
 带边界检查的元素访问(常量版本)
 
iterator begin () noexcept
 返回指向起始的迭代器
 
const_iterator begin () const noexcept
 返回指向起始的常量迭代器
 
const_iterator cbegin () const noexcept
 返回指向起始的常量迭代器
 
iterator end () noexcept
 返回指向末尾的迭代器
 
const_iterator end () const noexcept
 返回指向末尾的常量迭代器
 
const_iterator cend () const noexcept
 返回指向末尾的常量迭代器
 
reverse_iterator rbegin () noexcept
 返回指向起始的反向迭代器
 
const_reverse_iterator rbegin () const noexcept
 返回指向起始的常量反向迭代器
 
const_reverse_iterator crbegin () const noexcept
 返回指向起始的常量反向迭代器
 
reverse_iterator rend () noexcept
 返回指向末尾的反向迭代器
 
const_reverse_iterator rend () const noexcept
 返回指向末尾的常量反向迭代器
 
const_reverse_iterator crend () const noexcept
 返回指向末尾的常量反向迭代器
 
bool empty () const noexcept
 检查表格是否为空
 
size_type size () const noexcept
 返回元素数量
 
size_type max_size () const noexcept
 返回最大可能元素数量
 
table_index_type shape () const
 获取表格形状
 
std::size_t row_count () const
 获取行数
 
std::size_t column_count () const
 获取列数
 
void fill (const T &value)
 填充表格
 
void swap (da_array_table &other) noexcept
 交换两个表格的内容
 

详细描述

template<typename T, std::size_t RowN, std::size_t ColN>
class DA::da_array_table< T, RowN, ColN >

基于 std::array 的固定大小二维表格数据结构

此类提供了一个固定大小的二维表格数据结构,使用嵌套的 std::array 存储数据, 适合存储固定大小的二维数据,提供高效的随机访问性能。

模板参数
T存储的值类型
RowN行数
ColN列数

构造及析构函数说明

◆ da_array_table()

template<typename T , std::size_t RowN, std::size_t ColN>
DA::da_array_table< T, RowN, ColN >::da_array_table ( )

默认构造函数

模板参数
T存储的值类型
RowN行数
ColN列数
DA::da_array_table<int, 3, 4> table; // 创建3行4列的表格
基于 std::array 的固定大小二维表格数据结构
Definition da_array_table.hpp:22

成员函数说明

◆ at() [1/2]

template<typename T , std::size_t RowN, std::size_t ColN>
T & DA::da_array_table< T, RowN, ColN >::at ( std::size_t  row,
std::size_t  col 
)

带边界检查的元素访问

模板参数
T存储的值类型
RowN行数
ColN列数
参数
row行索引
col列索引
返回
元素的引用
异常
std::out_of_range如果索引超出范围
try {
T& value = table.at(0, 0); // 正常访问
T& invalid = table.at(5, 5); // 抛出std::out_of_range
} catch (const std::out_of_range& e) {
// 处理异常
}
T & at(std::size_t row, std::size_t col)
带边界检查的元素访问
Definition da_array_table.hpp:158

◆ at() [2/2]

template<typename T , std::size_t RowN, std::size_t ColN>
const T & DA::da_array_table< T, RowN, ColN >::at ( std::size_t  row,
std::size_t  col 
) const

带边界检查的元素访问(常量版本)

模板参数
T存储的值类型
RowN行数
ColN列数
参数
row行索引
col列索引
返回
元素的常量引用
异常
std::out_of_range如果索引超出范围
try {
const T& value = table.at(0, 0); // 正常访问
const T& invalid = table.at(5, 5); // 抛出std::out_of_range
} catch (const std::out_of_range& e) {
// 处理异常
}

◆ begin() [1/2]

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::const_iterator DA::da_array_table< T, RowN, ColN >::begin ( ) const
noexcept

返回指向起始的常量迭代器

模板参数
T存储的值类型
RowN行数
ColN列数
返回
指向表格起始的常量迭代器
for (auto it = table.begin(); it != table.end(); ++it) {
for (const auto& element : *it) {
// 处理元素
}
}
iterator begin() noexcept
返回指向起始的迭代器
Definition da_array_table.hpp:212
iterator end() noexcept
返回指向末尾的迭代器
Definition da_array_table.hpp:276

◆ begin() [2/2]

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::iterator DA::da_array_table< T, RowN, ColN >::begin ( )
noexcept

返回指向起始的迭代器

模板参数
T存储的值类型
RowN行数
ColN列数
返回
指向表格起始的迭代器
for (auto it = table.begin(); it != table.end(); ++it) {
for (auto& element : *it) {
// 处理元素
}
}

◆ cbegin()

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::const_iterator DA::da_array_table< T, RowN, ColN >::cbegin ( ) const
noexcept

返回指向起始的常量迭代器

模板参数
T存储的值类型
RowN行数
ColN列数
返回
指向表格起始的常量迭代器
for (auto it = table.cbegin(); it != table.cend(); ++it) {
for (const auto& element : *it) {
// 处理元素
}
}
const_iterator cend() const noexcept
返回指向末尾的常量迭代器
Definition da_array_table.hpp:316
const_iterator cbegin() const noexcept
返回指向起始的常量迭代器
Definition da_array_table.hpp:256

◆ cend()

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::const_iterator DA::da_array_table< T, RowN, ColN >::cend ( ) const
noexcept

返回指向末尾的常量迭代器

模板参数
T存储的值类型
RowN行数
ColN列数
返回
指向表格末尾的常量迭代器
for (auto it = table.cbegin(); it != table.cend(); ++it) {
// 处理行
}

◆ column_count()

template<typename T , std::size_t RowN, std::size_t ColN>
std::size_t DA::da_array_table< T, RowN, ColN >::column_count ( ) const

获取列数

模板参数
T存储的值类型
RowN行数
ColN列数
返回
表格的列数
std::cout << "表格有 " << table.column_count() << " 列" << std::endl;
// 输出: 表格有 4 列
std::size_t column_count() const
获取列数
Definition da_array_table.hpp:560

◆ crbegin()

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::const_reverse_iterator DA::da_array_table< T, RowN, ColN >::crbegin ( ) const
noexcept

返回指向起始的常量反向迭代器

模板参数
T存储的值类型
RowN行数
ColN列数
返回
指向表格起始的常量反向迭代器
for (auto it = table.crbegin(); it != table.crend(); ++it) {
for (const auto& element : *it) {
// 处理元素
}
}
const_reverse_iterator crend() const noexcept
返回指向末尾的常量反向迭代器
Definition da_array_table.hpp:442
const_reverse_iterator crbegin() const noexcept
返回指向起始的常量反向迭代器
Definition da_array_table.hpp:382

◆ crend()

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::const_reverse_iterator DA::da_array_table< T, RowN, ColN >::crend ( ) const
noexcept

返回指向末尾的常量反向迭代器

模板参数
T存储的值类型
RowN行数
ColN列数
返回
指向表格末尾的常量反向迭代器
for (auto it = table.crbegin(); it != table.crend(); ++it) {
// 处理行
}

◆ empty()

template<typename T , std::size_t RowN, std::size_t ColN>
bool DA::da_array_table< T, RowN, ColN >::empty ( ) const
noexcept

检查表格是否为空

模板参数
T存储的值类型
RowN行数
ColN列数
返回
如果表格为空返回true,否则返回false
if (table.empty()) {
std::cout << "表格为空" << std::endl;
} else {
std::cout << "表格不为空" << std::endl;
}
bool empty() const noexcept
检查表格是否为空
Definition da_array_table.hpp:464

◆ end() [1/2]

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::const_iterator DA::da_array_table< T, RowN, ColN >::end ( ) const
noexcept

返回指向末尾的常量迭代器

模板参数
T存储的值类型
RowN行数
ColN列数
返回
指向表格末尾的常量迭代器
for (auto it = table.begin(); it != table.end(); ++it) {
// 处理行
}

◆ end() [2/2]

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::iterator DA::da_array_table< T, RowN, ColN >::end ( )
noexcept

返回指向末尾的迭代器

模板参数
T存储的值类型
RowN行数
ColN列数
返回
指向表格末尾的迭代器
for (auto it = table.begin(); it != table.end(); ++it) {
// 处理行
}

◆ fill()

template<typename T , std::size_t RowN, std::size_t ColN>
void DA::da_array_table< T, RowN, ColN >::fill ( const T &  value)

填充表格

模板参数
T存储的值类型
RowN行数
ColN列数
参数
value要填充的值
table.fill(42); // 将所有元素设置为42
void fill(const T &value)
填充表格
Definition da_array_table.hpp:578

◆ max_size()

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::size_type DA::da_array_table< T, RowN, ColN >::max_size ( ) const
noexcept

返回最大可能元素数量

模板参数
T存储的值类型
RowN行数
ColN列数
返回
表格可容纳的最大元素数量
std::cout << "表格最大可容纳 " << table.max_size() << " 个元素" << std::endl;
// 输出: 表格最大可容纳 12 个元素
size_type max_size() const noexcept
返回最大可能元素数量
Definition da_array_table.hpp:502

◆ operator()() [1/2]

template<typename T , std::size_t RowN, std::size_t ColN>
T & DA::da_array_table< T, RowN, ColN >::operator() ( std::size_t  row,
std::size_t  col 
)

函数调用运算符访问元素

模板参数
T存储的值类型
RowN行数
ColN列数
参数
row行索引
col列索引
返回
元素的引用
table(0, 0) = 42; // 设置元素值
int value = table(0, 0); // 获取元素值

◆ operator()() [2/2]

template<typename T , std::size_t RowN, std::size_t ColN>
const T & DA::da_array_table< T, RowN, ColN >::operator() ( std::size_t  row,
std::size_t  col 
) const

函数调用运算符访问元素(常量版本)

模板参数
T存储的值类型
RowN行数
ColN列数
参数
row行索引
col列索引
返回
元素的常量引用
int value = table(0, 0); // 获取元素值

◆ rbegin() [1/2]

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::const_reverse_iterator DA::da_array_table< T, RowN, ColN >::rbegin ( ) const
noexcept

返回指向起始的常量反向迭代器

模板参数
T存储的值类型
RowN行数
ColN列数
返回
指向表格起始的常量反向迭代器
for (auto it = table.rbegin(); it != table.rend(); ++it) {
for (const auto& element : *it) {
// 处理元素
}
}
reverse_iterator rbegin() noexcept
返回指向起始的反向迭代器
Definition da_array_table.hpp:338
reverse_iterator rend() noexcept
返回指向末尾的反向迭代器
Definition da_array_table.hpp:402

◆ rbegin() [2/2]

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::reverse_iterator DA::da_array_table< T, RowN, ColN >::rbegin ( )
noexcept

返回指向起始的反向迭代器

模板参数
T存储的值类型
RowN行数
ColN列数
返回
指向表格起始的反向迭代器
for (auto it = table.rbegin(); it != table.rend(); ++it) {
for (auto& element : *it) {
// 处理元素
}
}

◆ rend() [1/2]

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::const_reverse_iterator DA::da_array_table< T, RowN, ColN >::rend ( ) const
noexcept

返回指向末尾的常量反向迭代器

模板参数
T存储的值类型
RowN行数
ColN列数
返回
指向表格末尾的常量反向迭代器
for (auto it = table.rbegin(); it != table.rend(); ++it) {
// 处理行
}

◆ rend() [2/2]

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::reverse_iterator DA::da_array_table< T, RowN, ColN >::rend ( )
noexcept

返回指向末尾的反向迭代器

模板参数
T存储的值类型
RowN行数
ColN列数
返回
指向表格末尾的反向迭代器
for (auto it = table.rbegin(); it != table.rend(); ++it) {
// 处理行
}

◆ row_count()

template<typename T , std::size_t RowN, std::size_t ColN>
std::size_t DA::da_array_table< T, RowN, ColN >::row_count ( ) const

获取行数

模板参数
T存储的值类型
RowN行数
ColN列数
返回
表格的行数
std::cout << "表格有 " << table.row_count() << " 行" << std::endl;
// 输出: 表格有 3 行
std::size_t row_count() const
获取行数
Definition da_array_table.hpp:541

◆ shape()

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::table_index_type DA::da_array_table< T, RowN, ColN >::shape ( ) const

获取表格形状

模板参数
T存储的值类型
RowN行数
ColN列数
返回
包含行数和列数的pair
auto shape = table.shape(); // 返回(3, 4)
std::cout << "表格形状: " << shape.first << " x " << shape.second << std::endl;
// 输出: 表格形状: 3 x 4
table_index_type shape() const
获取表格形状
Definition da_array_table.hpp:522

◆ size()

template<typename T , std::size_t RowN, std::size_t ColN>
da_array_table< T, RowN, ColN >::size_type DA::da_array_table< T, RowN, ColN >::size ( ) const
noexcept

返回元素数量

模板参数
T存储的值类型
RowN行数
ColN列数
返回
表格中的元素数量
std::cout << "表格有 " << table.size() << " 个元素" << std::endl;
// 输出: 表格有 12 个元素
size_type size() const noexcept
返回元素数量
Definition da_array_table.hpp:483

◆ swap()

template<typename T , std::size_t RowN, std::size_t ColN>
void DA::da_array_table< T, RowN, ColN >::swap ( da_array_table< T, RowN, ColN > &  other)
noexcept

交换两个表格的内容

模板参数
T存储的值类型
RowN行数
ColN列数
参数
other要交换的另一个表格
table1.swap(table2); // 交换两个表格的内容
void swap(da_array_table &other) noexcept
交换两个表格的内容
Definition da_array_table.hpp:599

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