Add rfl/internal/num_fields.hpp

This commit is contained in:
Txema Ynzenga
2023-12-06 16:05:25 +01:00
parent b3ce5d5ff7
commit 9944b743d0
2 changed files with 29 additions and 0 deletions
+1
View File
@@ -3,6 +3,7 @@
#include <cstddef>
#include <type_traits>
#include <utility>
namespace rfl {
namespace internal {
+28
View File
@@ -0,0 +1,28 @@
#ifndef RFL_INTERNAL_NUM_FIELDS_HPP_
#define RFL_INTERNAL_NUM_FIELDS_HPP_
#include <cstddef>
#include "rfl/internal/has_n_fields.hpp"
namespace rfl {
namespace internal {
template <class T, std::size_t _n>
struct num_fields_impl {
static constexpr std::size_t value = num_fields_impl<T, _n + 1>::value;
};
template <class T, std::size_t _n>
requires has_n_fields<T, _n>
struct num_fields_impl<T, _n> {
static constexpr std::size_t value = _n;
};
template <class T>
constexpr std::size_t num_fields = num_fields_impl<T, 0>::value;
} // namespace internal
} // namespace rfl
#endif