Skip to content

core: add an implementation based on C++26 destructuring into a pack #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jcelerier
Copy link
Contributor

@jcelerier jcelerier commented Mar 2, 2025

Tested with clang-21 HEAD which supports destructuring into a pack and pack indexing <3

I don't know how to use b2 / jam so I added some of the tests with CMake, however that excludes

  • the tests that use the BOOST_PFR_RUN_TEST_ON macro feature
  • test/core/run/huge_count.cpp which eats more ram than I have and gets oom-killed ?
  • all the "compile-fail" tests
[0/1] Running tests...
Test project /home/jcelerier/projets/oss/boost/pfr/build-clang21
      Start  1: _home_jcelerier_projets_oss_boost_pfr_test_config_print_config_cpp
 1/53 Test  #1: _home_jcelerier_projets_oss_boost_pfr_test_config_print_config_cpp .............................................   Passed    0.00 sec
      Start  2: _home_jcelerier_projets_oss_boost_pfr_test_core_can_be_as_fallback_in_the_fusion_cpp
 2/53 Test  #2: _home_jcelerier_projets_oss_boost_pfr_test_core_can_be_as_fallback_in_the_fusion_cpp ...........................   Passed    0.00 sec
      Start  3: _home_jcelerier_projets_oss_boost_pfr_test_core_fields_count_on_incomplete_type_cpp
 3/53 Test  #3: _home_jcelerier_projets_oss_boost_pfr_test_core_fields_count_on_incomplete_type_cpp ............................   Passed    0.00 sec
      Start  4: _home_jcelerier_projets_oss_boost_pfr_test_core_loophole_detection_cpp
 4/53 Test  #4: _home_jcelerier_projets_oss_boost_pfr_test_core_loophole_detection_cpp .........................................   Passed    0.00 sec
      Start  5: _home_jcelerier_projets_oss_boost_pfr_test_core_offset_based_getter_cpp
 5/53 Test  #5: _home_jcelerier_projets_oss_boost_pfr_test_core_offset_based_getter_cpp ........................................   Passed    0.00 sec
      Start  6: _home_jcelerier_projets_oss_boost_pfr_test_core_run_bitfields_count_cpp
 6/53 Test  #6: _home_jcelerier_projets_oss_boost_pfr_test_core_run_bitfields_count_cpp ........................................   Passed    0.00 sec
      Start  7: _home_jcelerier_projets_oss_boost_pfr_test_core_run_constexpr_ops_cpp
 7/53 Test  #7: _home_jcelerier_projets_oss_boost_pfr_test_core_run_constexpr_ops_cpp ..........................................   Passed    0.00 sec
      Start  8: _home_jcelerier_projets_oss_boost_pfr_test_core_run_core17_generated_cpp
 8/53 Test  #8: _home_jcelerier_projets_oss_boost_pfr_test_core_run_core17_generated_cpp .......................................   Passed    0.00 sec
      Start  9: _home_jcelerier_projets_oss_boost_pfr_test_core_run_destructuring_tie_cpp
 9/53 Test  #9: _home_jcelerier_projets_oss_boost_pfr_test_core_run_destructuring_tie_cpp ......................................   Passed    0.00 sec
      Start 10: _home_jcelerier_projets_oss_boost_pfr_test_core_run_error_pfr_c1202_cpp
10/53 Test #10: _home_jcelerier_projets_oss_boost_pfr_test_core_run_error_pfr_c1202_cpp ........................................   Passed    0.00 sec
      Start 11: _home_jcelerier_projets_oss_boost_pfr_test_core_run_fields_count_on_const_cpp
11/53 Test #11: _home_jcelerier_projets_oss_boost_pfr_test_core_run_fields_count_on_const_cpp ..................................   Passed    0.00 sec
      Start 12: _home_jcelerier_projets_oss_boost_pfr_test_core_run_for_each_field_cpp
12/53 Test #12: _home_jcelerier_projets_oss_boost_pfr_test_core_run_for_each_field_cpp .........................................   Passed    0.00 sec
      Start 13: _home_jcelerier_projets_oss_boost_pfr_test_core_run_functions_for_cpp
13/53 Test #13: _home_jcelerier_projets_oss_boost_pfr_test_core_run_functions_for_cpp ..........................................   Passed    0.00 sec
      Start 14: _home_jcelerier_projets_oss_boost_pfr_test_core_run_get_by_type_cpp
