draconisplusplus/include/rfl/internal/get_meta_fields.hpp

33 lines
1,000 B
C++
Raw Normal View History

2024-05-31 22:59:00 -04:00
#ifndef RFL_INTERNAL_GETMETAFIELDS_HPP_
#define RFL_INTERNAL_GETMETAFIELDS_HPP_
#include <array>
#include <tuple>
#include <utility>
#include "../MetaField.hpp"
#include "../type_name_t.hpp"
namespace rfl {
2024-06-08 14:10:59 -04:00
namespace internal {
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
template <class NamedTupleType, class... AlreadyExtracted>
auto get_meta_fields(AlreadyExtracted&&... _already_extracted) {
constexpr size_t i = sizeof...(_already_extracted);
if constexpr (NamedTupleType::size() == i) {
2024-06-16 00:13:15 -04:00
return std::array<MetaField, i> { std::move(_already_extracted)... };
2024-06-08 14:10:59 -04:00
} else {
2024-06-16 00:13:15 -04:00
using FieldType = std::tuple_element_t<i, typename NamedTupleType::Fields>;
auto name = typename FieldType::Name().str();
auto type = type_name_t<typename FieldType::Type>().str();
2024-06-08 14:10:59 -04:00
return get_meta_fields<NamedTupleType>(
2024-06-16 00:13:15 -04:00
std::move(_already_extracted)..., MetaField(std::move(name), std::move(type))
2024-06-08 15:53:06 -04:00
);
2024-06-08 14:10:59 -04:00
}
}
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
} // namespace internal
} // namespace rfl
2024-05-31 22:59:00 -04:00
#endif