mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-11-29 14:26:19 +08:00
Beautification and optimization
This commit is contained in:
@@ -22,8 +22,7 @@ struct Enum {
|
||||
"Duplicate field names are not allowed");
|
||||
}
|
||||
|
||||
Enum(VariantType&& _variant)
|
||||
: variant_(std::forward<VariantType>(_variant)) {
|
||||
Enum(VariantType&& _variant) : variant_(std::move(_variant)) {
|
||||
static_assert(internal::no_duplicate_field_names<Fields>(),
|
||||
"Duplicate field names are not allowed");
|
||||
}
|
||||
@@ -41,7 +40,7 @@ struct Enum {
|
||||
inline void operator=(VariantType&& _variant) {
|
||||
static_assert(internal::no_duplicate_field_names<Fields>(),
|
||||
"Duplicate field names are not allowed");
|
||||
variant_ = std::forward<VariantType>(_variant);
|
||||
variant_ = std::move(_variant);
|
||||
}
|
||||
|
||||
/// Returns the underlying variant.
|
||||
|
||||
@@ -17,19 +17,19 @@ namespace rfl {
|
||||
template <internal::StringLiteral _name, class _Type>
|
||||
struct Field {
|
||||
/// The underlying type.
|
||||
using Type = std::decay_t<_Type>;
|
||||
using Type = _Type;
|
||||
|
||||
/// The name of the field.
|
||||
using Name = rfl::Literal<_name>;
|
||||
|
||||
Field(const Type& _value) : value_(_value) {}
|
||||
|
||||
Field(Type&& _value) : value_(std::forward<Type>(_value)) {}
|
||||
Field(Type&& _value) noexcept : value_(std::move(_value)) {}
|
||||
|
||||
Field(const Field<_name, Type>& _field) : value_(_field.get()) {}
|
||||
|
||||
Field(Field<_name, Type>&& _field)
|
||||
: value_(std::forward<Type>(_field.value_)) {}
|
||||
Field(Field<_name, Type>&& _field) noexcept
|
||||
: value_(std::move(_field.value_)) {}
|
||||
|
||||
template <class T>
|
||||
Field(const Field<_name, T>& _field) : value_(_field.get()) {}
|
||||
@@ -43,7 +43,7 @@ struct Field {
|
||||
|
||||
template <class T, typename std::enable_if<std::is_convertible_v<T, Type>,
|
||||
bool>::type = true>
|
||||
Field(T&& _value) : value_(_value) {}
|
||||
Field(T&& _value) noexcept : value_(std::forward<T>(_value)) {}
|
||||
|
||||
template <class T, typename std::enable_if<std::is_convertible_v<T, Type>,
|
||||
bool>::type = true>
|
||||
@@ -73,8 +73,8 @@ struct Field {
|
||||
inline void operator=(const Type& _value) { value_ = _value; }
|
||||
|
||||
/// Assigns the underlying object.
|
||||
inline void operator=(Type&& _value) {
|
||||
value_ = std::forward<Type>(_value);
|
||||
inline void operator=(Type&& _value) noexcept {
|
||||
value_ = std::move(_value);
|
||||
}
|
||||
|
||||
/// Assigns the underlying object.
|
||||
@@ -118,7 +118,7 @@ struct Field {
|
||||
inline void set(const Type& _value) { value_ = _value; }
|
||||
|
||||
/// Assigns the underlying object.
|
||||
inline void set(Type&& _value) { value_ = std::forward<Type>(_value); }
|
||||
inline void set(Type&& _value) { value_ = std::move(_value); }
|
||||
|
||||
/// Returns the underlying object.
|
||||
inline Type& value() { return value_; }
|
||||
|
||||
@@ -100,7 +100,7 @@ class NamedTuple {
|
||||
template <class... TupContent, class... Tail>
|
||||
auto add(const std::tuple<TupContent...>& _tuple, Tail&&... _tail) const {
|
||||
if constexpr (sizeof...(Tail) > 0) {
|
||||
return add_tuple(std::forward<std::tuple<TupContent...>>(_tuple),
|
||||
return add_tuple(_tuple,
|
||||
std::make_index_sequence<sizeof...(TupContent)>{})
|
||||
.replace(_tail...);
|
||||
} else {
|
||||
|
||||
@@ -66,11 +66,11 @@ class Result {
|
||||
|
||||
Result(const T& _val) : t_or_err_(_val) {}
|
||||
|
||||
Result(T&& _val) : t_or_err_(std::forward<T>(_val)) {}
|
||||
Result(T&& _val) noexcept : t_or_err_(std::forward<T>(_val)) {}
|
||||
|
||||
Result(const Error& _err) : t_or_err_(_err) {}
|
||||
|
||||
Result(Error&& _err) : t_or_err_(std::forward<Error>(_err)) {}
|
||||
Result(Error&& _err) noexcept : t_or_err_(std::forward<Error>(_err)) {}
|
||||
|
||||
template <class U, typename std::enable_if<std::is_convertible_v<U, T>,
|
||||
bool>::type = true>
|
||||
|
||||
@@ -17,14 +17,15 @@ struct TaggedUnion {
|
||||
|
||||
TaggedUnion(const VariantType& _variant) : variant_(_variant) {}
|
||||
|
||||
TaggedUnion(VariantType&& _variant)
|
||||
: variant_(std::forward<VariantType>(_variant)) {}
|
||||
TaggedUnion(VariantType&& _variant) noexcept
|
||||
: variant_(std::move(_variant)) {}
|
||||
|
||||
TaggedUnion(const TaggedUnion<_discriminator, VariantType>& _tagged_union)
|
||||
: variant_(_tagged_union.variant_) {}
|
||||
|
||||
TaggedUnion(TaggedUnion<_discriminator, VariantType>&& _tagged_union)
|
||||
: variant_(std::forward<VariantType>(_tagged_union.variant_)) {}
|
||||
TaggedUnion(
|
||||
TaggedUnion<_discriminator, VariantType>&& _tagged_union) noexcept
|
||||
: variant_(std::move(_tagged_union.variant_)) {}
|
||||
|
||||
template <class T,
|
||||
typename std::enable_if<std::is_convertible_v<T, VariantType>,
|
||||
@@ -34,7 +35,7 @@ struct TaggedUnion {
|
||||
template <class T,
|
||||
typename std::enable_if<std::is_convertible_v<T, VariantType>,
|
||||
bool>::type = true>
|
||||
TaggedUnion(T&& _t) : variant_(std::forward<T>(_t)) {}
|
||||
TaggedUnion(T&& _t) noexcept : variant_(std::forward<T>(_t)) {}
|
||||
|
||||
~TaggedUnion() = default;
|
||||
|
||||
@@ -42,8 +43,16 @@ struct TaggedUnion {
|
||||
inline void operator=(const VariantType& _variant) { variant_ = _variant; }
|
||||
|
||||
/// Assigns the underlying object.
|
||||
inline void operator=(VariantType&& _variant) {
|
||||
variant_ = std::forward<VariantType>(_variant);
|
||||
inline void operator=(VariantType&& _variant) noexcept {
|
||||
variant_ = std::move(_variant);
|
||||
}
|
||||
|
||||
/// Assigns the underlying object.
|
||||
template <class T,
|
||||
typename std::enable_if<std::is_convertible_v<T, VariantType>,
|
||||
bool>::type = true>
|
||||
inline void operator=(T&& _variant) {
|
||||
variant_ = std::forward<T>(_variant);
|
||||
}
|
||||
|
||||
/// Assigns the underlying object.
|
||||
@@ -61,8 +70,9 @@ struct TaggedUnion {
|
||||
}
|
||||
|
||||
/// Assigns the underlying object.
|
||||
inline void operator=(TaggedUnion<_discriminator, VariantType>&& _other) {
|
||||
variant_ = std::forward<VariantType>(_other.variant_);
|
||||
inline void operator=(
|
||||
TaggedUnion<_discriminator, VariantType>&& _other) noexcept {
|
||||
variant_ = std::move(_other.variant_);
|
||||
}
|
||||
|
||||
/// Returns the underlying variant.
|
||||
|
||||
Reference in New Issue
Block a user