14/53 Test #14: _home_jcelerier_projets_oss_boost_pfr_test_core_run_get_by_type_cpp ............................................   Passed    0.00 sec
      Start 15: _home_jcelerier_projets_oss_boost_pfr_test_core_run_get_const_field_cpp
15/53 Test #15: _home_jcelerier_projets_oss_boost_pfr_test_core_run_get_const_field_cpp ........................................   Passed    0.00 sec
      Start 16: _home_jcelerier_projets_oss_boost_pfr_test_core_run_get_non_default_constructible_cpp
16/53 Test #16: _home_jcelerier_projets_oss_boost_pfr_test_core_run_get_non_default_constructible_cpp ..........................   Passed    0.00 sec
      Start 17: _home_jcelerier_projets_oss_boost_pfr_test_core_run_get_rvalue_cpp
17/53 Test #17: _home_jcelerier_projets_oss_boost_pfr_test_core_run_get_rvalue_cpp .............................................   Passed    0.00 sec
      Start 18: _home_jcelerier_projets_oss_boost_pfr_test_core_run_huge_count_cpp
18/53 Test #18: _home_jcelerier_projets_oss_boost_pfr_test_core_run_huge_count_cpp .............................................   Passed    0.00 sec
      Start 19: _home_jcelerier_projets_oss_boost_pfr_test_core_run_is_implicitly_reflectable_cpp
19/53 Test #19: _home_jcelerier_projets_oss_boost_pfr_test_core_run_is_implicitly_reflectable_cpp ..............................   Passed    0.00 sec
      Start 20: _home_jcelerier_projets_oss_boost_pfr_test_core_run_is_reflectable_cpp
20/53 Test #20: _home_jcelerier_projets_oss_boost_pfr_test_core_run_is_reflectable_cpp .........................................   Passed    0.00 sec
      Start 21: _home_jcelerier_projets_oss_boost_pfr_test_core_run_issue30_cpp
21/53 Test #21: _home_jcelerier_projets_oss_boost_pfr_test_core_run_issue30_cpp ................................................   Passed    0.00 sec
      Start 22: _home_jcelerier_projets_oss_boost_pfr_test_core_run_issue33_cpp
22/53 Test #22: _home_jcelerier_projets_oss_boost_pfr_test_core_run_issue33_cpp ................................................   Passed    0.00 sec
      Start 23: _home_jcelerier_projets_oss_boost_pfr_test_core_run_many_fields_count_cpp
23/53 Test #23: _home_jcelerier_projets_oss_boost_pfr_test_core_run_many_fields_count_cpp ......................................   Passed    0.00 sec
      Start 24: _home_jcelerier_projets_oss_boost_pfr_test_core_run_motivating_example_cpp
24/53 Test #24: _home_jcelerier_projets_oss_boost_pfr_test_core_run_motivating_example_cpp .....................................   Passed    0.00 sec
      Start 25: _home_jcelerier_projets_oss_boost_pfr_test_core_run_motivating_example2_cpp
25/53 Test #25: _home_jcelerier_projets_oss_boost_pfr_test_core_run_motivating_example2_cpp ....................................   Passed    0.00 sec
      Start 26: _home_jcelerier_projets_oss_boost_pfr_test_core_run_non_copyable_but_movable_cpp
26/53 Test #26: _home_jcelerier_projets_oss_boost_pfr_test_core_run_non_copyable_but_movable_cpp ...............................   Passed    0.00 sec
      Start 27: _home_jcelerier_projets_oss_boost_pfr_test_core_run_non_dc_non_cop_but_mov_cpp
27/53 Test #27: _home_jcelerier_projets_oss_boost_pfr_test_core_run_non_dc_non_cop_but_mov_cpp .................................   Passed    0.00 sec
      Start 28: _home_jcelerier_projets_oss_boost_pfr_test_core_run_non_default_constructible_cpp
28/53 Test #28: _home_jcelerier_projets_oss_boost_pfr_test_core_run_non_default_constructible_cpp ..............................   Passed    0.00 sec
      Start 29: _home_jcelerier_projets_oss_boost_pfr_test_core_run_non_movable_cpp
29/53 Test #29: _home_jcelerier_projets_oss_boost_pfr_test_core_run_non_movable_cpp ............................................   Passed    0.00 sec
      Start 30: _home_jcelerier_projets_oss_boost_pfr_test_core_run_non_std_layout_cpp
30/53 Test #30: _home_jcelerier_projets_oss_boost_pfr_test_core_run_non_std_layout_cpp .........................................   Passed    0.00 sec
      Start 31: _home_jcelerier_projets_oss_boost_pfr_test_core_run_ops_cpp
