Skip to content

Commit

Permalink
Another round of tweaks & cleanups
Browse files Browse the repository at this point in the history
The visit/accept machinery is finally in an ok state.. Now I can start
working on the actual project.
  • Loading branch information
laverdet committed Oct 28, 2024
1 parent e800e1a commit e237c2b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 13 deletions.
1 change: 0 additions & 1 deletion packages/value/enum/accept.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace ivm::value {
template <class Enum>
requires std::is_enum_v<Enum>
struct accept<void, Enum> : accept<void, void> {
using hash_type = uint32_t;
using accept<void, void>::accept;

template <class String>
Expand Down
11 changes: 5 additions & 6 deletions packages/value/struct/accept.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ template <class Meta, class Type, class... Setters>
struct accept<Meta, object_type<Type, std::tuple<Setters...>>> {
private:
template <class Setter>
using accept_setter = accept<Meta, value_by_key<property_name_v<Setter>, std::optional<typename Setter::type>, visit_subject_t<Meta>>>;
using setter_helper = value_by_key<property_name_v<Setter>, std::optional<typename Setter::type>, visit_subject_t<Meta>>;

public:
using hash_type = uint32_t;

constexpr accept(const auto_visit auto& visit) :
first{visit},
second{accept_setter<Setters>{visit}...} {}
second{accept<Meta, setter_helper<Setters>>{visit}...} {}
constexpr accept(int /*dummy*/, const auto_visit auto& visit, const auto_accept auto& /*accept_*/) :
accept{visit} {}

Expand All @@ -40,7 +38,8 @@ struct accept<Meta, object_type<Type, std::tuple<Setters...>>> {
util::select_t<Index, Setters...> setter{};
// nb: We `std::forward` the value to *each* setter. This allows the setters to pick an
// lvalue object apart member by member if it wants.
auto value = std::get<Index>(second)(dictionary_tag{}, std::forward<decltype(dictionary)>(dictionary), visit);
auto& accept = std::get<Index>(second);
auto value = accept(dictionary_tag{}, std::forward<decltype(dictionary)>(dictionary), visit);
if (value) {
setter(subject, *std::move(value));
} else if (setter.required) {
Expand All @@ -54,7 +53,7 @@ struct accept<Meta, object_type<Type, std::tuple<Setters...>>> {

private:
accept_next<Meta, std::string> first;
std::tuple<accept_setter<Setters>...> second;
std::tuple<accept<Meta, setter_helper<Setters>>...> second;
};

// Apply `setter_delegate` to each property, filtering properties which do not have a setter.
Expand Down
5 changes: 0 additions & 5 deletions packages/value/tuple/accept.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ struct accept<Meta, std::tuple<Types...>> {
constexpr accept(int /*dummy*/, const auto_visit auto& visit, const auto_accept auto& /*accept*/) :
accept{visit} {}

template <size_t Index>
constexpr auto operator()(std::integral_constant<size_t, Index> /*index*/, auto_tag auto tag, auto&& value, auto&&... rest) const -> decltype(auto) {
return std::get<Index>(acceptors_)(tag, std::forward<decltype(value)>(value), std::forward<decltype(rest)>(rest)...);
}

constexpr auto operator()(vector_tag /*tag*/, auto&& value, const auto& visit) const -> std::tuple<Types...> {
auto it = std::begin(value);
auto end = std::end(value);
Expand Down
1 change: 0 additions & 1 deletion packages/value/tuple/visit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ struct visit<Meta, std::tuple<Types...>> {
constexpr visit(int dummy, const auto_visit auto& visit_) :
visit_{visit<Meta, Types>{dummy, visit_}...} {}

// The invoker of visit is expected to invoke `std::get`. This should be fixed.
template <size_t Index>
constexpr auto operator()(std::integral_constant<size_t, Index> /*index*/, auto&& value, const auto& accept) const -> decltype(auto) {
return std::get<Index>(visit_)(std::get<Index>(std::forward<decltype(value)>(value)), accept);
Expand Down

0 comments on commit e237c2b

Please sign in to comment.