Skip to content
Closed
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
12 changes: 11 additions & 1 deletion include/rfl/internal/cpp20/num_fields.hpp

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this could also be used to avoid constructible_with_nested / constructible_no_brace_elision, but didn't want to touch code that didn't impact my use case.

Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,22 @@ struct any {
constexpr operator T() const noexcept;
};

/// Like `any`, but never converts to `T` itself, so that a single argument cannot select `T`'s
/// copy or move constructor instead of aggregate-initializing its first field.
template <class T>
struct any_but {
any_but(std::size_t);
template <class U>
requires(!std::is_same_v<std::remove_cvref_t<U>, std::remove_cv_t<T>>)
constexpr operator U() const noexcept;
};

template <typename T>
struct CountFieldsHelper {
template <std::size_t n>
static consteval bool constructible() {
return []<std::size_t... is>(std::index_sequence<is...>) {
return requires { T{any(is)...}; };
return std::is_constructible_v<T, decltype(any_but<T>(is))...>;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it, we should probably use any_but for the 1-argument case, but keep using any for other cases to allow T(T, T) constructors...

}(std::make_index_sequence<n>());
}

Expand Down
Loading