mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-06 10:46:18 +08:00
Optimizationg for the reader and writer; #68
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define RFL_INTERNAL_ARRAY_HPP_
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
#include "to_std_array.hpp"
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef RFL_INTERNAL_ISARRAY_HPP_
|
||||
#define RFL_INTERNAL_ISARRAY_HPP_
|
||||
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "Array.hpp"
|
||||
|
||||
namespace rfl::internal {
|
||||
|
||||
template <class T>
|
||||
class is_array;
|
||||
|
||||
template <class T>
|
||||
class is_array : public std::false_type {};
|
||||
|
||||
template <class Type>
|
||||
class is_array<Array<Type>> : public std::true_type {};
|
||||
|
||||
template <class T>
|
||||
constexpr bool is_array_v =
|
||||
is_array<std::remove_cvref_t<std::remove_pointer_t<T>>>::value;
|
||||
|
||||
} // namespace rfl::internal
|
||||
|
||||
#endif
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "../always_false.hpp"
|
||||
#include "../field_names_t.hpp"
|
||||
#include "../make_named_tuple.hpp"
|
||||
#include "copy_flattened_tuple_to_named_tuple.hpp"
|
||||
#include "has_fields.hpp"
|
||||
#include "has_flatten_fields.hpp"
|
||||
@@ -13,7 +14,6 @@
|
||||
#include "is_named_tuple.hpp"
|
||||
#include "to_flattened_ptr_tuple.hpp"
|
||||
#include "to_ptr_field_tuple.hpp"
|
||||
#include "../make_named_tuple.hpp"
|
||||
|
||||
namespace rfl {
|
||||
namespace internal {
|
||||
@@ -26,8 +26,7 @@ auto flatten_ptr_field_tuple(PtrFieldTuple& _t, Args&&... _args) {
|
||||
} else {
|
||||
using T = std::tuple_element_t<i, std::remove_cvref_t<PtrFieldTuple>>;
|
||||
if constexpr (internal::is_flatten_field<T>::value) {
|
||||
const auto subtuple =
|
||||
internal::to_ptr_field_tuple(*std::get<i>(_t).get());
|
||||
auto subtuple = internal::to_ptr_field_tuple(*std::get<i>(_t).get());
|
||||
return flatten_ptr_field_tuple(_t, std::forward<Args>(_args)...,
|
||||
flatten_ptr_field_tuple(subtuple));
|
||||
} else {
|
||||
@@ -39,7 +38,7 @@ auto flatten_ptr_field_tuple(PtrFieldTuple& _t, Args&&... _args) {
|
||||
|
||||
template <class PtrFieldTuple>
|
||||
auto field_tuple_to_named_tuple(PtrFieldTuple& _ptr_field_tuple) {
|
||||
const auto ft_to_nt = []<class... Fields>(const Fields&... _fields) {
|
||||
const auto ft_to_nt = []<class... Fields>(Fields&&... _fields) {
|
||||
return make_named_tuple(_fields...);
|
||||
};
|
||||
|
||||
|
||||
@@ -15,9 +15,7 @@ constexpr auto to_ptr_tuple(T& _t) {
|
||||
if constexpr (std::is_pointer_v<std::remove_cvref_t<T>>) {
|
||||
return to_ptr_tuple(*_t);
|
||||
} else {
|
||||
return bind_to_tuple(_t, [](auto&& x) {
|
||||
return std::addressof(std::forward<decltype(x)>(x));
|
||||
});
|
||||
return bind_to_tuple(_t, [](auto& x) { return &x; });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user