draconisplusplus/include/rfl/internal/to_ptr_field_tuple.hpp

41 lines
1.1 KiB
C++
Raw Normal View History

2024-05-31 22:59:00 -04:00
#ifndef RFL_INTERNAL_TO_PTR_FIELD_TUPLE_HPP_
#define RFL_INTERNAL_TO_PTR_FIELD_TUPLE_HPP_
#include <iostream>
#include <tuple>
#include <type_traits>
#include "../field_names_t.hpp"
#include "bind_to_tuple.hpp"
#include "has_fields.hpp"
#include "is_empty.hpp"
#include "is_named_tuple.hpp"
#include "nt_to_ptr_named_tuple.hpp"
#include "to_ptr_field.hpp"
#include "wrap_in_fields.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 T>
auto to_ptr_field_tuple(T& _t) {
if constexpr (std::is_pointer_v<std::remove_cvref_t<T>>) {
return to_ptr_field_tuple(*_t);
} else if constexpr (is_named_tuple_v<T>) {
return nt_to_ptr_named_tuple(_t).fields();
} else if constexpr (has_fields<T>()) {
return bind_to_tuple(_t, [](auto& x) { return to_ptr_field(x); });
} else if constexpr (is_empty<T>()) {
return std::tuple();
} else {
using FieldNames = field_names_t<T>;
2024-06-16 00:13:15 -04:00
auto tup = bind_to_tuple(_t, [](auto& x) { return to_ptr_field(x); });
2024-06-08 14:10:59 -04:00
return wrap_in_fields<FieldNames>(std::move(tup));
}
}
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