Merge pull request #19 from ChemiCalChems/reduce-boilerplate

Reduce boilerplate
This commit is contained in:
liuzicheng1987
2023-12-06 22:04:36 +01:00
committed by GitHub
5 changed files with 38 additions and 6413 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+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
+1 -1
View File
@@ -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>) {