mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 16:56:17 +08:00
Change all decay to remove_cvref.
This commit is contained in:
+154
-156
@@ -21,66 +21,64 @@ struct Getter;
|
||||
/// Default case - anything that cannot be explicitly matched.
|
||||
template <class NamedTupleType>
|
||||
struct Getter {
|
||||
public:
|
||||
/// Retrieves the indicated value from the tuple.
|
||||
template <int _index>
|
||||
static inline auto& get(NamedTupleType& _tup) {
|
||||
return std::get<_index>(_tup.values());
|
||||
}
|
||||
public:
|
||||
/// Retrieves the indicated value from the tuple.
|
||||
template <int _index>
|
||||
static inline auto& get(NamedTupleType& _tup) {
|
||||
return std::get<_index>(_tup.values());
|
||||
}
|
||||
|
||||
/// Gets a field by name.
|
||||
template <StringLiteral _field_name>
|
||||
static inline auto& get(NamedTupleType& _tup) {
|
||||
constexpr auto index =
|
||||
find_index<_field_name, typename NamedTupleType::Fields>();
|
||||
return Getter<NamedTupleType>::template get<index>(_tup);
|
||||
}
|
||||
/// Gets a field by name.
|
||||
template <StringLiteral _field_name>
|
||||
static inline auto& get(NamedTupleType& _tup) {
|
||||
constexpr auto index =
|
||||
find_index<_field_name, typename NamedTupleType::Fields>();
|
||||
return Getter<NamedTupleType>::template get<index>(_tup);
|
||||
}
|
||||
|
||||
/// Gets a field by the field type.
|
||||
template <class Field>
|
||||
static inline auto& get(NamedTupleType& _tup) {
|
||||
constexpr auto index =
|
||||
find_index<Field::name_, typename NamedTupleType::Fields>();
|
||||
static_assert(
|
||||
std::is_same<
|
||||
typename std::tuple_element<
|
||||
index, typename NamedTupleType::Fields>::type::Type,
|
||||
typename Field::Type>(),
|
||||
"If two fields have the same name, "
|
||||
"their type must be the same as "
|
||||
"well.");
|
||||
return Getter<NamedTupleType>::template get<index>(_tup);
|
||||
}
|
||||
/// Gets a field by the field type.
|
||||
template <class Field>
|
||||
static inline auto& get(NamedTupleType& _tup) {
|
||||
constexpr auto index =
|
||||
find_index<Field::name_, typename NamedTupleType::Fields>();
|
||||
static_assert(
|
||||
std::is_same<typename std::tuple_element<
|
||||
index, typename NamedTupleType::Fields>::type::Type,
|
||||
typename Field::Type>(),
|
||||
"If two fields have the same name, "
|
||||
"their type must be the same as "
|
||||
"well.");
|
||||
return Getter<NamedTupleType>::template get<index>(_tup);
|
||||
}
|
||||
|
||||
/// Retrieves the indicated value from the tuple.
|
||||
template <int _index>
|
||||
static inline const auto& get_const(const NamedTupleType& _tup) {
|
||||
return std::get<_index>(_tup.values());
|
||||
}
|
||||
/// Retrieves the indicated value from the tuple.
|
||||
template <int _index>
|
||||
static inline const auto& get_const(const NamedTupleType& _tup) {
|
||||
return std::get<_index>(_tup.values());
|
||||
}
|
||||
|
||||
/// Gets a field by name.
|
||||
template <StringLiteral _field_name>
|
||||
static inline const auto& get_const(const NamedTupleType& _tup) {
|
||||
constexpr auto index =
|
||||
find_index<_field_name, typename NamedTupleType::Fields>();
|
||||
return Getter<NamedTupleType>::template get_const<index>(_tup);
|
||||
}
|
||||
/// Gets a field by name.
|
||||
template <StringLiteral _field_name>
|
||||
static inline const auto& get_const(const NamedTupleType& _tup) {
|
||||
constexpr auto index =
|
||||
find_index<_field_name, typename NamedTupleType::Fields>();
|
||||
return Getter<NamedTupleType>::template get_const<index>(_tup);
|
||||
}
|
||||
|
||||
/// Gets a field by the field type.
|
||||
template <class Field>
|
||||
static inline const auto& get_const(const NamedTupleType& _tup) {
|
||||
constexpr auto index =
|
||||
find_index<Field::name_, typename NamedTupleType::Fields>();
|
||||
static_assert(
|
||||
std::is_same<
|
||||
typename std::tuple_element<
|
||||
index, typename NamedTupleType::Fields>::type::Type,
|
||||
typename Field::Type>(),
|
||||
"If two fields have the same name, "
|
||||
"their type must be the same as "
|
||||
"well.");
|
||||
return Getter<NamedTupleType>::template get_const<index>(_tup);
|
||||
}
|
||||
/// Gets a field by the field type.
|
||||
template <class Field>
|
||||
static inline const auto& get_const(const NamedTupleType& _tup) {
|
||||
constexpr auto index =
|
||||
find_index<Field::name_, typename NamedTupleType::Fields>();
|
||||
static_assert(
|
||||
std::is_same<typename std::tuple_element<
|
||||
index, typename NamedTupleType::Fields>::type::Type,
|
||||
typename Field::Type>(),
|
||||
"If two fields have the same name, "
|
||||
"their type must be the same as "
|
||||
"well.");
|
||||
return Getter<NamedTupleType>::template get_const<index>(_tup);
|
||||
}
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -88,69 +86,69 @@ struct Getter {
|
||||
/// For handling std::variant.
|
||||
template <class... NamedTupleTypes>
|
||||
struct Getter<std::variant<NamedTupleTypes...>> {
|
||||
public:
|
||||
/// Retrieves the indicated value from the tuple.
|
||||
template <int _index>
|
||||
static inline auto& get(std::variant<NamedTupleTypes...>& _tup) {
|
||||
const auto apply = [](auto& _t) -> auto& {
|
||||
using NamedTupleType = std::decay_t<decltype(_t)>;
|
||||
return Getter<NamedTupleType>::template get<_index>(_t);
|
||||
};
|
||||
return std::visit(apply, _tup);
|
||||
}
|
||||
public:
|
||||
/// Retrieves the indicated value from the tuple.
|
||||
template <int _index>
|
||||
static inline auto& get(std::variant<NamedTupleTypes...>& _tup) {
|
||||
const auto apply = [](auto& _t) -> auto& {
|
||||
using NamedTupleType = std::remove_cvref_t<decltype(_t)>;
|
||||
return Getter<NamedTupleType>::template get<_index>(_t);
|
||||
};
|
||||
return std::visit(apply, _tup);
|
||||
}
|
||||
|
||||
/// Gets a field by name.
|
||||
template <StringLiteral _field_name>
|
||||
static inline auto& get(std::variant<NamedTupleTypes...>& _tup) {
|
||||
const auto apply = [](auto& _t) -> auto& {
|
||||
using NamedTupleType = std::decay_t<decltype(_t)>;
|
||||
return Getter<NamedTupleType>::template get<_field_name>(_t);
|
||||
};
|
||||
return std::visit(apply, _tup);
|
||||
}
|
||||
/// Gets a field by name.
|
||||
template <StringLiteral _field_name>
|
||||
static inline auto& get(std::variant<NamedTupleTypes...>& _tup) {
|
||||
const auto apply = [](auto& _t) -> auto& {
|
||||
using NamedTupleType = std::remove_cvref_t<decltype(_t)>;
|
||||
return Getter<NamedTupleType>::template get<_field_name>(_t);
|
||||
};
|
||||
return std::visit(apply, _tup);
|
||||
}
|
||||
|
||||
/// Gets a field by the field type.
|
||||
template <class Field>
|
||||
static inline auto& get(std::variant<NamedTupleTypes...>& _tup) {
|
||||
const auto apply = [](auto& _t) -> auto& {
|
||||
using NamedTupleType = std::decay_t<decltype(_t)>;
|
||||
return Getter<NamedTupleType>::template get<Field>(_t);
|
||||
};
|
||||
return std::visit(apply, _tup);
|
||||
}
|
||||
/// Gets a field by the field type.
|
||||
template <class Field>
|
||||
static inline auto& get(std::variant<NamedTupleTypes...>& _tup) {
|
||||
const auto apply = [](auto& _t) -> auto& {
|
||||
using NamedTupleType = std::remove_cvref_t<decltype(_t)>;
|
||||
return Getter<NamedTupleType>::template get<Field>(_t);
|
||||
};
|
||||
return std::visit(apply, _tup);
|
||||
}
|
||||
|
||||
/// Retrieves the indicated value from the tuple.
|
||||
template <int _index>
|
||||
static inline const auto& get_const(
|
||||
const std::variant<NamedTupleTypes...>& _tup) {
|
||||
const auto apply = [](const auto& _tup) -> const auto& {
|
||||
using NamedTupleType = std::decay_t<decltype(_tup)>;
|
||||
return Getter<NamedTupleType>::template get_const<_index>(_tup);
|
||||
};
|
||||
return std::visit(apply, _tup);
|
||||
}
|
||||
/// Retrieves the indicated value from the tuple.
|
||||
template <int _index>
|
||||
static inline const auto& get_const(
|
||||
const std::variant<NamedTupleTypes...>& _tup) {
|
||||
const auto apply = [](const auto& _tup) -> const auto& {
|
||||
using NamedTupleType = std::remove_cvref_t<decltype(_tup)>;
|
||||
return Getter<NamedTupleType>::template get_const<_index>(_tup);
|
||||
};
|
||||
return std::visit(apply, _tup);
|
||||
}
|
||||
|
||||
/// Gets a field by name.
|
||||
template <StringLiteral _field_name>
|
||||
static inline const auto& get_const(
|
||||
const std::variant<NamedTupleTypes...>& _tup) {
|
||||
const auto apply = [](const auto& _t) -> const auto& {
|
||||
using NamedTupleType = std::decay_t<decltype(_t)>;
|
||||
return Getter<NamedTupleType>::template get_const<_field_name>(_t);
|
||||
};
|
||||
return std::visit(apply, _tup);
|
||||
}
|
||||
/// Gets a field by name.
|
||||
template <StringLiteral _field_name>
|
||||
static inline const auto& get_const(
|
||||
const std::variant<NamedTupleTypes...>& _tup) {
|
||||
const auto apply = [](const auto& _t) -> const auto& {
|
||||
using NamedTupleType = std::remove_cvref_t<decltype(_t)>;
|
||||
return Getter<NamedTupleType>::template get_const<_field_name>(_t);
|
||||
};
|
||||
return std::visit(apply, _tup);
|
||||
}
|
||||
|
||||
/// Gets a field by the field type.
|
||||
template <class Field>
|
||||
static inline const auto& get_const(
|
||||
const std::variant<NamedTupleTypes...>& _tup) {
|
||||
const auto apply = [](const auto& _t) -> const auto& {
|
||||
using NamedTupleType = std::decay_t<decltype(_t)>;
|
||||
return Getter<NamedTupleType>::template get_const<Field>(_t);
|
||||
};
|
||||
return std::visit(apply, _tup);
|
||||
}
|
||||
/// Gets a field by the field type.
|
||||
template <class Field>
|
||||
static inline const auto& get_const(
|
||||
const std::variant<NamedTupleTypes...>& _tup) {
|
||||
const auto apply = [](const auto& _t) -> const auto& {
|
||||
using NamedTupleType = std::remove_cvref_t<decltype(_t)>;
|
||||
return Getter<NamedTupleType>::template get_const<Field>(_t);
|
||||
};
|
||||
return std::visit(apply, _tup);
|
||||
}
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -158,54 +156,54 @@ struct Getter<std::variant<NamedTupleTypes...>> {
|
||||
/// For handling std::variant.
|
||||
template <StringLiteral _discriminator, class... NamedTupleTypes>
|
||||
struct Getter<TaggedUnion<_discriminator, NamedTupleTypes...>> {
|
||||
public:
|
||||
/// Retrieves the indicated value from the tuple.
|
||||
template <int _index>
|
||||
static inline auto& get(
|
||||
TaggedUnion<_discriminator, NamedTupleTypes...>& _tu) {
|
||||
return Getter<std::variant<NamedTupleTypes...>>::template get<_index>(
|
||||
_tu.variant_);
|
||||
}
|
||||
public:
|
||||
/// Retrieves the indicated value from the tuple.
|
||||
template <int _index>
|
||||
static inline auto& get(
|
||||
TaggedUnion<_discriminator, NamedTupleTypes...>& _tu) {
|
||||
return Getter<std::variant<NamedTupleTypes...>>::template get<_index>(
|
||||
_tu.variant_);
|
||||
}
|
||||
|
||||
/// Gets a field by name.
|
||||
template <StringLiteral _field_name>
|
||||
static inline auto& get(
|
||||
TaggedUnion<_discriminator, NamedTupleTypes...>& _tu) {
|
||||
return Getter<std::variant<NamedTupleTypes...>>::template get<
|
||||
_field_name>(_tu.variant_);
|
||||
}
|
||||
/// Gets a field by name.
|
||||
template <StringLiteral _field_name>
|
||||
static inline auto& get(
|
||||
TaggedUnion<_discriminator, NamedTupleTypes...>& _tu) {
|
||||
return Getter<std::variant<NamedTupleTypes...>>::template get<_field_name>(
|
||||
_tu.variant_);
|
||||
}
|
||||
|
||||
/// Gets a field by the field type.
|
||||
template <class Field>
|
||||
static inline auto& get(
|
||||
TaggedUnion<_discriminator, NamedTupleTypes...>& _tu) {
|
||||
return Getter<std::variant<NamedTupleTypes...>>::template get<Field>(
|
||||
_tu.variant_);
|
||||
}
|
||||
/// Gets a field by the field type.
|
||||
template <class Field>
|
||||
static inline auto& get(
|
||||
TaggedUnion<_discriminator, NamedTupleTypes...>& _tu) {
|
||||
return Getter<std::variant<NamedTupleTypes...>>::template get<Field>(
|
||||
_tu.variant_);
|
||||
}
|
||||
|
||||
/// Retrieves the indicated value from the tuple.
|
||||
template <int _index>
|
||||
static inline const auto& get_const(
|
||||
const TaggedUnion<_discriminator, NamedTupleTypes...>& _tu) {
|
||||
return Getter<std::variant<NamedTupleTypes...>>::template get_const<
|
||||
_index>(_tu.variant_);
|
||||
}
|
||||
/// Retrieves the indicated value from the tuple.
|
||||
template <int _index>
|
||||
static inline const auto& get_const(
|
||||
const TaggedUnion<_discriminator, NamedTupleTypes...>& _tu) {
|
||||
return Getter<std::variant<NamedTupleTypes...>>::template get_const<_index>(
|
||||
_tu.variant_);
|
||||
}
|
||||
|
||||
/// Gets a field by name.
|
||||
template <StringLiteral _field_name>
|
||||
static inline const auto& get_const(
|
||||
const TaggedUnion<_discriminator, NamedTupleTypes...>& _tu) {
|
||||
return Getter<std::variant<NamedTupleTypes...>>::template get_const<
|
||||
_field_name>(_tu.variant_);
|
||||
}
|
||||
/// Gets a field by name.
|
||||
template <StringLiteral _field_name>
|
||||
static inline const auto& get_const(
|
||||
const TaggedUnion<_discriminator, NamedTupleTypes...>& _tu) {
|
||||
return Getter<std::variant<NamedTupleTypes...>>::template get_const<
|
||||
_field_name>(_tu.variant_);
|
||||
}
|
||||
|
||||
/// Gets a field by the field type.
|
||||
template <class Field>
|
||||
static inline const auto& get_const(
|
||||
const TaggedUnion<_discriminator, NamedTupleTypes...>& _tu) {
|
||||
return Getter<std::variant<NamedTupleTypes...>>::template get_const<
|
||||
Field>(_tu.variant_);
|
||||
}
|
||||
/// Gets a field by the field type.
|
||||
template <class Field>
|
||||
static inline const auto& get_const(
|
||||
const TaggedUnion<_discriminator, NamedTupleTypes...>& _tu) {
|
||||
return Getter<std::variant<NamedTupleTypes...>>::template get_const<Field>(
|
||||
_tu.variant_);
|
||||
}
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -16,15 +16,15 @@ template <class FieldNames, class... Fields>
|
||||
auto copy_flattened_tuple_to_named_tuple(const auto& _flattened_tuple,
|
||||
Fields&&... _fields) {
|
||||
constexpr auto size =
|
||||
std::tuple_size_v<std::decay_t<decltype(_flattened_tuple)>>;
|
||||
std::tuple_size_v<std::remove_cvref_t<decltype(_flattened_tuple)>>;
|
||||
constexpr auto i = sizeof...(_fields);
|
||||
if constexpr (i == size) {
|
||||
return make_named_tuple(std::move(_fields)...);
|
||||
} else {
|
||||
const auto name_literal = FieldNames::template name_of<i>();
|
||||
auto new_field =
|
||||
rfl::make_field<lit_name_v<std::decay_t<decltype(name_literal)>>>(
|
||||
std::get<i>(_flattened_tuple));
|
||||
auto new_field = rfl::make_field<
|
||||
lit_name_v<std::remove_cvref_t<decltype(name_literal)>>>(
|
||||
std::get<i>(_flattened_tuple));
|
||||
return copy_flattened_tuple_to_named_tuple<FieldNames>(
|
||||
_flattened_tuple, std::move(_fields)..., std::move(new_field));
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ struct extract_discriminators;
|
||||
|
||||
template <StringLiteral _discriminator, class... NamedTupleType>
|
||||
struct extract_discriminators<TaggedUnion<_discriminator, NamedTupleType...>> {
|
||||
using type = define_literal_t<
|
||||
std::decay_t<field_type_t<_discriminator, NamedTupleType>>...>;
|
||||
using type = define_literal_t<
|
||||
std::remove_cvref_t<field_type_t<_discriminator, NamedTupleType>>...>;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
@@ -12,7 +12,8 @@ namespace internal {
|
||||
/// Finds the index of the field signified by _field_name
|
||||
template <StringLiteral _field_name, class Fields, int I = 0>
|
||||
constexpr static int find_index() {
|
||||
using FieldType = std::decay_t<typename std::tuple_element<I, Fields>::type>;
|
||||
using FieldType =
|
||||
std::remove_cvref_t<typename std::tuple_element<I, Fields>::type>;
|
||||
|
||||
constexpr bool name_i_matches = (FieldType::name_ == _field_name);
|
||||
|
||||
|
||||
@@ -75,13 +75,13 @@ auto get_field_names();
|
||||
|
||||
template <auto ptr>
|
||||
auto get_field_name() {
|
||||
using Type = std::decay_t<std::remove_pointer_t<
|
||||
using Type = std::remove_cvref_t<std::remove_pointer_t<
|
||||
typename std::remove_pointer_t<decltype(ptr)>::Type>>;
|
||||
if constexpr (is_rename_v<Type>) {
|
||||
using Name = typename Type::Name;
|
||||
return Name();
|
||||
} else if constexpr (is_flatten_field_v<Type>) {
|
||||
return get_field_names<std::decay_t<typename Type::Type>>();
|
||||
return get_field_names<std::remove_cvref_t<typename Type::Type>>();
|
||||
} else {
|
||||
return rfl::Literal<get_field_name_str_lit<ptr>()>();
|
||||
}
|
||||
@@ -114,7 +114,7 @@ template <class T>
|
||||
#endif
|
||||
#endif
|
||||
auto get_field_names() {
|
||||
if constexpr (std::is_pointer_v<std::decay_t<T>>) {
|
||||
if constexpr (std::is_pointer_v<std::remove_cvref_t<T>>) {
|
||||
return get_field_names<std::remove_pointer_t<T>>();
|
||||
} else {
|
||||
constexpr auto ptr_tuple = to_ptr_tuple(fake_object<T>);
|
||||
|
||||
@@ -18,7 +18,7 @@ constexpr bool all_fields_or_flatten() {
|
||||
if constexpr (_i == std::tuple_size_v<TupleType>) {
|
||||
return true;
|
||||
} else {
|
||||
using T = std::decay_t<std::tuple_element_t<_i, TupleType>>;
|
||||
using T = std::remove_cvref_t<std::tuple_element_t<_i, TupleType>>;
|
||||
if constexpr (is_flatten_field_v<T>) {
|
||||
return all_fields_or_flatten<
|
||||
ptr_tuple_t<typename std::remove_pointer_t<T>::Type>>() &&
|
||||
@@ -34,7 +34,7 @@ constexpr bool some_fields_or_flatten() {
|
||||
if constexpr (_i == std::tuple_size_v<TupleType>) {
|
||||
return false;
|
||||
} else {
|
||||
using T = std::decay_t<std::tuple_element_t<_i, TupleType>>;
|
||||
using T = std::remove_cvref_t<std::tuple_element_t<_i, TupleType>>;
|
||||
if constexpr (is_flatten_field_v<T>) {
|
||||
return some_fields_or_flatten<
|
||||
ptr_tuple_t<typename std::remove_pointer_t<T>::Type>>() ||
|
||||
|
||||
@@ -15,7 +15,7 @@ constexpr bool has_flatten_fields() {
|
||||
if constexpr (_i == std::tuple_size_v<TupleType>) {
|
||||
return false;
|
||||
} else {
|
||||
using T = std::decay_t<std::tuple_element_t<_i, TupleType>>;
|
||||
using T = std::remove_cvref_t<std::tuple_element_t<_i, TupleType>>;
|
||||
return is_flatten_field_v<T> || has_flatten_fields<TupleType, _i + 1>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ template <class Type>
|
||||
class is_attribute<const Attribute<Type>*> : public std::true_type {};
|
||||
|
||||
template <class T>
|
||||
constexpr bool is_attribute_v = is_attribute<std::decay_t<T>>::value;
|
||||
constexpr bool is_attribute_v = is_attribute<std::remove_cvref_t<T>>::value;
|
||||
|
||||
} // namespace internal
|
||||
} // namespace rfl
|
||||
|
||||
@@ -8,10 +8,11 @@ namespace rfl {
|
||||
namespace internal {
|
||||
|
||||
template <class T>
|
||||
constexpr bool is_basic_type_v = std::is_floating_point_v<std::decay_t<T>> ||
|
||||
std::is_integral_v<std::decay_t<T>> ||
|
||||
std::is_same<std::decay_t<T>, std::string>() ||
|
||||
std::is_same<std::decay_t<T>, bool>();
|
||||
constexpr bool is_basic_type_v =
|
||||
std::is_floating_point_v<std::remove_cvref_t<T>> ||
|
||||
std::is_integral_v<std::remove_cvref_t<T>> ||
|
||||
std::is_same<std::remove_cvref_t<T>, std::string>() ||
|
||||
std::is_same<std::remove_cvref_t<T>, bool>();
|
||||
|
||||
} // namespace internal
|
||||
} // namespace rfl
|
||||
|
||||
@@ -11,22 +11,22 @@ namespace internal {
|
||||
|
||||
template <class FieldTuple, class... Args>
|
||||
auto move_and_flatten_field_tuple(FieldTuple&& _t, Args&&... _args) {
|
||||
constexpr auto i = sizeof...(Args);
|
||||
if constexpr (i == std::tuple_size_v<std::decay_t<FieldTuple>>) {
|
||||
return std::tuple_cat(std::move(_args)...);
|
||||
constexpr auto i = sizeof...(Args);
|
||||
if constexpr (i == std::tuple_size_v<std::remove_cvref_t<FieldTuple>>) {
|
||||
return std::tuple_cat(std::move(_args)...);
|
||||
} else {
|
||||
using T = std::tuple_element_t<i, std::remove_cvref_t<FieldTuple>>;
|
||||
if constexpr (is_flatten_field<T>::value) {
|
||||
return move_and_flatten_field_tuple(
|
||||
std::move(_t), std::move(_args)...,
|
||||
move_and_flatten_field_tuple(
|
||||
move_to_field_tuple(std::move(std::get<i>(_t).value_))));
|
||||
} else {
|
||||
using T = std::tuple_element_t<i, std::decay_t<FieldTuple>>;
|
||||
if constexpr (is_flatten_field<T>::value) {
|
||||
return move_and_flatten_field_tuple(
|
||||
std::move(_t), std::move(_args)...,
|
||||
move_and_flatten_field_tuple(
|
||||
move_to_field_tuple(std::move(std::get<i>(_t).value_))));
|
||||
} else {
|
||||
return move_and_flatten_field_tuple(
|
||||
std::move(_t), std::move(_args)...,
|
||||
std::make_tuple(std::move(std::get<i>(_t))));
|
||||
}
|
||||
return move_and_flatten_field_tuple(
|
||||
std::move(_t), std::move(_args)...,
|
||||
std::make_tuple(std::move(std::get<i>(_t))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
@@ -13,17 +13,17 @@ namespace internal {
|
||||
|
||||
template <class FieldTuple>
|
||||
auto move_field_tuple_to_named_tuple(FieldTuple&& _field_tuple) {
|
||||
const auto ft_to_nt = []<class... Fields>(Fields&&... _fields) {
|
||||
return make_named_tuple(std::move(_fields)...);
|
||||
};
|
||||
const auto ft_to_nt = []<class... Fields>(Fields&&... _fields) {
|
||||
return make_named_tuple(std::move(_fields)...);
|
||||
};
|
||||
|
||||
if constexpr (!has_flatten_fields<std::decay_t<FieldTuple>>()) {
|
||||
return std::apply(ft_to_nt, std::move(_field_tuple));
|
||||
} else {
|
||||
auto flattened_tuple =
|
||||
move_and_flatten_field_tuple(std::move(_field_tuple));
|
||||
return std::apply(ft_to_nt, std::move(flattened_tuple));
|
||||
}
|
||||
if constexpr (!has_flatten_fields<std::remove_cvref_t<FieldTuple>>()) {
|
||||
return std::apply(ft_to_nt, std::move(_field_tuple));
|
||||
} else {
|
||||
auto flattened_tuple =
|
||||
move_and_flatten_field_tuple(std::move(_field_tuple));
|
||||
return std::apply(ft_to_nt, std::move(flattened_tuple));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
@@ -17,13 +17,15 @@ template <class PtrFieldTupleType, class PtrNamedTupleType, class... Args>
|
||||
auto make_ptr_fields(PtrNamedTupleType& _n, Args... _args) {
|
||||
constexpr auto i = sizeof...(Args);
|
||||
|
||||
constexpr auto size = std::tuple_size_v<std::decay_t<PtrFieldTupleType>>;
|
||||
constexpr auto size =
|
||||
std::tuple_size_v<std::remove_cvref_t<PtrFieldTupleType>>;
|
||||
|
||||
if constexpr (i == size) {
|
||||
return std::make_tuple(_args...);
|
||||
} else {
|
||||
using Field = std::decay_t<std::tuple_element_t<i, PtrFieldTupleType>>;
|
||||
using T = std::decay_t<std::remove_pointer_t<typename Field::Type>>;
|
||||
using Field =
|
||||
std::remove_cvref_t<std::tuple_element_t<i, PtrFieldTupleType>>;
|
||||
using T = std::remove_cvref_t<std::remove_pointer_t<typename Field::Type>>;
|
||||
|
||||
if constexpr (is_named_tuple_v<T>) {
|
||||
using SubPtrNamedTupleType =
|
||||
@@ -34,7 +36,7 @@ auto make_ptr_fields(PtrNamedTupleType& _n, Args... _args) {
|
||||
_n, _args..., SubPtrNamedTupleType(_n).fields());
|
||||
|
||||
} else if constexpr (is_flatten_field<Field>::value) {
|
||||
using SubPtrFieldTupleType = std::decay_t<ptr_field_tuple_t<T>>;
|
||||
using SubPtrFieldTupleType = std::remove_cvref_t<ptr_field_tuple_t<T>>;
|
||||
|
||||
return make_ptr_fields<PtrFieldTupleType>(
|
||||
_n, _args..., make_ptr_fields<SubPtrFieldTupleType>(_n));
|
||||
@@ -49,10 +51,10 @@ auto make_ptr_fields(PtrNamedTupleType& _n, Args... _args) {
|
||||
template <class T, class Pointers, class... Args>
|
||||
auto move_from_ptr_fields(Pointers& _ptrs, Args&&... _args) {
|
||||
constexpr auto i = sizeof...(Args);
|
||||
if constexpr (i == std::tuple_size_v<std::decay_t<Pointers>>) {
|
||||
if constexpr (i == std::tuple_size_v<std::remove_cvref_t<Pointers>>) {
|
||||
return T{std::move(_args)...};
|
||||
} else {
|
||||
using FieldType = std::tuple_element_t<i, std::decay_t<Pointers>>;
|
||||
using FieldType = std::tuple_element_t<i, std::remove_cvref_t<Pointers>>;
|
||||
|
||||
if constexpr (is_field_v<FieldType>) {
|
||||
return move_from_ptr_fields<T>(
|
||||
@@ -61,9 +63,9 @@ auto move_from_ptr_fields(Pointers& _ptrs, Args&&... _args) {
|
||||
std::move(*std::get<i>(_ptrs).value())));
|
||||
|
||||
} else {
|
||||
using PtrFieldTupleType = std::decay_t<ptr_field_tuple_t<T>>;
|
||||
using PtrFieldTupleType = std::remove_cvref_t<ptr_field_tuple_t<T>>;
|
||||
|
||||
using U = std::decay_t<std::remove_pointer_t<
|
||||
using U = std::remove_cvref_t<std::remove_pointer_t<
|
||||
typename std::tuple_element_t<i, PtrFieldTupleType>::Type>>;
|
||||
|
||||
return move_from_ptr_fields<T>(
|
||||
@@ -77,16 +79,16 @@ auto move_from_ptr_fields(Pointers& _ptrs, Args&&... _args) {
|
||||
/// fields.
|
||||
template <class T, class NamedTupleType>
|
||||
T move_from_named_tuple(NamedTupleType&& _n) {
|
||||
using RequiredType = std::decay_t<named_tuple_t<T>>;
|
||||
using RequiredType = std::remove_cvref_t<named_tuple_t<T>>;
|
||||
|
||||
if constexpr (is_named_tuple_v<std::decay_t<T>>) {
|
||||
if constexpr (is_named_tuple_v<std::remove_cvref_t<T>>) {
|
||||
return std::move(_n);
|
||||
|
||||
} else if constexpr (std::is_same<std::decay_t<NamedTupleType>,
|
||||
} else if constexpr (std::is_same<std::remove_cvref_t<NamedTupleType>,
|
||||
RequiredType>()) {
|
||||
auto ptr_named_tuple = nt_to_ptr_named_tuple(_n);
|
||||
|
||||
using PtrFieldTupleType = std::decay_t<ptr_field_tuple_t<T>>;
|
||||
using PtrFieldTupleType = std::remove_cvref_t<ptr_field_tuple_t<T>>;
|
||||
|
||||
auto pointers = make_ptr_fields<PtrFieldTupleType>(ptr_named_tuple);
|
||||
|
||||
|
||||
@@ -32,12 +32,12 @@ template <class TargetTupleType, class PtrTupleType, int _j = 0, class... Args>
|
||||
auto unflatten_ptr_tuple(PtrTupleType& _t, Args... _args) {
|
||||
constexpr auto i = sizeof...(Args);
|
||||
|
||||
constexpr auto size = std::tuple_size_v<std::decay_t<TargetTupleType>>;
|
||||
constexpr auto size = std::tuple_size_v<std::remove_cvref_t<TargetTupleType>>;
|
||||
|
||||
if constexpr (i == size) {
|
||||
return std::make_tuple(_args...);
|
||||
} else {
|
||||
using T = std::decay_t<
|
||||
using T = std::remove_cvref_t<
|
||||
std::remove_pointer_t<std::tuple_element_t<i, TargetTupleType>>>;
|
||||
|
||||
if constexpr (is_flatten_field_v<T>) {
|
||||
@@ -61,19 +61,19 @@ auto unflatten_ptr_tuple(PtrTupleType& _t, Args... _args) {
|
||||
template <class T, class Pointers, class... Args>
|
||||
auto move_from_pointers(Pointers& _ptrs, Args&&... _args) {
|
||||
constexpr auto i = sizeof...(Args);
|
||||
if constexpr (i == std::tuple_size_v<std::decay_t<Pointers>>) {
|
||||
if constexpr (i == std::tuple_size_v<std::remove_cvref_t<Pointers>>) {
|
||||
return T{std::move(_args)...};
|
||||
} else {
|
||||
using FieldType = std::tuple_element_t<i, std::decay_t<Pointers>>;
|
||||
using FieldType = std::tuple_element_t<i, std::remove_cvref_t<Pointers>>;
|
||||
|
||||
if constexpr (std::is_pointer_v<FieldType>) {
|
||||
return move_from_pointers<T>(_ptrs, std::move(_args)...,
|
||||
std::move(*std::get<i>(_ptrs)));
|
||||
|
||||
} else {
|
||||
using PtrTupleType = ptr_tuple_t<std::decay_t<T>>;
|
||||
using PtrTupleType = ptr_tuple_t<std::remove_cvref_t<T>>;
|
||||
|
||||
using U = std::decay_t<typename std::remove_pointer_t<
|
||||
using U = std::remove_cvref_t<typename std::remove_pointer_t<
|
||||
typename std::tuple_element_t<i, PtrTupleType>>::Type>;
|
||||
|
||||
return move_from_pointers<T>(_ptrs, std::move(_args)...,
|
||||
@@ -88,7 +88,7 @@ template <class T, class TupleType>
|
||||
T move_from_tuple(TupleType&& _t) {
|
||||
auto ptr_tuple = tup_to_ptr_tuple(_t);
|
||||
|
||||
using TargetTupleType = tuple_t<std::decay_t<T>>;
|
||||
using TargetTupleType = tuple_t<std::remove_cvref_t<T>>;
|
||||
|
||||
auto pointers = unflatten_ptr_tuple<TargetTupleType>(ptr_tuple);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace internal {
|
||||
|
||||
template <class OriginalStruct>
|
||||
auto move_to_field_tuple(OriginalStruct&& _t) {
|
||||
using T = std::decay_t<OriginalStruct>;
|
||||
using T = std::remove_cvref_t<OriginalStruct>;
|
||||
if constexpr (is_named_tuple_v<T>) {
|
||||
return _t.fields();
|
||||
} else if constexpr (has_fields<T>()) {
|
||||
|
||||
@@ -8,33 +8,31 @@ namespace internal {
|
||||
|
||||
template <class Fields, int _i = 1, int _j = 0>
|
||||
constexpr inline bool no_duplicate_field_names() {
|
||||
constexpr auto num_fields = std::tuple_size_v<Fields>;
|
||||
constexpr auto num_fields = std::tuple_size_v<Fields>;
|
||||
|
||||
if constexpr (num_fields <= 1) {
|
||||
return true;
|
||||
if constexpr (num_fields <= 1) {
|
||||
return true;
|
||||
} else {
|
||||
if constexpr (_i == num_fields) {
|
||||
return true;
|
||||
} else if constexpr (_j == -1) {
|
||||
return no_duplicate_field_names<Fields, _i + 1, _i>();
|
||||
} else {
|
||||
if constexpr (_i == num_fields) {
|
||||
return true;
|
||||
} else if constexpr (_j == -1) {
|
||||
return no_duplicate_field_names<Fields, _i + 1, _i>();
|
||||
} else {
|
||||
using FieldType1 =
|
||||
std::decay_t<typename std::tuple_element<_i, Fields>::type>;
|
||||
using FieldType2 =
|
||||
std::decay_t<typename std::tuple_element<_j, Fields>::type>;
|
||||
using FieldType1 =
|
||||
std::remove_cvref_t<typename std::tuple_element<_i, Fields>::type>;
|
||||
using FieldType2 =
|
||||
std::remove_cvref_t<typename std::tuple_element<_j, Fields>::type>;
|
||||
|
||||
constexpr auto field_name_i = FieldType1::name_;
|
||||
constexpr auto field_name_j = FieldType2::name_;
|
||||
constexpr auto field_name_i = FieldType1::name_;
|
||||
constexpr auto field_name_j = FieldType2::name_;
|
||||
|
||||
constexpr bool no_duplicate = (field_name_i != field_name_j);
|
||||
constexpr bool no_duplicate = (field_name_i != field_name_j);
|
||||
|
||||
static_assert(no_duplicate,
|
||||
"Duplicate field names are not allowed");
|
||||
static_assert(no_duplicate, "Duplicate field names are not allowed");
|
||||
|
||||
return no_duplicate &&
|
||||
no_duplicate_field_names<Fields, _i, _j - 1>();
|
||||
}
|
||||
return no_duplicate && no_duplicate_field_names<Fields, _i, _j - 1>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
@@ -22,7 +22,7 @@ auto nt_to_ptr_named_tuple(NamedTupleType& _nt, AlreadyExtracted... _a) {
|
||||
return make_named_tuple(_a...);
|
||||
} else {
|
||||
using FieldType = typename std::tuple_element<i, Fields>::type;
|
||||
using T = std::decay_t<typename FieldType::Type>;
|
||||
using T = std::remove_cvref_t<typename FieldType::Type>;
|
||||
return nt_to_ptr_named_tuple(
|
||||
_nt, _a..., Field<FieldType::name_, T*>(&std::get<i>(_nt.values())));
|
||||
}
|
||||
@@ -41,7 +41,7 @@ auto nt_to_ptr_named_tuple(const NamedTupleType& _nt, AlreadyExtracted... _a) {
|
||||
return make_named_tuple(_a...);
|
||||
} else {
|
||||
using FieldType = typename std::tuple_element<i, Fields>::type;
|
||||
using T = std::decay_t<typename FieldType::Type>;
|
||||
using T = std::remove_cvref_t<typename FieldType::Type>;
|
||||
return nt_to_ptr_named_tuple(
|
||||
_nt, _a...,
|
||||
Field<FieldType::name_, const T*>(&std::get<i>(_nt.values())));
|
||||
|
||||
@@ -29,12 +29,12 @@ struct remove_single_field<_OldNamedTupleType, _name, _NewNamedTupleType, 0> {
|
||||
template <class _OldNamedTupleType, StringLiteral _name,
|
||||
class _NewNamedTupleType, int _i>
|
||||
struct remove_single_field {
|
||||
using OldNamedTupleType = std::decay_t<_OldNamedTupleType>;
|
||||
using OldNamedTupleType = std::remove_cvref_t<_OldNamedTupleType>;
|
||||
|
||||
constexpr static int num_fields =
|
||||
std::tuple_size_v<typename OldNamedTupleType::Fields>;
|
||||
|
||||
using FieldType = std::decay_t<typename std::tuple_element<
|
||||
using FieldType = std::remove_cvref_t<typename std::tuple_element<
|
||||
num_fields - _i, typename OldNamedTupleType::Fields>::type>;
|
||||
|
||||
using NewNamedTupleType =
|
||||
@@ -53,7 +53,7 @@ struct remove_fields;
|
||||
/// Special case - only head is left.
|
||||
template <class _NamedTupleType, StringLiteral _head>
|
||||
struct remove_fields<_NamedTupleType, _head> {
|
||||
using NamedTupleType = std::decay_t<_NamedTupleType>;
|
||||
using NamedTupleType = std::remove_cvref_t<_NamedTupleType>;
|
||||
|
||||
constexpr static int num_fields =
|
||||
std::tuple_size_v<typename NamedTupleType::Fields>;
|
||||
@@ -65,7 +65,7 @@ struct remove_fields<_NamedTupleType, _head> {
|
||||
/// General case.
|
||||
template <class _NamedTupleType, StringLiteral _head, StringLiteral... _tail>
|
||||
struct remove_fields {
|
||||
using NamedTupleType = std::decay_t<_NamedTupleType>;
|
||||
using NamedTupleType = std::remove_cvref_t<_NamedTupleType>;
|
||||
|
||||
constexpr static int num_fields =
|
||||
std::tuple_size_v<typename NamedTupleType::Fields>;
|
||||
|
||||
@@ -16,7 +16,8 @@ struct remove_ptrs_tup;
|
||||
|
||||
template <class... Ts>
|
||||
struct remove_ptrs_tup<std::tuple<Ts...>> {
|
||||
using TupleType = std::tuple<std::decay_t<std::remove_pointer_t<Ts>>...>;
|
||||
using TupleType =
|
||||
std::tuple<std::remove_cvref_t<std::remove_pointer_t<Ts>>...>;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
@@ -15,10 +15,10 @@ auto flatten_ptr_tuple(PtrTuple&& _t, Args... _args) {
|
||||
constexpr auto i = sizeof...(Args);
|
||||
if constexpr (i == 0 && !has_flatten_fields<PtrTuple>()) {
|
||||
return std::forward<PtrTuple>(_t);
|
||||
} else if constexpr (i == std::tuple_size_v<std::decay_t<PtrTuple>>) {
|
||||
} else if constexpr (i == std::tuple_size_v<std::remove_cvref_t<PtrTuple>>) {
|
||||
return std::tuple_cat(std::forward<Args>(_args)...);
|
||||
} else {
|
||||
using T = std::tuple_element_t<i, std::decay_t<PtrTuple>>;
|
||||
using T = std::tuple_element_t<i, std::remove_cvref_t<PtrTuple>>;
|
||||
if constexpr (is_flatten_field_v<T>) {
|
||||
return flatten_ptr_tuple(
|
||||
std::forward<PtrTuple>(_t), std::forward<Args>(_args)...,
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace internal {
|
||||
|
||||
template <class T>
|
||||
auto to_ptr_field_tuple(T& _t) {
|
||||
if constexpr (std::is_pointer_v<std::decay_t<T>>) {
|
||||
if constexpr (std::is_pointer_v<std::remove_cvref_t<T>>) {
|
||||
return to_ptr_field_tuple(*_t);
|
||||
} else if constexpr (is_named_tuple_v<T>) {
|
||||
return nt_to_ptr_named_tuple(_t).fields();
|
||||
|
||||
@@ -21,10 +21,10 @@ namespace internal {
|
||||
template <class PtrFieldTuple, class... Args>
|
||||
auto flatten_ptr_field_tuple(PtrFieldTuple& _t, Args&&... _args) {
|
||||
constexpr auto i = sizeof...(Args);
|
||||
if constexpr (i == std::tuple_size_v<std::decay_t<PtrFieldTuple>>) {
|
||||
if constexpr (i == std::tuple_size_v<std::remove_cvref_t<PtrFieldTuple>>) {
|
||||
return std::tuple_cat(std::forward<Args>(_args)...);
|
||||
} else {
|
||||
using T = std::tuple_element_t<i, std::decay_t<PtrFieldTuple>>;
|
||||
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());
|
||||
@@ -43,7 +43,7 @@ auto field_tuple_to_named_tuple(PtrFieldTuple& _ptr_field_tuple) {
|
||||
return make_named_tuple(_fields...);
|
||||
};
|
||||
|
||||
if constexpr (!has_flatten_fields<std::decay_t<PtrFieldTuple>>()) {
|
||||
if constexpr (!has_flatten_fields<std::remove_cvref_t<PtrFieldTuple>>()) {
|
||||
return std::apply(ft_to_nt, std::move(_ptr_field_tuple));
|
||||
} else {
|
||||
const auto flattened_tuple = flatten_ptr_field_tuple(_ptr_field_tuple);
|
||||
@@ -55,10 +55,10 @@ auto field_tuple_to_named_tuple(PtrFieldTuple& _ptr_field_tuple) {
|
||||
/// the struct.
|
||||
template <class T>
|
||||
auto to_ptr_named_tuple(T&& _t) {
|
||||
if constexpr (has_fields<std::decay_t<T>>()) {
|
||||
if constexpr (std::is_pointer_v<std::decay_t<T>>) {
|
||||
if constexpr (has_fields<std::remove_cvref_t<T>>()) {
|
||||
if constexpr (std::is_pointer_v<std::remove_cvref_t<T>>) {
|
||||
return to_ptr_named_tuple(*_t);
|
||||
} else if constexpr (is_named_tuple_v<std::decay_t<T>>) {
|
||||
} else if constexpr (is_named_tuple_v<std::remove_cvref_t<T>>) {
|
||||
return nt_to_ptr_named_tuple(_t);
|
||||
} else {
|
||||
auto ptr_field_tuple = to_ptr_field_tuple(_t);
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace internal {
|
||||
|
||||
template <class T>
|
||||
constexpr auto to_ptr_tuple(T& _t) {
|
||||
if constexpr (std::is_pointer_v<std::decay_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) {
|
||||
|
||||
@@ -13,25 +13,26 @@ namespace internal {
|
||||
|
||||
template <class FieldNames, int j = 0, class... Fields>
|
||||
auto wrap_in_fields(auto&& _tuple, Fields&&... _fields) {
|
||||
constexpr auto size = std::tuple_size_v<std::decay_t<decltype(_tuple)>>;
|
||||
constexpr auto size =
|
||||
std::tuple_size_v<std::remove_cvref_t<decltype(_tuple)>>;
|
||||
constexpr auto i = sizeof...(_fields);
|
||||
if constexpr (i == size) {
|
||||
return std::make_tuple(std::move(_fields)...);
|
||||
} else {
|
||||
auto value = std::move(std::get<i>(_tuple));
|
||||
using Type = std::decay_t<std::remove_pointer_t<decltype(value)>>;
|
||||
using Type = std::remove_cvref_t<std::remove_pointer_t<decltype(value)>>;
|
||||
if constexpr (is_flatten_field_v<Type>) {
|
||||
// The problem here is that the FieldNames are already flattened, but this
|
||||
// is not, so we need to determine how many field names to skip.
|
||||
constexpr auto n_skip = std::tuple_size_v<
|
||||
std::decay_t<flattened_ptr_tuple_t<typename Type::Type>>>;
|
||||
std::remove_cvref_t<flattened_ptr_tuple_t<typename Type::Type>>>;
|
||||
return wrap_in_fields<FieldNames, j + n_skip>(
|
||||
std::move(_tuple), std::move(_fields)..., std::move(value));
|
||||
} else {
|
||||
const auto name_literal = FieldNames::template name_of<j>();
|
||||
auto new_field =
|
||||
rfl::make_field<lit_name_v<std::decay_t<decltype(name_literal)>>>(
|
||||
std::move(value));
|
||||
auto new_field = rfl::make_field<
|
||||
lit_name_v<std::remove_cvref_t<decltype(name_literal)>>>(
|
||||
std::move(value));
|
||||
return wrap_in_fields<FieldNames, j + 1>(
|
||||
std::move(_tuple), std::move(_fields)..., std::move(new_field));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user