Skip to content

Commit 517cf6e

Browse files
committed
Simplify container element parsing without forcing the parse helper inline
1 parent 18dad08 commit 517cf6e

1 file changed

Lines changed: 24 additions & 33 deletions

File tree

‎include/rfl/parsing/VectorReader.hpp‎

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ class VectorReader {
2222
using InputVarType = typename R::InputVarType;
2323
using T = typename VecType::value_type;
2424

25+
static constexpr auto parsed_type() {
26+
if constexpr (is_map_like_v<VecType>) {
27+
using K = std::remove_cvref_t<typename T::first_type>;
28+
using V = std::remove_cvref_t<typename T::second_type>;
29+
return std::type_identity<std::pair<K, V>>{};
30+
} else {
31+
return std::type_identity<std::remove_cvref_t<T>>{};
32+
}
33+
}
34+
35+
using ParsedType = typename decltype(parsed_type())::type;
36+
2537
public:
2638
/**
2739
* @brief Constructor.
@@ -53,42 +65,21 @@ class VectorReader {
5365
* @return An optional error.
5466
*/
5567
RFL_ALWAYS_INLINE std::optional<Error> read(const InputVarType& _var) const {
56-
const auto insert = [this](auto&& _var) -> std::optional<Error> {
57-
if constexpr (is_map_like_v<VecType> || is_set_like_v<VecType>) {
58-
vec_->insert(std::move(_var));
59-
} else if constexpr (is_inplace_vector_v<VecType>) {
60-
if (!vec_->try_emplace_back(std::move(_var))) {
61-
return Error("Too many elements, capacity is " +
62-
std::to_string(vec_->capacity()) + ".");
63-
}
64-
} else {
65-
vec_->emplace_back(std::move(_var));
66-
}
67-
return std::nullopt;
68-
};
69-
auto res = parse(_var).transform(insert);
70-
if (res) {
71-
return *res;
72-
} else {
73-
return res.error();
68+
auto res = Parser<R, W, ParsedType, ProcessorsType>::read(*r_, _var);
69+
if (!res) {
70+
return std::move(res).error();
7471
}
75-
// return parse(_var).transform(insert).error();
76-
}
77-
78-
private:
79-
RFL_ALWAYS_INLINE auto parse(const InputVarType& _var) const {
80-
if constexpr (is_map_like_v<VecType>) {
81-
return get_pair(_var);
72+
if constexpr (is_map_like_v<VecType> || is_set_like_v<VecType>) {
73+
vec_->insert(std::move(*res));
74+
} else if constexpr (is_inplace_vector_v<VecType>) {
75+
if (!vec_->try_emplace_back(std::move(*res))) {
76+
return Error("Too many elements, capacity is " +
77+
std::to_string(vec_->capacity()) + ".");
78+
}
8279
} else {
83-
return Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::read(*r_, _var);
80+
vec_->emplace_back(std::move(*res));
8481
}
85-
}
86-
87-
auto get_pair(const auto& _var) const {
88-
using K = std::remove_cvref_t<typename T::first_type>;
89-
using V = std::remove_cvref_t<typename T::second_type>;
90-
return Parser<R, W, std::remove_cvref_t<std::pair<K, V>>,
91-
ProcessorsType>::read(*r_, _var);
82+
return std::nullopt;
9283
}
9384

9485
private:

0 commit comments

Comments
 (0)