2
0
mirror of https://github.com/boostorg/pfr.git synced 2026-01-19 04:22:13 +00:00

Make for_each_field() constexpr for c++17 (#134)

#127
This commit is contained in:
Alexander Karatarakis
2023-08-12 00:43:20 -07:00
committed by GitHub
parent 674f3723c5
commit b5e523f2b3
4 changed files with 23 additions and 8 deletions

View File

@@ -56,6 +56,21 @@ struct simple {
struct empty{};
#if BOOST_PFR_USE_CPP17
constexpr std::size_t get_field_count_through_for_each_field() {
std::size_t counter = 0;
boost::pfr::for_each_field(simple{}, [&counter](auto&& /*val*/, std::size_t /*i*/) {
++ counter;
});
return counter;
}
// MSVC-14.1 fails to compile the following code
#if !defined(_MSC_VER) || _MSC_VER > 1916
static_assert(3 == get_field_count_through_for_each_field());
#endif
#endif
int main () {
std::size_t control = 0;