mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-11-29 22:36:19 +08:00
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
@@ -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>
|
||||
@@ -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)...};
|
||||
};
|
||||
@@ -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>
|
||||
@@ -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>();
|
||||
|
||||
Reference in New Issue
Block a user