Fix a subtle bug in rfl::to_view (#237)

This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2024-10-29 20:24:36 +01:00
committed by GitHub
parent 9755dda7c6
commit 29c42010a3
5 changed files with 12 additions and 11 deletions
+6 -6
View File
@@ -1,9 +1,9 @@
#ifndef RFL_INTERNAL_BIND_TO_TUPLE_HPP_
#define RFL_INTERNAL_BIND_TO_TUPLE_HPP_
#include <cassert>
#include <cstddef>
#include <iostream>
#include <tuple>
#include <type_traits>
#include <utility>
@@ -42,8 +42,8 @@ struct tuple_view_helper<0> {
n, ...) \
template <> \
struct tuple_view_helper<n> { \
static auto tuple_view(auto& t) { \
auto& [__VA_ARGS__] = t; \
static auto tuple_view(auto& _t) { \
auto& [__VA_ARGS__] = _t; \
return [](auto&... _refs) { \
return rfl::make_tuple(&_refs...); \
}(__VA_ARGS__); \
@@ -2822,13 +2822,13 @@ RFL_INTERNAL_TUPLE_VIEW_IF_YOU_SEE_AN_ERROR_REFER_TO_DOCUMENTATION_ON_C_ARRAYS(
#undef RFL_INTERNAL_TUPLE_VIEW_IF_YOU_SEE_AN_ERROR_REFER_TO_DOCUMENTATION_ON_C_ARRAYS
template <class T>
auto tuple_view(T& t) {
return tuple_view_helper<num_fields<T>>::tuple_view(t);
auto bind_to_tuple(T& _t) {
return tuple_view_helper<num_fields<T>>::tuple_view(_t);
}
template <class T, typename F>
auto bind_to_tuple(T& _t, const F& _f) {
auto view = tuple_view(_t);
auto view = bind_to_tuple(_t);
return [&]<std::size_t... _is>(std::index_sequence<_is...>) {
return rfl::make_tuple(_f(rfl::get<_is>(view))...);
}
@@ -14,15 +14,15 @@ namespace internal {
template <class PtrTuple>
auto flatten_ptr_tuple(PtrTuple&& _t) {
if constexpr (0 && !has_flatten_fields<PtrTuple>()) {
if constexpr (!has_flatten_fields<PtrTuple>()) {
return std::forward<PtrTuple>(_t);
} else {
const auto get_one = [&]<int _i>(std::integral_constant<int, _i>) {
using T = tuple_element_t<_i, std::remove_cvref_t<PtrTuple>>;
if constexpr (is_flatten_field_v<T>) {
return flatten_ptr_tuple(to_ptr_tuple(std::get<_i>(_t)->get()));
return flatten_ptr_tuple(to_ptr_tuple(rfl::get<_i>(_t)->get()));
} else {
return rfl::make_tuple(std::get<_i>(_t));
return rfl::make_tuple(rfl::get<_i>(_t));
}
};
+1 -1
View File
@@ -15,7 +15,7 @@ auto to_ptr_tuple(T& _t) {
if constexpr (std::is_pointer_v<std::remove_cvref_t<T>>) {
return to_ptr_tuple(*_t);
} else {
return bind_to_tuple(_t, [](auto* _ptr) { return _ptr; });
return bind_to_tuple(_t);
}
}
+1 -1
View File
@@ -277,7 +277,7 @@ struct Parser {
const InputVarType& _var) {
auto t = T{};
auto view = ProcessorsType::template process<T>(to_view(t));
using ViewType = std::remove_cvref_t<decltype(view)>;
using ViewType = decltype(view);
const auto err =
Parser<R, W, ViewType, ProcessorsType>::read_view_with_default(_r, _var,
&view);
+1
View File
@@ -2,6 +2,7 @@
#define RFL_TO_VIEW_HPP_
#include <iostream>
#include <stdexcept>
#include <tuple>
#include <type_traits>