Skip to content

Commit

Permalink
Replaced all decay_t with cvref_t
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzicheng1987 committed Jan 3, 2024
1 parent 11c80d4 commit 7a5b53b
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 41 deletions.
16 changes: 8 additions & 8 deletions include/rfl/flexbuf/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ struct Writer {
template <class T>
OutputVarType insert_value(const std::string& _name,
const T& _var) const noexcept {
if constexpr (std::is_same<std::decay_t<T>, std::string>()) {
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
fbb_->String(_name.c_str(), _var);
} else if constexpr (std::is_same<std::decay_t<T>, bool>()) {
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
fbb_->Bool(_name.c_str(), _var);
} else if constexpr (std::is_floating_point<std::decay_t<T>>()) {
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
fbb_->Double(_name.c_str(), _var);
} else if constexpr (std::is_integral<std::decay_t<T>>()) {
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
fbb_->Int(_name.c_str(), _var);
} else {
static_assert(always_false_v<T>, "Unsupported type");
Expand All @@ -131,13 +131,13 @@ struct Writer {

template <class T>
OutputVarType insert_value(const T& _var) const noexcept {
if constexpr (std::is_same<std::decay_t<T>, std::string>()) {
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
fbb_->String(_var);
} else if constexpr (std::is_same<std::decay_t<T>, bool>()) {
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
fbb_->Bool(_var);
} else if constexpr (std::is_floating_point<std::decay_t<T>>()) {
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
fbb_->Double(_var);
} else if constexpr (std::is_integral<std::decay_t<T>>()) {
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
fbb_->Int(_var);
} else {
static_assert(always_false_v<T>, "Unsupported type");
Expand Down
2 changes: 1 addition & 1 deletion include/rfl/parsing/FieldVariantParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct FieldVariantParser {

const auto handle = [&](const auto& _field) {
const auto named_tuple = make_named_tuple(internal::to_ptr_field(_field));
using NamedTupleType = std::decay_t<decltype(named_tuple)>;
using NamedTupleType = std::remove_cvref_t<decltype(named_tuple)>;
Parser<R, W, NamedTupleType>::write(_w, named_tuple, _parent);
};

Expand Down
10 changes: 6 additions & 4 deletions include/rfl/parsing/MapParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,23 @@ struct MapParser {
std::is_floating_point_v<ReflT>) {
const auto new_parent =
typename ParentType::Object{std::to_string(k.reflection()), &obj};
Parser<R, W, std::decay_t<ValueType>>::write(_w, v, new_parent);
Parser<R, W, std::remove_cvref_t<ValueType>>::write(_w, v,
new_parent);
} else {
const auto new_parent =
typename ParentType::Object{k.reflection(), &obj};
Parser<R, W, std::decay_t<ValueType>>::write(_w, v, new_parent);
Parser<R, W, std::remove_cvref_t<ValueType>>::write(_w, v,
new_parent);
}

} else if constexpr (std::is_integral_v<KeyType> ||
std::is_floating_point_v<KeyType>) {
const auto new_parent =
typename ParentType::Object{std::to_string(k), &obj};
Parser<R, W, std::decay_t<ValueType>>::write(_w, v, new_parent);
Parser<R, W, std::remove_cvref_t<ValueType>>::write(_w, v, new_parent);
} else {
const auto new_parent = typename ParentType::Object{k, &obj};
Parser<R, W, std::decay_t<ValueType>>::write(_w, v, new_parent);
Parser<R, W, std::remove_cvref_t<ValueType>>::write(_w, v, new_parent);
}
}
_w.end_object(&obj);
Expand Down
12 changes: 6 additions & 6 deletions include/rfl/parsing/Parent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct Parent {
template <class ParentType>
static OutputArrayType add_array(const W& _w, const size_t _size,
const ParentType& _parent) {
using Type = std::decay_t<ParentType>;
using Type = std::remove_cvref_t<ParentType>;
if constexpr (std::is_same<Type, Array>()) {
return _w.add_array_to_array(_size, _parent.arr_);
} else if constexpr (std::is_same<Type, Object>()) {
Expand All @@ -47,7 +47,7 @@ struct Parent {
template <class ParentType>
static OutputObjectType add_object(const W& _w, const size_t _size,
const ParentType& _parent) {
using Type = std::decay_t<ParentType>;
using Type = std::remove_cvref_t<ParentType>;
if constexpr (std::is_same<Type, Array>()) {
return _w.add_object_to_array(_size, _parent.arr_);
} else if constexpr (std::is_same<Type, Object>()) {
Expand All @@ -61,11 +61,11 @@ struct Parent {

template <class ParentType>
static OutputVarType add_null(const W& _w, const ParentType& _parent) {
using Type = std::decay_t<ParentType>;
using Type = std::remove_cvref_t<ParentType>;
if constexpr (std::is_same<Type, Array>()) {
return _w.add_null_to_array(_parent.arr_);
} else if constexpr (std::is_same<Type, Object>()) {
if constexpr (supports_attributes<std::decay_t<W>>) {
if constexpr (supports_attributes<std::remove_cvref_t<W>>) {
return _w.add_null_to_object(_parent.name_, _parent.obj_,
_parent.is_attribute_);
} else {
Expand All @@ -81,11 +81,11 @@ struct Parent {
template <class ParentType, class T>
static OutputVarType add_value(const W& _w, const T& _var,
const ParentType& _parent) {
using Type = std::decay_t<ParentType>;
using Type = std::remove_cvref_t<ParentType>;
if constexpr (std::is_same<Type, Array>()) {
return _w.add_value_to_array(_var, _parent.arr_);
} else if constexpr (std::is_same<Type, Object>()) {
if constexpr (supports_attributes<std::decay_t<W>>) {
if constexpr (supports_attributes<std::remove_cvref_t<W>>) {
return _w.add_value_to_object(_parent.name_, _var, _parent.obj_,
_parent.is_attribute_);
} else {
Expand Down
2 changes: 1 addition & 1 deletion include/rfl/parsing/Parser_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct Parser<R, W, std::array<T, _size>> {
auto arr = ParentType::add_array(_w, _size, _parent);
const auto new_parent = typename ParentType::Array{&arr};
for (auto it = _arr.begin(); it != _arr.end(); ++it) {
Parser<R, W, std::decay_t<T>>::write(_w, *it, new_parent);
Parser<R, W, std::remove_cvref_t<T>>::write(_w, *it, new_parent);
}
_w.end_array(&arr);
}
Expand Down
2 changes: 1 addition & 1 deletion include/rfl/parsing/Parser_box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Parser<R, W, Box<T>> {
template <class P>
static void write(const W& _w, const Box<T>& _box,
const P& _parent) noexcept {
Parser<R, W, std::decay_t<T>>::write(_w, *_box, _parent);
Parser<R, W, std::remove_cvref_t<T>>::write(_w, *_box, _parent);
}
};

Expand Down
4 changes: 2 additions & 2 deletions include/rfl/parsing/Parser_default.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct Parser {
template <class P>
static void write(const W& _w, const T& _var, const P& _parent) noexcept {
if constexpr (internal::has_reflection_type_v<T>) {
using ReflectionType = std::decay_t<typename T::ReflectionType>;
using ReflectionType = std::remove_cvref_t<typename T::ReflectionType>;
if constexpr (internal::has_reflection_method_v<T>) {
Parser<R, W, ReflectionType>::write(_w, _var.reflection(), _parent);
} else {
Expand All @@ -81,7 +81,7 @@ struct Parser {
}
} else if constexpr (std::is_class_v<T> && std::is_aggregate_v<T>) {
const auto ptr_named_tuple = internal::to_ptr_named_tuple(_var);
using PtrNamedTupleType = std::decay_t<decltype(ptr_named_tuple)>;
using PtrNamedTupleType = std::remove_cvref_t<decltype(ptr_named_tuple)>;
Parser<R, W, PtrNamedTupleType>::write(_w, ptr_named_tuple, _parent);
} else if constexpr (std::is_enum_v<T>) {
using StringConverter = internal::enums::StringConverter<T>;
Expand Down
2 changes: 1 addition & 1 deletion include/rfl/parsing/Parser_optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct Parser<R, W, std::optional<T>> {
ParentType::add_null(_w, _parent);
return;
}
Parser<R, W, std::decay_t<T>>::write(_w, *_o, _parent);
Parser<R, W, std::remove_cvref_t<T>>::write(_w, *_o, _parent);
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/rfl/parsing/Parser_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct Parser<R, W, T*> {
ParentType::add_null(_w, _parent);
return;
}
Parser<R, W, std::decay_t<T>>::write(_w, *_ptr, _parent);
Parser<R, W, std::remove_cvref_t<T>>::write(_w, *_ptr, _parent);
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/rfl/parsing/Parser_ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct Parser<R, W, Ref<T>> {
template <class P>
static void write(const W& _w, const Ref<T>& _ref,
const P& _parent) noexcept {
Parser<R, W, std::decay_t<T>>::write(_w, *_ref, _parent);
Parser<R, W, std::remove_cvref_t<T>>::write(_w, *_ref, _parent);
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/rfl/parsing/Parser_reference_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct Parser<R, W, std::reference_wrapper<T>> {
template <class P>
static void write(const W& _w, const std::reference_wrapper<T> _ref,
const P& _p) noexcept {
Parser<R, W, std::decay_t<T>>::write(_w, _ref.get(), _p);
Parser<R, W, std::remove_cvref_t<T>>::write(_w, _ref.get(), _p);
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/rfl/parsing/Parser_rename.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct Parser<R, W, Rename<_name, T>> {
template <class P>
static void write(const W& _w, const Rename<_name, T>& _rename,
const P& _parent) noexcept {
Parser<R, W, std::decay_t<T>>::write(_w, _rename.value(), _parent);
Parser<R, W, std::remove_cvref_t<T>>::write(_w, _rename.value(), _parent);
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/rfl/parsing/Parser_shared_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct Parser<R, W, std::shared_ptr<T>> {
ParentType::add_null(_w, _parent);
return;
}
Parser<R, W, std::decay_t<T>>::write(_w, *_s, _parent);
Parser<R, W, std::remove_cvref_t<T>>::write(_w, *_s, _parent);
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/rfl/parsing/Parser_unique_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct Parser<R, W, std::unique_ptr<T>> {
ParentType::add_null(_w, _parent);
return;
}
Parser<R, W, std::decay_t<T>>::write(_w, *_s, _parent);
Parser<R, W, std::remove_cvref_t<T>>::write(_w, *_s, _parent);
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/rfl/parsing/VectorParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct VectorParser {
_w, std::distance(_vec.begin(), _vec.end()), _parent);
const auto new_parent = typename ParentType::Array{&arr};
for (const auto& v : _vec) {
Parser<R, W, std::decay_t<T>>::write(_w, v, new_parent);
Parser<R, W, std::remove_cvref_t<T>>::write(_w, v, new_parent);
}
_w.end_array(&arr);
}
Expand Down
2 changes: 1 addition & 1 deletion include/rfl/parsing/is_empty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace parsing {

template <class T>
static const bool is_empty(const T& _var) {
using Type = std::decay_t<T>;
using Type = std::remove_cvref_t<T>;
if constexpr (std::is_pointer_v<Type>) {
return !_var || is_empty(*_var);
} else if constexpr (internal::has_reflection_type_v<Type>) {
Expand Down
8 changes: 4 additions & 4 deletions include/rfl/xml/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ struct Writer {
private:
template <class T>
std::string to_string(const T& _val) const noexcept {
if constexpr (std::is_same<std::decay_t<T>, std::string>()) {
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
return _val;
} else if constexpr (std::is_same<std::decay_t<T>, bool>()) {
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
return _val ? "true" : "false";
} else if constexpr (std::is_floating_point<std::decay_t<T>>() ||
std::is_integral<std::decay_t<T>>()) {
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>() ||
std::is_integral<std::remove_cvref_t<T>>()) {
return std::to_string(_val);
} else {
static_assert(always_false_v<T>, "Unsupported type");
Expand Down
10 changes: 5 additions & 5 deletions include/rfl/yaml/Reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ struct Reader {
template <class T>
rfl::Result<T> to_basic_type(const InputVarType& _var) const noexcept {
try {
if constexpr (std::is_same<std::decay_t<T>, std::string>() ||
std::is_same<std::decay_t<T>, bool>() ||
std::is_floating_point<std::decay_t<T>>() ||
std::is_integral<std::decay_t<T>>()) {
return _var.node_.as<std::decay_t<T>>();
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>() ||
std::is_same<std::remove_cvref_t<T>, bool>() ||
std::is_floating_point<std::remove_cvref_t<T>>() ||
std::is_integral<std::remove_cvref_t<T>>()) {
return _var.node_.as<std::remove_cvref_t<T>>();
} else {
static_assert(rfl::always_false_v<T>, "Unsupported type.");
}
Expand Down

0 comments on commit 7a5b53b

Please sign in to comment.