31/53 Test #31: _home_jcelerier_projets_oss_boost_pfr_test_core_run_ops_cpp ....................................................   Passed    0.00 sec
      Start 32: _home_jcelerier_projets_oss_boost_pfr_test_core_run_optional_chrono_cpp
32/53 Test #32: _home_jcelerier_projets_oss_boost_pfr_test_core_run_optional_chrono_cpp ........................................   Passed    0.00 sec
      Start 33: _home_jcelerier_projets_oss_boost_pfr_test_core_run_optional_like_cpp
33/53 Test #33: _home_jcelerier_projets_oss_boost_pfr_test_core_run_optional_like_cpp ..........................................   Passed    0.00 sec
      Start 34: _home_jcelerier_projets_oss_boost_pfr_test_core_run_read_write_cpp
34/53 Test #34: _home_jcelerier_projets_oss_boost_pfr_test_core_run_read_write_cpp .............................................   Passed    0.00 sec
      Start 35: _home_jcelerier_projets_oss_boost_pfr_test_core_run_read_write_non_literal_cpp
35/53 Test #35: _home_jcelerier_projets_oss_boost_pfr_test_core_run_read_write_non_literal_cpp .................................   Passed    0.00 sec
      Start 36: _home_jcelerier_projets_oss_boost_pfr_test_core_run_std_interactions_cpp
36/53 Test #36: _home_jcelerier_projets_oss_boost_pfr_test_core_run_std_interactions_cpp .......................................   Passed    0.00 sec
      Start 37: _home_jcelerier_projets_oss_boost_pfr_test_core_run_structure_to_tuple_cpp
37/53 Test #37: _home_jcelerier_projets_oss_boost_pfr_test_core_run_structure_to_tuple_cpp .....................................   Passed    0.00 sec
      Start 38: _home_jcelerier_projets_oss_boost_pfr_test_core_run_template_constructor_cpp
38/53 Test #38: _home_jcelerier_projets_oss_boost_pfr_test_core_run_template_constructor_cpp ...................................   Passed    0.00 sec
      Start 39: _home_jcelerier_projets_oss_boost_pfr_test_core_run_template_forwarding_ref_cpp
39/53 Test #39: _home_jcelerier_projets_oss_boost_pfr_test_core_run_template_forwarding_ref_cpp ................................   Passed    0.00 sec
      Start 40: _home_jcelerier_projets_oss_boost_pfr_test_core_run_template_unconstrained_cpp
40/53 Test #40: _home_jcelerier_projets_oss_boost_pfr_test_core_run_template_unconstrained_cpp .................................   Passed    0.00 sec
      Start 41: _home_jcelerier_projets_oss_boost_pfr_test_core_run_tie_anonymous_cpp
41/53 Test #41: _home_jcelerier_projets_oss_boost_pfr_test_core_run_tie_anonymous_cpp ..........................................   Passed    0.00 sec
      Start 42: _home_jcelerier_projets_oss_boost_pfr_test_core_run_tie_anonymous_const_field_cpp
42/53 Test #42: _home_jcelerier_projets_oss_boost_pfr_test_core_run_tie_anonymous_const_field_cpp ..............................   Passed    0.00 sec
      Start 43: _home_jcelerier_projets_oss_boost_pfr_test_core_run_tuple_size_cpp
43/53 Test #43: _home_jcelerier_projets_oss_boost_pfr_test_core_run_tuple_size_cpp .............................................   Passed    0.00 sec
      Start 44: _home_jcelerier_projets_oss_boost_pfr_test_core_test_tuple_sizes_on_cpp
44/53 Test #44: _home_jcelerier_projets_oss_boost_pfr_test_core_test_tuple_sizes_on_cpp ........................................   Passed    0.00 sec
      Start 45: _home_jcelerier_projets_oss_boost_pfr_test_core_name_cxx20_address_of_non_static_member_tplarg_detection_cpp
45/53 Test #45: _home_jcelerier_projets_oss_boost_pfr_test_core_name_cxx20_address_of_non_static_member_tplarg_detection_cpp ...   Passed    0.00 sec
      Start 46: _home_jcelerier_projets_oss_boost_pfr_test_core_name_cxx20_nontype_tplarg_detection_cpp
46/53 Test #46: _home_jcelerier_projets_oss_boost_pfr_test_core_name_cxx20_nontype_tplarg_detection_cpp ........................   Passed    0.00 sec
      Start 47: _home_jcelerier_projets_oss_boost_pfr_test_core_name_print_name_cpp
