Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapted the C arrays flag; fixes #353 #355

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/c_arrays_and_inheritance.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ inheritance altogether.
Note that C arrays are not the same thing as `std::array`. `std::array` is always
supported and is the recommended alternative.

If you want support for these, you will have to pass the flag `-D REFLECTCPP_C_ARRAYS_OR_INHERITANCE`
If you want support for these, you will have to pass the flag `-D REFLECT_CPP_C_ARRAYS_OR_INHERITANCE`
during compilation.

## C arrays
Expand Down
42 changes: 21 additions & 21 deletions include/rfl/internal/num_fields.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,23 @@ template <class Derived>
struct any_empty_base {
any_empty_base(std::size_t);
template <class Base>
requires(std::is_empty_v<std::remove_cvref_t<Base>>&& std::is_base_of_v<
std::remove_cvref_t<Base>, std::remove_cv_t<Derived>> &&
!std::is_same_v<std::remove_cvref_t<Base>,
std::remove_cv_t<Derived>>) constexpr
operator Base&() const noexcept;
requires(
std::is_empty_v<std::remove_cvref_t<Base>> &&
std::is_base_of_v<std::remove_cvref_t<Base>,
std::remove_cv_t<Derived>> &&
!std::is_same_v<std::remove_cvref_t<Base>, std::remove_cv_t<Derived>>)
constexpr operator Base&() const noexcept;
};

template <class Derived>
struct any_base {
any_base(std::size_t);
template <class Base>
requires(
std::is_base_of_v<std::remove_cvref_t<Base>, std::remove_cv_t<Derived>> &&
!std::is_same_v<std::remove_cvref_t<Base>,
std::remove_cv_t<Derived>>) constexpr
operator Base&() const noexcept;
requires(
std::is_base_of_v<std::remove_cvref_t<Base>,
std::remove_cv_t<Derived>> &&
!std::is_same_v<std::remove_cvref_t<Base>, std::remove_cv_t<Derived>>)
constexpr operator Base&() const noexcept;
};

struct any {
Expand All @@ -83,19 +84,17 @@ struct CountFieldsHelper {
static consteval bool constructible() {
return []<std::size_t... is>(std::index_sequence<is...>) {
return requires { T{any(is)...}; };
}
(std::make_index_sequence<n>());
}(std::make_index_sequence<n>());
}

template <std::size_t l, std::size_t nested, std::size_t r>
static consteval bool constructible_with_nested() {
return []<std::size_t... i, std::size_t... j, std::size_t... k>(
std::index_sequence<i...>, std::index_sequence<j...>,
std::index_sequence<k...>) {
std::index_sequence<i...>, std::index_sequence<j...>,
std::index_sequence<k...>) {
return requires { T{any(i)..., {any(j)...}, any(k)...}; };
}
(std::make_index_sequence<l>(), std::make_index_sequence<nested>(),
std::make_index_sequence<r>());
}(std::make_index_sequence<l>(), std::make_index_sequence<nested>(),
std::make_index_sequence<r>());
}

template <std::size_t n = 0>
Expand Down Expand Up @@ -124,7 +123,8 @@ struct CountFieldsHelper {
static consteval std::size_t find_the_sole_non_empty_base_index() {
static_assert(index < max_args);
constexpr auto check = []<std::size_t... l, std::size_t... r>(
std::index_sequence<l...>, std::index_sequence<r...>) {
std::index_sequence<l...>,
std::index_sequence<r...>) {
return requires {
T{any_empty_base<T>(l)..., any_base<T>(0), any_empty_base<T>(r)...};
};
Expand Down Expand Up @@ -155,8 +155,7 @@ struct CountFieldsHelper {
return []<std::size_t... l, std::size_t... r>(std::index_sequence<l...>,
std::index_sequence<r...>) {
return requires { T{any_base<T>(l)..., any(r)...}; };
}
(std::make_index_sequence<n>(), std::make_index_sequence<right_len>());
}(std::make_index_sequence<n>(), std::make_index_sequence<right_len>());
}

template <std::size_t max_arg_num, std::size_t index = 0>
Expand All @@ -182,7 +181,8 @@ struct CountFieldsHelper {

static consteval std::size_t count_fields() {
constexpr std::size_t max_agg_args = count_max_args_in_agg_init();
#ifdef REFLECT_CPP_C_ARRAYS_OR_INHERITANCE
#if defined(REFLECT_CPP_C_ARRAYS_OR_INHERITANCE) || \
defined(REFLECTCPP_C_ARRAYS_OR_INHERITANCE)
constexpr std::size_t no_brace_ellison_args =
constructible_no_brace_elision<0, max_agg_args>();
constexpr std::size_t base_args = base_param_num<no_brace_ellison_args>();
Expand Down
Loading