Files
libconfig/build-config/reflect-cpp/include/rfl/internal/tuple/calculate_positions.hpp
Emily Boudreaux ec13264050 feat(reflect-cpp): Switched from glaze -> reflect cpp
A bug was discovered in glaze which prevented valid toml output. We have
switched to toml++ and reflect-cpp. The interface has remained the same
so this should not break any code
2025-12-06 10:55:46 -05:00

39 lines
1.1 KiB
C++

#ifndef RFL_INTERNAL_TUPLE_CALCULATE_POSITIONS_HPP_
#define RFL_INTERNAL_TUPLE_CALCULATE_POSITIONS_HPP_
#include <array>
namespace rfl::internal::tuple {
template <class T>
struct PositionWrapper {};
template <unsigned long _last, unsigned long... _is>
struct Positions {
static consteval auto to_array() {
return std::array<unsigned long, sizeof...(_is) + 1>({_is..., _last});
}
};
template <class T, unsigned long _last, unsigned long... _is>
consteval auto operator+(const Positions<_last, _is...>&,
const PositionWrapper<T>&) {
if constexpr (_last % alignof(T) == 0) {
constexpr auto last_new = _last + sizeof(T);
return Positions<last_new, _is..., _last>{};
} else {
constexpr auto last_corrected = _last + alignof(T) - (_last % alignof(T));
constexpr auto last_new = last_corrected + sizeof(T);
return Positions<last_new, _is..., last_corrected>{};
}
}
template <class... Types>
consteval auto calculate_positions() {
return (Positions<0>{} + ... + PositionWrapper<Types>{}).to_array();
}
} // namespace rfl::internal::tuple
#endif