diff --git a/include/rfl/Tuple.hpp b/include/rfl/Tuple.hpp index ee12e54c2..1df892eec 100644 --- a/include/rfl/Tuple.hpp +++ b/include/rfl/Tuple.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -68,7 +69,7 @@ class Tuple { template constexpr auto& get() { using Type = internal::nth_element_t<_index, Types...>; - return *internal::ptr_cast(data_ + pos<_index>()); + return *internal::ptr_cast(data_ + std::get<_index>(positions_)); } /// Gets an element by index (const). @@ -77,7 +78,8 @@ class Tuple { template constexpr const auto& get() const { using Type = internal::nth_element_t<_index, Types...>; - return *internal::ptr_cast(data_ + pos<_index>()); + return *internal::ptr_cast(data_ + + std::get<_index>(positions_)); } /// Copy assignment operator. Assigns from another Tuple by copy. @@ -154,13 +156,10 @@ class Tuple { template void copy_from_other(const Tuple& _other, std::integer_sequence) { - const auto copy_one = [this](const auto& _other, - std::integral_constant) { - using Type = internal::nth_element_t<_i, Types...>; - ::new (static_cast(data_ + pos<_i>())) - Type(_other.template get<_i>()); - }; - (copy_one(_other, std::integral_constant{}), ...); + ((::new (static_cast(data_ + std::get<_is>(positions_))) + Types(*internal::ptr_cast( + _other.data_ + std::get<_is>(positions_)))), + ...); } /// Copies all elements from provided arguments. @@ -169,25 +168,22 @@ class Tuple { template void copy_from_types(const Types&... _types, std::integer_sequence) { - const auto copy_one = [this](const auto& _t, - std::integral_constant) { - using Type = internal::nth_element_t<_i, Types...>; - ::new (static_cast(data_ + pos<_i>())) Type(_t); - }; - (copy_one(_types, std::integral_constant{}), ...); + ((::new (static_cast(data_ + std::get<_is>(positions_))) + Types(_types)), + ...); } /// Destroys all elements if they are destructible. /// @param seq_ Integer sequence for element indices. template void destroy_if_necessary(std::integer_sequence) { - const auto destroy_one = [](auto& _t) { - using Type = std::remove_cvref_t; - if constexpr (std::is_destructible_v) { - _t.~Type(); - } - }; - (destroy_one(get<_is>()), ...); + if constexpr (!(std::is_trivially_destructible_v && ...)) { + ((std::is_trivially_destructible_v + ? void() + : std::destroy_at( + internal::ptr_cast(data_ + std::get<_is>(positions_)))), + ...); + } } /// Moves all elements from another Tuple. @@ -195,13 +191,10 @@ class Tuple { /// @param seq_ Integer sequence for element indices. template void move_from_other(Tuple&& _other, std::integer_sequence) { - const auto move_one = [this](auto&& _other, - std::integral_constant) { - using Type = internal::nth_element_t<_i, Types...>; - ::new (static_cast(data_ + pos<_i>())) - Type(std::move(_other.template get<_i>())); - }; - (move_one(_other, std::integral_constant{}), ...); + ((::new (static_cast(data_ + std::get<_is>(positions_))) + Types(std::move(*internal::ptr_cast( + _other.data_ + std::get<_is>(positions_))))), + ...); } /// Moves all elements from provided arguments. @@ -209,20 +202,9 @@ class Tuple { /// @param seq_ Integer sequence for element indices. template void move_from_types(Types&&... _types, std::integer_sequence) { - const auto move_one = [this](auto&& _t, - std::integral_constant) { - using Type = internal::nth_element_t<_i, Types...>; - ::new (static_cast(data_ + pos<_i>())) Type(std::move(_t)); - }; - (move_one(std::move(_types), std::integral_constant{}), ...); - } - - /// Returns the byte offset of the element at index _i. - /// @tparam _i The index of the element. - /// @return The byte offset of the element. - template - static consteval unsigned int pos() { - return std::get<_i>(positions_); + ((::new (static_cast(data_ + std::get<_is>(positions_))) + Types(std::move(_types))), + ...); } private: diff --git a/include/rfl/cli/usage.hpp b/include/rfl/cli/usage.hpp index 8b545ad12..3b5c6fc41 100644 --- a/include/rfl/cli/usage.hpp +++ b/include/rfl/cli/usage.hpp @@ -814,7 +814,11 @@ class UsageWalker { } if (def_obj) { - auto view = ProcessorsType::template process(rfl::to_view(*def_obj)); + // Reuse the non-const to_view instantiation already created by read() + // instead of duplicating the entire reflection tree for `const S`. + // The view is only read through const pointers below. + auto view = ProcessorsType::template process( + rfl::to_view(const_cast(*def_obj))); using ViewType = decltype(view); [&](std::index_sequence<_is...>) { auto visit = [&]() { diff --git a/include/rfl/parsing/NamedTupleParser.hpp b/include/rfl/parsing/NamedTupleParser.hpp index 518fc3185..d21dd5462 100644 --- a/include/rfl/parsing/NamedTupleParser.hpp +++ b/include/rfl/parsing/NamedTupleParser.hpp @@ -352,38 +352,75 @@ struct NamedTupleParser { } /// Generates error messages for when fields are missing. - template + template static RFL_ALWAYS_INLINE void handle_one_missing_field( const std::array& _found, const NamedTupleType& _view, std::array* _set, FieldErrors* _errors, const bool _value_initialize_default_vals) noexcept { - if (should_stop_on_field_error(*_errors)) return; using FieldType = internal::nth_element_t<_i, FieldTypes...>; using ValueType = std::remove_reference_t< std::remove_pointer_t>; + constexpr bool is_default_val_field = + internal::is_default_val_v; + constexpr bool is_required_field = + !is_default_val_field && !internal::is_extra_fields_v && + (_all_required || is_required()); + + // When the struct was default-constructed, missing optional or DefaultVal + // fields already hold their default values, so nothing is needed at all. + if constexpr (_defaults_constructed && !is_required_field) { + return; + } else { + if (should_stop_on_field_error(*_errors)) return; + if (!std::get<_i>(_found)) { + if constexpr (!_defaults_constructed && + internal::is_unwrapped_default_val_v) { + if constexpr (can_value_initialize_default_val()) { + if (_value_initialize_default_vals) { + // The value's constructor can throw, for instance a Validator + // whose zero value is invalid. + try { + ::new (rfl::get<_i>(_view)) ValueType(); + } catch (std::exception& e) { + constexpr auto current_name = + internal::nth_element_t<_i, FieldTypes...>::name(); + _errors->emplace_back(make_nested_error( + std::string(current_name), + "Field named '" + std::string(current_name) + + "' not found, and its default value could not be " + "constructed: " + + e.what())); + return; + } + std::get<_i>(*_set) = true; + return; + } + } + } - if (!std::get<_i>(_found)) { - constexpr bool is_default_val_field = - internal::is_default_val_v; - constexpr bool is_required_field = - !is_default_val_field && !internal::is_extra_fields_v && - (_all_required || is_required()); - - // Without _set, the struct was default-constructed before it was read, - // so the field already holds its default value. With _set, the fields - // are constructed in raw memory. An rfl::NamedTuple has no in-class - // initializers, so a missing bare rfl::DefaultVal field is - // value-initialized there. Otherwise the field's default value is not - // available, so the field is required. - const bool defaults_constructed = _set == nullptr; - - if constexpr (internal::is_unwrapped_default_val_v) { - if constexpr (can_value_initialize_default_val()) { - if (_value_initialize_default_vals && !defaults_constructed) { - // The value's constructor can throw, for instance a Validator - // whose zero value is invalid. + if constexpr (is_required_field || + (is_default_val_field && !_defaults_constructed)) { + constexpr auto current_name = + internal::nth_element_t<_i, FieldTypes...>::name(); + std::stringstream stream; + stream << "Field named '" << std::string(current_name) + << "' not found."; + _errors->emplace_back( + make_nested_error(std::string(current_name), stream.str())); + return; + } + + if constexpr (!_defaults_constructed && !is_required_field && + !is_default_val_field) { + using NonConstT = std::remove_const_t; + const auto ptr = const_cast(rfl::get<_i>(_view)); + if constexpr (std::is_nothrow_default_constructible_v) { + ::new (ptr) NonConstT(); + } else { + // The default value can throw, for instance a Validator whose + // default value is invalid. try { - ::new (rfl::get<_i>(_view)) ValueType(); + ::new (ptr) NonConstT(); } catch (std::exception& e) { constexpr auto current_name = internal::nth_element_t<_i, FieldTypes...>::name(); @@ -395,51 +432,10 @@ struct NamedTupleParser { e.what())); return; } - std::get<_i>(*_set) = true; - return; } + std::get<_i>(*_set) = true; } } - - if (is_required_field || - (is_default_val_field && !defaults_constructed)) { - constexpr auto current_name = - internal::nth_element_t<_i, FieldTypes...>::name(); - std::stringstream stream; - stream << "Field named '" << std::string(current_name) - << "' not found."; - _errors->emplace_back( - make_nested_error(std::string(current_name), stream.str())); - return; - } - - if constexpr (!is_required_field && !is_default_val_field) { - if (defaults_constructed) { - return; - } - using NonConstT = std::remove_const_t; - const auto ptr = const_cast(rfl::get<_i>(_view)); - if constexpr (std::is_nothrow_default_constructible_v) { - ::new (ptr) NonConstT(); - } else { - // The default value can throw, for instance a Validator whose - // default value is invalid. - try { - ::new (ptr) NonConstT(); - } catch (std::exception& e) { - constexpr auto current_name = - internal::nth_element_t<_i, FieldTypes...>::name(); - _errors->emplace_back(make_nested_error( - std::string(current_name), - "Field named '" + std::string(current_name) + - "' not found, and its default value could not be " - "constructed: " + - e.what())); - return; - } - } - std::get<_i>(*_set) = true; - } } } @@ -454,14 +450,14 @@ struct NamedTupleParser { } /// Generates error messages for when fields are missing. - template + template static RFL_ALWAYS_INLINE void handle_missing_fields( const std::array& _found, const NamedTupleType& _view, std::array* _set, FieldErrors* _errors, const bool _value_initialize_default_vals, std::integer_sequence) noexcept { - (handle_one_missing_field<_is>(_found, _view, _set, _errors, - _value_initialize_default_vals), + (handle_one_missing_field<_is, _defaults_constructed>( + _found, _view, _set, _errors, _value_initialize_default_vals), ...); } @@ -498,9 +494,9 @@ struct NamedTupleParser { } } if (!should_stop_on_field_error(errors)) { - handle_missing_fields(found, *_view, &set, &errors, - _value_initialize_default_vals, - std::make_integer_sequence()); + handle_missing_fields( + found, *_view, &set, &errors, _value_initialize_default_vals, + std::make_integer_sequence()); } if constexpr (internal::fail_fast_v) { return std::make_pair(set, std::move(errors).error()); @@ -531,9 +527,10 @@ struct NamedTupleParser { if constexpr (internal::has_default_val_v && !internal::default_if_missing_v) { if (!should_stop_on_field_error(errors)) { - handle_missing_fields(reader.found(), *_view, nullptr, &errors, - /*_value_initialize_default_vals=*/false, - std::make_integer_sequence()); + handle_missing_fields( + reader.found(), *_view, nullptr, &errors, + /*_value_initialize_default_vals=*/false, + std::make_integer_sequence()); } } if constexpr (internal::fail_fast_v) { diff --git a/include/rfl/parsing/ViewReader.hpp b/include/rfl/parsing/ViewReader.hpp index 84ee4b826..ec2fcdc5e 100644 --- a/include/rfl/parsing/ViewReader.hpp +++ b/include/rfl/parsing/ViewReader.hpp @@ -14,6 +14,7 @@ #include "../internal/no_extra_fields_v.hpp" #include "FieldErrors.hpp" #include "Parser_base.hpp" +#include "peel_transparent_wrappers.hpp" #include "schemaful/IsSchemafulReader.hpp" #include "wrap_error.hpp" @@ -115,19 +116,22 @@ class ViewReader { is_matching(_current_name_or_index)) { std::get(*_found) = true; *_already_assigned = true; - auto res = Parser::read(_r, _var); + using Peel = peel_transparent; + auto res = read_field_core(_r, _var, FieldType::name(), + _errors, size_); if (!res) [[unlikely]] { - constexpr auto name = FieldType::name(); - // Reserve lazily to avoid error-vector reallocations while keeping - // successful reads allocation-free. - _errors->reserve(size_); - _errors->emplace_back(wrap_field_error(name, std::move(res).error())); return; } if constexpr (std::is_pointer_v) { - move_to(rfl::get(*_view), &(*res)); + if constexpr (Peel::peeled) { + auto wrapped = Peel::wrap(std::move(*res)); + placement_move_field(rfl::get(*_view), &wrapped); + } else { + placement_move_field(rfl::get(*_view), &(*res)); + } } else { - rfl::get(*_view) = std::move(*res); + rfl::get(*_view) = Peel::wrap(std::move(*res)); } std::get(*_set) = true; } @@ -192,26 +196,6 @@ class ViewReader { } } - template - static void move_to(Target* _t, Source* _s) { - if constexpr (std::is_const_v) { - return move_to(const_cast*>(_t), _s); - } else if constexpr (!rfl::internal::is_array_v && - !std::is_array_v) { - ::new (_t) Target(std::move(*_s)); - } else if constexpr (rfl::internal::is_array_v) { - static_assert(std::is_array_v, - "Expected target to be a c-array."); - for (size_t i = 0; i < _s->arr_.size(); ++i) { - move_to(&((*_t)[i]), &(_s->arr_[i])); - } - } else { - for (size_t i = 0; i < _s->size(); ++i) { - move_to(&((*_t)[i]), &((*_s)[i])); - } - } - } - private: /// The underlying reader. const R* r_; diff --git a/include/rfl/parsing/ViewReaderWithDefault.hpp b/include/rfl/parsing/ViewReaderWithDefault.hpp index c2e034322..f1d305f19 100644 --- a/include/rfl/parsing/ViewReaderWithDefault.hpp +++ b/include/rfl/parsing/ViewReaderWithDefault.hpp @@ -10,10 +10,12 @@ #include "../Ref.hpp" #include "../Tuple.hpp" +#include "../internal/always_inline.hpp" #include "../internal/is_array.hpp" #include "../internal/no_extra_fields_v.hpp" #include "FieldErrors.hpp" #include "Parser_base.hpp" +#include "peel_transparent_wrappers.hpp" #include "wrap_error.hpp" namespace rfl::parsing { @@ -68,31 +70,43 @@ class ViewReaderWithDefault { static constexpr size_t size() { return size_; } private: - template - static void assign_if_field_matches(const R& _r, - const std::string_view& _current_name, - const auto& _var, auto* _view, - auto* _errors, auto* _found, - bool* _already_assigned) { - using FieldType = tuple_element_t; - using OriginalType = typename FieldType::Type; - using T = - std::remove_cvref_t>; - constexpr auto name = FieldType::name(); - if (!(*_already_assigned) && !std::get(*_found) && - _current_name == name) { - std::get(*_found) = true; - *_already_assigned = true; - auto res = Parser::read(_r, _var); - if (!res) { - _errors->emplace_back(wrap_field_error(name, std::move(res).error())); - return; + static constexpr auto make_sorted_name_table() { + return [](std::integer_sequence) { + std::array, sizeof...(_is)> table{ + std::pair{ + tuple_element_t<_is, typename ViewType::Fields>::name(), _is}...}; + for (size_t i = 1; i < table.size(); ++i) { + const auto key = table[i]; + size_t j = i; + while (j > 0 && key.first < table[j - 1].first) { + table[j] = table[j - 1]; + --j; + } + table[j] = key; } - if constexpr (std::is_pointer_v) { - move_to(rfl::get(*_view), &(*res)); - } else { - rfl::get(*_view) = std::move(*res); + return table; + }(std::make_integer_sequence()); + } + + static int find_field_index(const std::string_view _name) noexcept { + if constexpr (size_ == 0) { + return -1; + } else { + static constexpr auto table = make_sorted_name_table(); + size_t lo = 0; + size_t hi = table.size(); + while (lo < hi) { + const size_t mid = lo + (hi - lo) / 2; + if (table[mid].first < _name) { + lo = mid + 1; + } else { + hi = mid; + } + } + if (lo < table.size() && table[lo].first == _name) { + return table[lo].second; } + return -1; } } @@ -115,6 +129,41 @@ class ViewReaderWithDefault { extra_fields->emplace(std::string(_current_name), std::move(*res)); } + template + static RFL_ALWAYS_INLINE void assign_one_field( + const R& _r, const auto& _var, ViewType* _view, + FieldErrors* _errors) { + using FieldType = tuple_element_t<_i, typename ViewType::Fields>; + using OriginalType = typename FieldType::Type; + using T = std::remove_cvref_t>; + using Peel = peel_transparent; + auto res = read_field_core( + _r, _var, FieldType::name(), _errors); + if (!res) [[unlikely]] { + return; + } + // Parser::check_deferred_defaults relies on DefaultVal fields being + // replaced as a whole. For pure non-DefaultVal transparent wrappers on + // mutable fields, assign directly to the inner CoreType without + // instantiating per-wrapper move helpers. + if constexpr (std::is_pointer_v) { + using TargetType = std::remove_pointer_t; + if constexpr (Peel::peeled && !Peel::has_default_val && + !std::is_const_v && + !std::is_array_v && + !rfl::internal::is_array_v) { + Peel::unwrap_ref(*rfl::get<_i>(*_view)) = std::move(*res); + } else if constexpr (Peel::peeled) { + auto wrapped = Peel::wrap(std::move(*res)); + move_assign_field(rfl::get<_i>(*_view), &wrapped); + } else { + move_assign_field(rfl::get<_i>(*_view), &(*res)); + } + } else { + rfl::get<_i>(*_view) = Peel::wrap(std::move(*res)); + } + } + template static void assign_to_matching_field(const R& _r, const std::string_view& _current_name, @@ -122,10 +171,15 @@ class ViewReaderWithDefault { auto* _errors, auto* _found, std::integer_sequence) { bool already_assigned = false; - - (assign_if_field_matches(_r, _current_name, _var, _view, _errors, - _found, &already_assigned), - ...); + const int idx = find_field_index(_current_name); + if (idx >= 0 && !(*_found)[static_cast(idx)]) { + (*_found)[static_cast(idx)] = true; + already_assigned = true; + static_cast( + ((idx == is ? (assign_one_field(_r, _var, _view, _errors), true) + : false) || + ...)); + } if constexpr (ViewType::pos_extra_fields() != -1) { constexpr int pos = ViewType::pos_extra_fields(); @@ -144,35 +198,6 @@ class ViewReaderWithDefault { } } - template - static void move_to(Target* _t, Source* _s) { - if constexpr (!rfl::internal::is_array_v && - !std::is_array_v) { - if constexpr (std::is_const_v) { - // The struct was default-constructed, so *_t is a live const object - // and must not be assigned to. Re-create it in place instead. If the - // constructor throws, we are inside a noexcept function, so it cannot - // be destroyed twice. - using NonConstTarget = std::remove_const_t; - auto* const ptr = const_cast(_t); - std::destroy_at(ptr); - ::new (ptr) NonConstTarget(std::move(*_s)); - } else { - *_t = Target(std::move(*_s)); - } - } else if constexpr (rfl::internal::is_array_v) { - static_assert(std::is_array_v, - "Expected target to be a c-array."); - for (size_t i = 0; i < _s->arr_.size(); ++i) { - move_to(&((*_t)[i]), &(_s->arr_[i])); - } - } else { - for (size_t i = 0; i < _s->size(); ++i) { - move_to(&((*_t)[i]), &((*_s)[i])); - } - } - } - private: /// The underlying reader. const R* r_; diff --git a/include/rfl/parsing/peel_transparent_wrappers.hpp b/include/rfl/parsing/peel_transparent_wrappers.hpp new file mode 100644 index 000000000..dc6022a93 --- /dev/null +++ b/include/rfl/parsing/peel_transparent_wrappers.hpp @@ -0,0 +1,152 @@ +#ifndef RFL_PARSING_PEEL_TRANSPARENT_WRAPPERS_HPP_ +#define RFL_PARSING_PEEL_TRANSPARENT_WRAPPERS_HPP_ + +#include +#include +#include +#include +#include + +#include "../DefaultVal.hpp" +#include "../internal/TransparentWrapper.hpp" +#include "../internal/always_inline.hpp" +#include "../internal/is_array.hpp" +#include "../internal/is_deprecated.hpp" +#include "../internal/is_description.hpp" +#include "../internal/is_positional.hpp" +#include "../internal/is_rename.hpp" +#include "../internal/is_short.hpp" +#include "FieldErrors.hpp" +#include "Parser_base.hpp" +#include "wrap_error.hpp" + +namespace rfl::parsing { + +template +struct is_default_val_wrapper : std::false_type {}; + +template +struct is_default_val_wrapper> : std::true_type {}; + +template +constexpr bool is_default_val_wrapper_v = + is_default_val_wrapper>::value; + +/// Whether T is a pure metadata/annotation wrapper whose Parser::read does +/// nothing except read `typename T::Type` and construct `T` from it. +template +constexpr bool is_peelable_read_wrapper_v = + rfl::internal::is_transparent_wrapper_v || + rfl::internal::is_description_v || rfl::internal::is_deprecated_v || + rfl::internal::is_short_v || rfl::internal::is_positional_v || + rfl::internal::is_rename_v || is_default_val_wrapper_v; + +/// Peels all pure metadata/annotation wrappers off T at compile time so that +/// fields with different help/group/short/value-name annotations share a single +/// `Parser::read` instantiation. +template +struct peel_transparent { + using CoreType = T; + static constexpr bool peeled = false; + static constexpr bool has_default_val = is_default_val_wrapper_v; + + static RFL_ALWAYS_INLINE T wrap(T&& _v) { return std::move(_v); } + static RFL_ALWAYS_INLINE CoreType& unwrap_ref(T& _t) noexcept { return _t; } +}; + +template + requires(is_peelable_read_wrapper_v && + !R::template has_custom_constructor) +struct peel_transparent { + using Inner = std::remove_cvref_t; + using Next = peel_transparent; + using CoreType = typename Next::CoreType; + static constexpr bool peeled = true; + static constexpr bool has_default_val = + is_default_val_wrapper_v || Next::has_default_val; + + static RFL_ALWAYS_INLINE T wrap(CoreType&& _v) { + return T(Next::wrap(std::move(_v))); + } + + static RFL_ALWAYS_INLINE CoreType& unwrap_ref(T& _t) noexcept { + return Next::unwrap_ref(_t.value()); + } +}; + +/// Move-assigns a parsed value into an already-constructed target field. +/// Free function (outside ViewReaderWithDefault) so instantiations never carry +/// the enclosing NamedTuple in their mangled symbol name or DWARF debug info. +template +RFL_ALWAYS_INLINE void move_assign_field(Target* _t, Source* _s) { + if constexpr (!rfl::internal::is_array_v && + !std::is_array_v) { + if constexpr (std::is_const_v) { + // The struct was default-constructed, so *_t is a live const object + // and must not be assigned to. Re-create it in place instead. If the + // constructor throws, we are inside a noexcept function, so it cannot + // be destroyed twice. + using NonConstTarget = std::remove_const_t; + auto* const ptr = const_cast(_t); + std::destroy_at(ptr); + ::new (ptr) NonConstTarget(std::move(*_s)); + } else { + *_t = Target(std::move(*_s)); + } + } else if constexpr (rfl::internal::is_array_v) { + static_assert(std::is_array_v, + "Expected target to be a c-array."); + for (size_t i = 0; i < _s->arr_.size(); ++i) { + move_assign_field(&((*_t)[i]), &(_s->arr_[i])); + } + } else { + for (size_t i = 0; i < _s->size(); ++i) { + move_assign_field(&((*_t)[i]), &((*_s)[i])); + } + } +} + +/// Placement-moves a parsed value into uninitialized target storage. +/// Free function (outside ViewReader) so instantiations never carry the +/// enclosing NamedTuple in their mangled symbol name or DWARF debug info. +template +RFL_ALWAYS_INLINE void placement_move_field(Target* _t, Source* _s) { + if constexpr (std::is_const_v) { + placement_move_field(const_cast*>(_t), _s); + } else if constexpr (!rfl::internal::is_array_v && + !std::is_array_v) { + ::new (_t) Target(std::move(*_s)); + } else if constexpr (rfl::internal::is_array_v) { + static_assert(std::is_array_v, + "Expected target to be a c-array."); + for (size_t i = 0; i < _s->arr_.size(); ++i) { + placement_move_field(&((*_t)[i]), &(_s->arr_[i])); + } + } else { + for (size_t i = 0; i < _s->size(); ++i) { + placement_move_field(&((*_t)[i]), &((*_s)[i])); + } + } +} + +/// Reads one field using only (R, W, CoreType, ProcessorsType) as template +/// arguments—never the enclosing ViewType—so all fields with the same unwrapped +/// CoreType share a single compiled Parser::read instantiation. +template +auto read_field_core(const R& _r, const typename R::InputVarType& _var, + const std::string_view _name, + FieldErrors* _errors, + const size_t _reserve_errors = 0) { + auto res = Parser::read(_r, _var); + if (!res) [[unlikely]] { + if (_reserve_errors != 0) { + _errors->reserve(_reserve_errors); + } + _errors->emplace_back(wrap_field_error(_name, std::move(res).error())); + } + return res; +} + +} // namespace rfl::parsing + +#endif