mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 08:46:19 +08:00
Apply 'composition over inheritance' to rfl::Array
This commit is contained in:
+11
-8
@@ -8,17 +8,20 @@
|
||||
namespace rfl {
|
||||
|
||||
template <class T>
|
||||
requires std::is_array_v<T>
|
||||
struct Array : internal::to_std_array_t<T> {
|
||||
requires std::is_array_v<T>
|
||||
struct Array {
|
||||
using Type = T;
|
||||
using Base = internal::to_std_array_t<T>;
|
||||
using Base::Base;
|
||||
using StdArrayType = internal::to_std_array_t<T>;
|
||||
|
||||
Array() = default;
|
||||
Array(const Base &t) : Base(t) {}
|
||||
Array(Base &&t) : Base(std::move(t)) {}
|
||||
Array(const T &t) : Base(reinterpret_cast<const Base &>(t)) {}
|
||||
Array(T &&t) : Base(reinterpret_cast<Base &&>(t)) {}
|
||||
Array(const StdArrayType &_arr) : arr_(_arr) {}
|
||||
Array(StdArrayType &&_arr) : arr_(std::move(_arr)) {}
|
||||
Array(const T &_t) : arr_(reinterpret_cast<const StdArrayType &>(_t)) {}
|
||||
Array(T &&_t) : arr_(reinterpret_cast<StdArrayType &&>(_t)) {}
|
||||
|
||||
~Array() = default;
|
||||
|
||||
StdArrayType arr_;
|
||||
};
|
||||
|
||||
} // namespace rfl
|
||||
|
||||
@@ -32,7 +32,7 @@ struct Parser<R, W, Array<T>> {
|
||||
template <class P>
|
||||
static void write(const W& _w, const Array<T>& _arr,
|
||||
const P& _parent) noexcept {
|
||||
Parser<R, W, StdArray>::write(_w, _arr, _parent);
|
||||
Parser<R, W, StdArray>::write(_w, _arr.arr_, _parent);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user