https://github.com/celtera/ahsohtoa
Structure-of-array synthesis in C++20
https://github.com/celtera/ahsohtoa
cplusplus cplusplus-20 game-development gamedev structure-of-arrays
Last synced: 6 months ago
JSON representation
Structure-of-array synthesis in C++20
- Host: GitHub
- URL: https://github.com/celtera/ahsohtoa
- Owner: celtera
- License: other
- Created: 2021-11-03T13:16:02.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-27T09:05:32.000Z (over 3 years ago)
- Last Synced: 2025-04-14T23:36:58.948Z (9 months ago)
- Topics: cplusplus, cplusplus-20, game-development, gamedev, structure-of-arrays
- Language: C++
- Homepage:
- Size: 27.3 KB
- Stars: 81
- Watchers: 6
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ahsohtoa - automatic AoS-to-SoA
 [](https://github.com/sponsors/jcelerier)  
Automatic structure-of-array generation for C++20: this library
takes a structure such as:
```C++
struct Foo {
int a;
float b;
struct Bar {
float x;
char y;
} c;
};
```
and, given:
```C++
ahso::arrays storage_direct;
ahso::recursive_arrays storage_recursive;
```
will respectively synthesize types which look like:
```C++
// for storage_direct:
std::tuple, std::vector, std::vector>
// for storage_recursive:
std::tuple, std::vector, std::vector, std::vector>
```
## Dependencies
- Boost.PFR
- C++20
## Simple example
```C++
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 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(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](https://celtera.dev/).