Skip to content

Commit 29c4201

Browse files
Fix a subtle bug in rfl::to_view (#237)
1 parent 9755dda commit 29c4201

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

include/rfl/internal/bind_to_tuple.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef RFL_INTERNAL_BIND_TO_TUPLE_HPP_
22
#define RFL_INTERNAL_BIND_TO_TUPLE_HPP_
33

4+
#include <cassert>
45
#include <cstddef>
56
#include <iostream>
6-
#include <tuple>
77
#include <type_traits>
88
#include <utility>
99

@@ -42,8 +42,8 @@ struct tuple_view_helper<0> {
4242
n, ...) \
4343
template <> \
4444
struct tuple_view_helper<n> { \
45-
static auto tuple_view(auto& t) { \
46-
auto& [__VA_ARGS__] = t; \
45+
static auto tuple_view(auto& _t) { \
46+
auto& [__VA_ARGS__] = _t; \
4747
return [](auto&... _refs) { \
4848
return rfl::make_tuple(&_refs...); \
4949
}(__VA_ARGS__); \
@@ -2822,13 +2822,13 @@ RFL_INTERNAL_TUPLE_VIEW_IF_YOU_SEE_AN_ERROR_REFER_TO_DOCUMENTATION_ON_C_ARRAYS(
28222822
#undef RFL_INTERNAL_TUPLE_VIEW_IF_YOU_SEE_AN_ERROR_REFER_TO_DOCUMENTATION_ON_C_ARRAYS
28232823

28242824
template <class T>
2825-
auto tuple_view(T& t) {
2826-
return tuple_view_helper<num_fields<T>>::tuple_view(t);
2825+
auto bind_to_tuple(T& _t) {
2826+
return tuple_view_helper<num_fields<T>>::tuple_view(_t);
28272827
}
28282828

28292829
template <class T, typename F>
28302830
auto bind_to_tuple(T& _t, const F& _f) {
2831-
auto view = tuple_view(_t);
2831+
auto view = bind_to_tuple(_t);
28322832
return [&]<std::size_t... _is>(std::index_sequence<_is...>) {
28332833
return rfl::make_tuple(_f(rfl::get<_is>(view))...);
28342834
}

include/rfl/internal/to_flattened_ptr_tuple.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ namespace internal {
1414

1515
template <class PtrTuple>
1616
auto flatten_ptr_tuple(PtrTuple&& _t) {
17-
if constexpr (0 && !has_flatten_fields<PtrTuple>()) {
17+
if constexpr (!has_flatten_fields<PtrTuple>()) {
1818
return std::forward<PtrTuple>(_t);
1919
} else {
2020
const auto get_one = [&]<int _i>(std::integral_constant<int, _i>) {
2121
using T = tuple_element_t<_i, std::remove_cvref_t<PtrTuple>>;
2222
if constexpr (is_flatten_field_v<T>) {
23-
return flatten_ptr_tuple(to_ptr_tuple(std::get<_i>(_t)->get()));
23+
return flatten_ptr_tuple(to_ptr_tuple(rfl::get<_i>(_t)->get()));
2424
} else {
25-
return rfl::make_tuple(std::get<_i>(_t));
25+
return rfl::make_tuple(rfl::get<_i>(_t));
2626
}
2727
};
2828

include/rfl/internal/to_ptr_tuple.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ auto to_ptr_tuple(T& _t) {
1515
if constexpr (std::is_pointer_v<std::remove_cvref_t<T>>) {
1616
return to_ptr_tuple(*_t);
1717
} else {
18-
return bind_to_tuple(_t, [](auto* _ptr) { return _ptr; });
18+
return bind_to_tuple(_t);
1919
}
2020
}
2121

include/rfl/parsing/Parser_default.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ struct Parser {
277277
const InputVarType& _var) {
278278
auto t = T{};
279279
auto view = ProcessorsType::template process<T>(to_view(t));
280-
using ViewType = std::remove_cvref_t<decltype(view)>;
280+
using ViewType = decltype(view);
281281
const auto err =
282282
Parser<R, W, ViewType, ProcessorsType>::read_view_with_default(_r, _var,
283283
&view);

include/rfl/to_view.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define RFL_TO_VIEW_HPP_
33

44
#include <iostream>
5+
#include <stdexcept>
56
#include <tuple>
67
#include <type_traits>
78

0 commit comments

Comments
 (0)