47/53 Test #47: _home_jcelerier_projets_oss_boost_pfr_test_core_name_print_name_cpp ............................................   Passed    0.00 sec
      Start 48: _home_jcelerier_projets_oss_boost_pfr_test_core_name_run_fields_names_cpp
48/53 Test #48: _home_jcelerier_projets_oss_boost_pfr_test_core_name_run_fields_names_cpp ......................................   Passed    0.00 sec
      Start 49: _home_jcelerier_projets_oss_boost_pfr_test_core_name_run_fields_names_big_cpp
49/53 Test #49: _home_jcelerier_projets_oss_boost_pfr_test_core_name_run_fields_names_big_cpp ..................................   Passed    0.00 sec
      Start 50: _home_jcelerier_projets_oss_boost_pfr_test_core_name_run_fields_names_constexpr_cpp
50/53 Test #50: _home_jcelerier_projets_oss_boost_pfr_test_core_name_run_fields_names_constexpr_cpp ............................   Passed    0.00 sec
      Start 51: _home_jcelerier_projets_oss_boost_pfr_test_core_name_run_fields_names_internal_parser_cpp
51/53 Test #51: _home_jcelerier_projets_oss_boost_pfr_test_core_name_run_fields_names_internal_parser_cpp ......................   Passed    0.00 sec
      Start 52: _home_jcelerier_projets_oss_boost_pfr_test_core_name_run_fields_names_nonascii_cpp
52/53 Test #52: _home_jcelerier_projets_oss_boost_pfr_test_core_name_run_fields_names_nonascii_cpp .............................   Passed    0.00 sec
      Start 53: _home_jcelerier_projets_oss_boost_pfr_test_core_name_run_for_each_field_with_name_cpp
53/53 Test #53: _home_jcelerier_projets_oss_boost_pfr_test_core_name_run_for_each_field_with_name_cpp ..........................   Passed    0.00 sec

100% tests passed, 0 tests failed out of 53

@jcelerier
Copy link
Contributor Author

I'd like to add such a CI configuration, though IDK if there is some github action or VM that easily provides clang@HEAD?

@coveralls
Copy link

Pull Request Test Coverage Report for Build 13617014832

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 12675824451: 0.0%
Covered Lines: 407
Relevant Lines: 407

💛 - Coveralls

return std::forward_like<const T &>(members...[I]);
#else
return detail::sequence_tuple::get<I>(detail::tie_as_tuple(val));
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant change, please remove it. You've already implemented detail::tie_as_tuple which is responsible for that

return detail::sequence_tuple::get<I>( detail::tie_as_tuple(val) );
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant change, please remove it. You've already implemented detail::tie_as_tuple which is responsible for that

return std::move(detail::sequence_tuple::get<I>( detail::tie_as_tuple(val) ));
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant change, please remove it. You've already implemented detail::tie_as_tuple which is responsible for that

return detail::make_stdtuple_from_tietuple(
detail::tie_as_tuple(val),
detail::make_index_sequence< tuple_size_v<T> >()
);
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant change, please remove it. You've already implemented detail::tie_as_tuple which is responsible for that

return detail::make_conststdtiedtuple_from_tietuple(
detail::tie_as_tuple(const_cast<T&>(val)),
detail::make_index_sequence< tuple_size_v<T> >()
);
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant change, please remove it. You've already implemented detail::tie_as_tuple which is responsible for that

);
#if BOOST_PFR_USE_CPP26
auto &[... members] = val;
return std::tie(std::forward_like<T &>(members)...);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant change, please remove it. You've already implemented detail::tie_as_tuple which is responsible for that

auto &&[... members] = std::forward<T>(val);
return sequence_tuple::tuple<std::add_lvalue_reference_t<decltype(members)>...>{members...};
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement for_each_field_dispatcher in order to fit the core interface.

std::make_index_sequence<1>{},
std::is_rvalue_reference<T &&>{});
}
#else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant change, please remove it. You should implement detail::for_each_field_dispatcher as it discussed in another thread, which is responsible for that.

@@ -23,6 +23,43 @@ namespace boost { namespace pfr { namespace detail {
template <std::size_t Index>
using size_t_ = std::integral_constant<std::size_t, Index >;

#if BOOST_PFR_USE_CPP26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It becomens redundat having you removed the change in for_each_field.hpp. Please remove this change too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants