Struct-of-Array Transforms
SoA<->AoS conversion code as well as IsSoAType concept.
- Author
Bryce Ferenczi
- Version
0.1
- Date
2024-08-10
- Copyright
Copyright (c) 2024
-
namespace cvt
Functions
-
template<typename SoA, typename AoS>
auto AoStoSoA(AoS &&aos) noexcept -> SoA Convert AoS to SoA.
- Template Parameters:
AoS – incoming AoS type
SoA – outgoing SoA type
- Parameters:
aos – input data
- Returns:
transformed aos to soa
-
template<typename SoA, typename AoS>
auto AoStoSoA(const AoS &aos) noexcept -> SoA Convert AoS to SoA.
- Template Parameters:
AoS – incoming AoS type
SoA – outgoing SoA type
- Parameters:
aos – input data
- Returns:
transformed aos to soa
-
template<typename SoA, typename AoS>
auto SoAtoAoS(const SoA &soa) noexcept -> AoS Convert SoA to AoS.
- Template Parameters:
SoA – incoming SoA type
AoS – outgoing AoS type
- Parameters:
soa – input data
- Returns:
transformed soa to aos
-
template<IsSoAType SoA>
auto SoAtoAoS(const SoA &soa) noexcept -> std::vector<typename SoA::struct_type> Convert SoA to AoS which is basic std::vector of the original struct_type.
- Template Parameters:
SoA – incoming SoA type
AoS – outgoing AoS type
- Parameters:
soa – input data
- Returns:
transformed soa to aos
-
template<IsSoAType SoA>
auto gatherStructAtIndex(const SoA &soa, std::size_t index) noexcept -> typename SoA::struct_type Gather data from an SoA to create the struct at the target index.
- Template Parameters:
SoA – type
- Parameters:
soa – data to gather from
index – index of data to gather
- Returns:
SoA::struct_type gathered from SoA at index.
-
namespace detail
Functions
-
template<std::size_t I, typename SoA>
consteval auto getStructIndex() -> std::size_t Get index of the underlying struct that corresponds to the SoA index based on matching names between struct and SoA types.
- Template Parameters:
I – index in SoA type
SoA – type
- Returns:
std::size_t matched index in the SoA::struct_type
-
template<typename T, std::size_t I = boost::pfr::tuple_size_v<T> - 1>
inline void emplaceBackIntoSoA(T &dest, const typename T::struct_type &element) noexcept emplace_back an element into a Struct-of-Arrays. Writes to SoA element-by-element from greatest index.
- Template Parameters:
T – Struct-of-Arrays type
I – Index of SoA/Struct to copy from.
- Parameters:
dest – Struct-of-Arrays to emplace_back data to
element – Data to scatter over the the SoA vectors.
-
template<typename T, std::size_t I = boost::pfr::tuple_size_v<T> - 1>
inline void assignFromSoAIndex(typename T::struct_type &dest, const T &soa, std::size_t index) noexcept Assign to a struct from an index in a Struct-of-Arrays. Reads from SoA element-by-element from greatest index.
- Template Parameters:
T – Struct-of-Arrays type
I – Index of SoA to copy from
- Parameters:
dest – struct to write data to
soa – Struct-of-Arrays to gather data from
index – Index from struct-of-arrays to gather from
-
template<std::size_t I, typename SoA>
-
template<typename SoA, typename AoS>