mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-02 16:16:19 +08:00
Merge pull request #19 from ChemiCalChems/reduce-boilerplate
Reduce boilerplate
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace rfl {
|
||||
namespace internal {
|
||||
|
||||
@@ -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
|
||||
@@ -37,7 +37,7 @@ with open("generated_code4.cpp", "w", encoding="utf-8") as codefile:
|
||||
*/
|
||||
|
||||
template <class T>
|
||||
auto to_ptr_tuple(const T& _t) {
|
||||
constexpr auto to_ptr_tuple(const T& _t) {
|
||||
if constexpr (std::is_pointer_v<std::decay_t<T>>) {
|
||||
return to_ptr_tuple(*_t);
|
||||
} else if constexpr (has_n_fields<T, 0>) {
|
||||
|
||||
Reference in New Issue
Block a user