Ahsohtoa
Structure-of-array synthesis in C++20
Install / Use
/learn @celtera/AhsohtoaREADME
ahsohtoa - automatic AoS-to-SoA
Automatic structure-of-array generation for C++20: this library takes a structure such as:
struct Foo {
int a;
float b;
struct Bar {
float x;
char y;
} c;
};
and, given:
ahso::arrays<std::vector, Foo> storage_direct;
ahso::recursive_arrays<std::vector, Foo> storage_recursive;
will respectively synthesize types which look like:
// for storage_direct:
std::tuple<std::vector<int>, std::vector<float>, std::vector<Bar>>
// for storage_recursive:
std::tuple<std::vector<int>, std::vector<float>, std::vector<float>, std::vector<char>>
Dependencies
- Boost.PFR
- C++20
Simple example
struct vec3 { float x,y,z; };
struct color { float r,g,b,a; };
struct physics_component {
vec3 position;
vec3 speed;
vec3 acceleration;
};
struct render_component {
color col;
};
struct entity {
physics_component physics;
render_component render;
}
int main()
{
// Define our storage
ahso::arrays<std::vector, entity> e;
// Preallocate some space like you would with std::vector
e.reserve(1000);
// Add a new entity
auto index = e.add_entity({
.physics {
.position { 0., 0., 0. }
, .acceleration { 1., 0., 0. }
},
.render {
.col { 0., 1., 0., 1. }
}
});
// Access a specific component for entity "index"
e.get<physics_component>(index).position.x = 2;
// Or if the proper type is provided (until we get metaclasses, see example):
e[index].physics.position.x = 2;
// Remove an entity
e.erase(index);
}
Example with all the features
See https://github.com/celtera/ahsohtoa/blob/main/tests/test.cpp !
Licensing
The library is licensed under GPLv3 + commercial.
Related Skills
node-connect
350.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
350.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
350.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
