mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 08:46:19 +08:00
rename _res to _result to avoid macro conflict (#456)
This commit is contained in:
@@ -43,7 +43,7 @@ struct OneOf {
|
|||||||
static rfl::Result<T> validate_impl(const T& _value,
|
static rfl::Result<T> validate_impl(const T& _value,
|
||||||
std::vector<Error> _errors) {
|
std::vector<Error> _errors) {
|
||||||
return Head::validate(_value)
|
return Head::validate(_value)
|
||||||
.and_then([&](auto&& _res) -> rfl::Result<T> {
|
.and_then([&](auto&& _result) -> rfl::Result<T> {
|
||||||
if constexpr (sizeof...(Tail) == 0) {
|
if constexpr (sizeof...(Tail) == 0) {
|
||||||
if (_errors.size() == sizeof...(Cs)) {
|
if (_errors.size() == sizeof...(Cs)) {
|
||||||
return _value;
|
return _value;
|
||||||
|
|||||||
+40
-40
@@ -283,103 +283,103 @@ class Variant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class F, class ResultType, IndexType... _is>
|
template <class F, class ResultType, IndexType... _is>
|
||||||
void do_visit_with_result(F& _f, std::optional<ResultType>* _res,
|
void do_visit_with_result(F& _f, std::optional<ResultType>* _result,
|
||||||
std::integer_sequence<IndexType, _is...>) {
|
std::integer_sequence<IndexType, _is...>) {
|
||||||
auto visit_one = [this]<IndexType _i>(const F& _f,
|
auto visit_one = [this]<IndexType _i>(const F& _f,
|
||||||
std::optional<ResultType>* _res,
|
std::optional<ResultType>* _result,
|
||||||
Index<_i>) {
|
Index<_i>) {
|
||||||
if (!*_res && index_ == _i) {
|
if (!*_result && index_ == _i) {
|
||||||
_res->emplace(_f(get_alternative<_i>()));
|
_result->emplace(_f(get_alternative<_i>()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(visit_one(_f, _res, Index<_is>{}), ...);
|
(visit_one(_f, _result, Index<_is>{}), ...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class F, class ResultType, IndexType... _is>
|
template <class F, class ResultType, IndexType... _is>
|
||||||
void do_visit_with_result(F& _f, std::optional<ResultType>* _res,
|
void do_visit_with_result(F& _f, std::optional<ResultType>* _result,
|
||||||
std::integer_sequence<IndexType, _is...>) const {
|
std::integer_sequence<IndexType, _is...>) const {
|
||||||
auto visit_one = [this]<IndexType _i>(const F& _f,
|
auto visit_one = [this]<IndexType _i>(const F& _f,
|
||||||
std::optional<ResultType>* _res,
|
std::optional<ResultType>* _result,
|
||||||
Index<_i>) {
|
Index<_i>) {
|
||||||
if (!*_res && index_ == _i) {
|
if (!*_result && index_ == _i) {
|
||||||
_res->emplace(_f(get_alternative<_i>()));
|
_result->emplace(_f(get_alternative<_i>()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(visit_one(_f, _res, Index<_is>{}), ...);
|
(visit_one(_f, _result, Index<_is>{}), ...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class F, class ResultType, IndexType... _is>
|
template <class F, class ResultType, IndexType... _is>
|
||||||
void do_visit_with_result(const F& _f, std::optional<ResultType>* _res,
|
void do_visit_with_result(const F& _f, std::optional<ResultType>* _result,
|
||||||
std::integer_sequence<IndexType, _is...>) {
|
std::integer_sequence<IndexType, _is...>) {
|
||||||
const auto visit_one = [this]<IndexType _i>(const F& _f,
|
const auto visit_one = [this]<IndexType _i>(const F& _f,
|
||||||
std::optional<ResultType>* _res,
|
std::optional<ResultType>* _result,
|
||||||
Index<_i>) {
|
Index<_i>) {
|
||||||
if (!*_res && index_ == _i) {
|
if (!*_result && index_ == _i) {
|
||||||
_res->emplace(_f(get_alternative<_i>()));
|
_result->emplace(_f(get_alternative<_i>()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(visit_one(_f, _res, Index<_is>{}), ...);
|
(visit_one(_f, _result, Index<_is>{}), ...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class F, class ResultType, IndexType... _is>
|
template <class F, class ResultType, IndexType... _is>
|
||||||
void do_visit_with_result(const F& _f, std::optional<ResultType>* _res,
|
void do_visit_with_result(const F& _f, std::optional<ResultType>* _result,
|
||||||
std::integer_sequence<IndexType, _is...>) const {
|
std::integer_sequence<IndexType, _is...>) const {
|
||||||
const auto visit_one = [this]<IndexType _i>(const F& _f,
|
const auto visit_one = [this]<IndexType _i>(const F& _f,
|
||||||
std::optional<ResultType>* _res,
|
std::optional<ResultType>* _result,
|
||||||
Index<_i>) {
|
Index<_i>) {
|
||||||
if (!*_res && index_ == _i) {
|
if (!*_result && index_ == _i) {
|
||||||
_res->emplace(_f(get_alternative<_i>()));
|
_result->emplace(_f(get_alternative<_i>()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(visit_one(_f, _res, Index<_is>{}), ...);
|
(visit_one(_f, _result, Index<_is>{}), ...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class F, class ResultType, IndexType... _is>
|
template <class F, class ResultType, IndexType... _is>
|
||||||
void do_visit_with_reference(F& _f, ResultType** _res,
|
void do_visit_with_reference(F& _f, ResultType** _result,
|
||||||
std::integer_sequence<IndexType, _is...>) {
|
std::integer_sequence<IndexType, _is...>) {
|
||||||
const auto visit_one = [this]<IndexType _i>(const F& _f, ResultType** _res,
|
const auto visit_one = [this]<IndexType _i>(const F& _f, ResultType** _result,
|
||||||
Index<_i>) {
|
Index<_i>) {
|
||||||
if (!*_res && index_ == _i) {
|
if (!*_result && index_ == _i) {
|
||||||
*_res = &_f(get_alternative<_i>());
|
*_result = &_f(get_alternative<_i>());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(visit_one(_f, _res, Index<_is>{}), ...);
|
(visit_one(_f, _result, Index<_is>{}), ...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class F, class ResultType, IndexType... _is>
|
template <class F, class ResultType, IndexType... _is>
|
||||||
void do_visit_with_reference(F& _f, ResultType** _res,
|
void do_visit_with_reference(F& _f, ResultType** _result,
|
||||||
std::integer_sequence<IndexType, _is...>) const {
|
std::integer_sequence<IndexType, _is...>) const {
|
||||||
const auto visit_one = [this]<IndexType _i>(const F& _f, ResultType** _res,
|
const auto visit_one = [this]<IndexType _i>(const F& _f, ResultType** _result,
|
||||||
Index<_i>) {
|
Index<_i>) {
|
||||||
if (!*_res && index_ == _i) {
|
if (!*_result && index_ == _i) {
|
||||||
*_res = &_f(get_alternative<_i>());
|
*_result = &_f(get_alternative<_i>());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(visit_one(_f, _res, Index<_is>{}), ...);
|
(visit_one(_f, _result, Index<_is>{}), ...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class F, class ResultType, IndexType... _is>
|
template <class F, class ResultType, IndexType... _is>
|
||||||
void do_visit_with_reference(const F& _f, ResultType** _res,
|
void do_visit_with_reference(const F& _f, ResultType** _result,
|
||||||
std::integer_sequence<IndexType, _is...>) {
|
std::integer_sequence<IndexType, _is...>) {
|
||||||
const auto visit_one = [this]<IndexType _i>(const F& _f, ResultType** _res,
|
const auto visit_one = [this]<IndexType _i>(const F& _f, ResultType** _result,
|
||||||
Index<_i>) {
|
Index<_i>) {
|
||||||
if (!*_res && index_ == _i) {
|
if (!*_result && index_ == _i) {
|
||||||
*_res = &_f(get_alternative<_i>());
|
*_result = &_f(get_alternative<_i>());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(visit_one(_f, _res, Index<_is>{}), ...);
|
(visit_one(_f, _result, Index<_is>{}), ...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class F, class ResultType, IndexType... _is>
|
template <class F, class ResultType, IndexType... _is>
|
||||||
void do_visit_with_reference(const F& _f, ResultType** _res,
|
void do_visit_with_reference(const F& _f, ResultType** _result,
|
||||||
std::integer_sequence<IndexType, _is...>) const {
|
std::integer_sequence<IndexType, _is...>) const {
|
||||||
const auto visit_one = [this]<IndexType _i>(const F& _f, ResultType** _res,
|
const auto visit_one = [this]<IndexType _i>(const F& _f, ResultType** _result,
|
||||||
Index<_i>) {
|
Index<_i>) {
|
||||||
if (!*_res && index_ == _i) {
|
if (!*_result && index_ == _i) {
|
||||||
*_res = &_f(get_alternative<_i>());
|
*_result = &_f(get_alternative<_i>());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(visit_one(_f, _res, Index<_is>{}), ...);
|
(visit_one(_f, _result, Index<_is>{}), ...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <IndexType _i>
|
template <IndexType _i>
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ struct Parser<R, W, TaggedUnion<_discriminator, AlternativeTypes...>,
|
|||||||
static void set_if_disc_value_matches(const R& _r,
|
static void set_if_disc_value_matches(const R& _r,
|
||||||
const std::string& _disc_value,
|
const std::string& _disc_value,
|
||||||
const InputVarType& _var,
|
const InputVarType& _var,
|
||||||
ResultType* _res,
|
ResultType* _result,
|
||||||
bool* _match_found) noexcept {
|
bool* _match_found) noexcept {
|
||||||
using AlternativeType = std::remove_cvref_t<
|
using AlternativeType = std::remove_cvref_t<
|
||||||
std::variant_alternative_t<_i, std::variant<AlternativeTypes...>>>;
|
std::variant_alternative_t<_i, std::variant<AlternativeTypes...>>>;
|
||||||
@@ -156,12 +156,12 @@ struct Parser<R, W, TaggedUnion<_discriminator, AlternativeTypes...>,
|
|||||||
if constexpr (no_field_names_) {
|
if constexpr (no_field_names_) {
|
||||||
using T = tagged_union_wrapper_no_ptr_t<std::invoke_result_t<
|
using T = tagged_union_wrapper_no_ptr_t<std::invoke_result_t<
|
||||||
decltype(wrap_if_necessary<AlternativeType>), AlternativeType>>;
|
decltype(wrap_if_necessary<AlternativeType>), AlternativeType>>;
|
||||||
*_res = Parser<R, W, T, ProcessorsType>::read(_r, _var)
|
*_result = Parser<R, W, T, ProcessorsType>::read(_r, _var)
|
||||||
.transform(get_fields)
|
.transform(get_fields)
|
||||||
.transform(to_tagged_union)
|
.transform(to_tagged_union)
|
||||||
.transform_error(embellish_error);
|
.transform_error(embellish_error);
|
||||||
} else {
|
} else {
|
||||||
*_res = Parser<R, W, AlternativeType, ProcessorsType>::read(_r, _var)
|
*_result = Parser<R, W, AlternativeType, ProcessorsType>::read(_r, _var)
|
||||||
.transform(to_tagged_union)
|
.transform(to_tagged_union)
|
||||||
.transform_error(embellish_error);
|
.transform_error(embellish_error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user