2024-05-31 22:59:00 -04:00
|
|
|
#ifndef RFL_INTERNAL_HASFIELDS_HPP_
|
|
|
|
#define RFL_INTERNAL_HASFIELDS_HPP_
|
|
|
|
|
|
|
|
#include <tuple>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "all_fields.hpp"
|
|
|
|
#include "is_field.hpp"
|
|
|
|
#include "is_flatten_field.hpp"
|
|
|
|
#include "ptr_tuple_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 TupleType, int _i = 0>
|
|
|
|
constexpr bool all_fields_or_flatten() {
|
|
|
|
if constexpr (_i == std::tuple_size_v<TupleType>) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
using T = std::remove_cvref_t<std::tuple_element_t<_i, TupleType>>;
|
|
|
|
if constexpr (is_flatten_field_v<T>) {
|
2024-06-16 00:13:15 -04:00
|
|
|
return all_fields_or_flatten<ptr_tuple_t<typename std::remove_pointer_t<T>::Type>>() &&
|
2024-06-08 14:10:59 -04:00
|
|
|
all_fields_or_flatten<TupleType, _i + 1>();
|
|
|
|
} else {
|
|
|
|
return is_field_v<T> && all_fields_or_flatten<TupleType, _i + 1>();
|
|
|
|
}
|
|
|
|
}
|
2024-05-31 22:59:00 -04:00
|
|
|
}
|
|
|
|
|
2024-06-08 14:10:59 -04:00
|
|
|
template <class TupleType, int _i = 0>
|
|
|
|
constexpr bool some_fields_or_flatten() {
|
|
|
|
if constexpr (_i == std::tuple_size_v<TupleType>) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
using T = std::remove_cvref_t<std::tuple_element_t<_i, TupleType>>;
|
|
|
|
if constexpr (is_flatten_field_v<T>) {
|
2024-06-16 00:13:15 -04:00
|
|
|
return some_fields_or_flatten<ptr_tuple_t<typename std::remove_pointer_t<T>::Type>>() ||
|
2024-06-08 14:10:59 -04:00
|
|
|
some_fields_or_flatten<TupleType, _i + 1>();
|
|
|
|
} else {
|
|
|
|
return is_field_v<T> || some_fields_or_flatten<TupleType, _i + 1>();
|
|
|
|
}
|
|
|
|
}
|
2024-05-31 22:59:00 -04:00
|
|
|
}
|
|
|
|
|
2024-06-08 14:10:59 -04:00
|
|
|
template <class T>
|
|
|
|
constexpr bool has_fields() {
|
|
|
|
if constexpr (is_named_tuple_v<T>) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
using TupleType = ptr_tuple_t<T>;
|
|
|
|
if constexpr (some_fields_or_flatten<TupleType>()) {
|
|
|
|
static_assert(
|
2024-06-16 00:13:15 -04:00
|
|
|
all_fields_or_flatten<TupleType>(),
|
|
|
|
"If some of your fields are annotated using rfl::Field<...>, "
|
|
|
|
"then you must annotate all of your fields. "
|
|
|
|
"Also, you cannot combine annotated and "
|
|
|
|
"unannotated fields using rfl::Flatten<...>."
|
2024-06-08 15:53:06 -04:00
|
|
|
);
|
2024-06-08 14:10:59 -04:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
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
|