DStruct數(shù)據(jù)結(jié)構(gòu)模板庫
DStruct 是一個(gè)易于移植且結(jié)構(gòu)簡潔的數(shù)據(jù)結(jié)構(gòu)模板庫。
特性
- 易于移植,不依賴標(biāo)準(zhǔn)庫(std)和其它三方庫
- 易于使用(數(shù)據(jù)結(jié)構(gòu)和算法分離設(shè)計(jì),統(tǒng)一接口,std標(biāo)準(zhǔn)庫風(fēng)格)
- 易于學(xué)習(xí)/定制和改進(jìn)(結(jié)構(gòu)簡潔且只有頭文件)
- 提供靜態(tài)數(shù)據(jù)結(jié)構(gòu)和自定義數(shù)據(jù)結(jié)構(gòu)分配器功能
- 支持裸機(jī)/小內(nèi)存設(shè)備, 提供簡單的靜態(tài)內(nèi)存管理/分配器SMA
- 現(xiàn)代 C++ / 泛型結(jié)構(gòu),包含多樣豐富的數(shù)據(jù)結(jié)構(gòu)
用法
1. 源碼及配置
- 下載源碼到本地
- 添加DStruct庫的根目錄到你的include的路徑
- 自定義分配器&實(shí)現(xiàn)dstruct-port.h接口 - 可選
2. 代碼用例 - 動態(tài)內(nèi)存
#include <iostream>
#include "dstruct.hpp"
int main() {
dstruct::Array<int, 10> arr(2);
decltype(arr)::ValueType val = 6;
arr[0] = arr[-1] = val;
for (int i = 0; i < arr.size(); i++) {
std::cout << arr[-(i + 1)] << " : " << arr[i] << std::endl;
}
return 0;
}
3. 代碼用例 - 靜態(tài)內(nèi)存
使用靜態(tài)內(nèi)存SMA, 支持無內(nèi)存管理環(huán)境(如: 裸機(jī))
#include <dstruct.hpp>
int main() {
//dstruct::Vector<int> dVec;
dstruct::smemory::Vector<int> sVec;
for (int i = 0; i < 10; i++) {
sVec.push_back(i);
}
for (auto v : sVec)
DSTRUCT_ASSERT(v == i++);
while (!sVec.empty()) {
sVec.pop_back();
}
return 0;
}
注: 靜態(tài)數(shù)據(jù)結(jié)構(gòu)定義在dstruct::smemory空間里, 其他接口及用法同動態(tài)內(nèi)存支持的數(shù)據(jù)結(jié)構(gòu)一樣
相關(guān)鏈接
評論
圖片
表情
