Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/rfl/Binary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ struct Binary {

Binary(const Type& _value) : value_(_value) {}

Binary(Binary<T>&& _other) noexcept = default;
Binary(Binary&& _other) noexcept = default;

Binary(const Binary<T>& _other) = default;
Binary(const Binary& _other) = default;

template <class U>
Binary(const Binary<U>& _other) : value_(_other.get()) {}
Expand Down Expand Up @@ -77,10 +77,10 @@ struct Binary {
}

/// Assigns the underlying object.
Binary<T>& operator=(const Binary<T>& _other) = default;
Binary& operator=(const Binary<T>& _other) = default;

/// Assigns the underlying object.
Binary<T>& operator=(Binary<T>&& _other) = default;
Binary& operator=(Binary<T>&& _other) = default;

/// Assigns the underlying object.
template <class U>
Expand Down
22 changes: 11 additions & 11 deletions include/rfl/Box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@ class Box {
/// The only way of creating new boxes is
/// Box<T>::make(...).
template <class... Args>
static Box<T, C> make(Args&&... _args) {
return Box<T, C>(std::make_unique<T>(std::forward<Args>(_args)...));
static Box make(Args&&... _args) {
return Box(std::make_unique<T>(std::forward<Args>(_args)...));
}

/// You can generate them from unique_ptrs as well, in which case it will
/// return an Error, if the unique_ptr is not set.
static Result<Box<T, C>> make(std::unique_ptr<T>&& _ptr) {
static Result<Box> make(std::unique_ptr<T>&& _ptr) {
if (!_ptr) {
return error("std::unique_ptr was a nullptr.");
}
return Box<T, C>(std::move(_ptr));
return Box(std::move(_ptr));
}

Box() : ptr_(std::make_unique<T>()) {}

/// Copy constructor if copyable
Box(const Box<T, C>& _other) requires (C == Copyability::COPYABLE)
Box(const Box& _other) requires (C == Copyability::COPYABLE)
{
ptr_ = std::make_unique<T>(*_other);
}

/// Copy constructor if not copyable
Box(const Box<T, C>& _other) requires (C == Copyability::NON_COPYABLE) = delete;
Box(const Box& _other) requires (C == Copyability::NON_COPYABLE) = delete;

Box(Box<T, C>&& _other) = default;
Box(Box&& _other) = default;

template <class U, Copyability C2>
Box(Box<U, C2>&& _other) noexcept
Expand All @@ -65,22 +65,22 @@ class Box {
T* get() const { return ptr_.get(); }

/// Copy assignment operator if copyable
Box<T, C>& operator=(const Box<T>& other) requires (C == Copyability::COPYABLE) {
Box& operator=(const Box<T>& other) requires (C == Copyability::COPYABLE) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The return type has been updated from Box<T, C>& to Box&, which is a good simplification using the injected class name.

However, the parameter type remains const Box<T>& other. For consistency with similar changes in this PR (e.g., the deleted assignment operator on line 76 which now uses const Box& _other) and the general goal of using the concise injected class name, consider changing this parameter to const Box& other.

Using Box<T> as a type for a parameter of Box<T, C> is unusual because Box is defined as template <class T, Copyability C>. const Box& would correctly resolve to const Box<T, C>& within this class context and align better with the PR's intent.

Suggested change
Box& operator=(const Box<T>& other) requires (C == Copyability::COPYABLE) {
Box& operator=(const Box& other) requires (C == Copyability::COPYABLE) {

if(this != &other) {
ptr_ = std::make_unique<T>(*other);
}
return *this;
}

/// Copy assignment operator if not copyable
Box<T, C>& operator=(const Box<T>& _other) requires (C == Copyability::NON_COPYABLE) = delete;
Box& operator=(const Box& _other) requires (C == Copyability::NON_COPYABLE) = delete;

/// Move assignment operator
Box<T, C>& operator=(Box<T, C>&& _other) noexcept = default;
Box& operator=(Box&& _other) noexcept = default;

/// Move assignment operator
template <class U>
Box<T, C>& operator=(Box<U>&& _other) noexcept {
Box& operator=(Box<U>&& _other) noexcept {
ptr_ = std::forward<std::unique_ptr<U>>(_other.ptr());
return *this;
}
Expand Down
12 changes: 6 additions & 6 deletions include/rfl/Description.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ struct Description {

Description(Type&& _value) noexcept : value_(std::move(_value)) {}

Description(Description<_description, T>&& _field) noexcept = default;
Description(Description&& _field) noexcept = default;

Description(const Description<_description, Type>& _field) = default;
Description(const Description& _field) = default;

template <class U>
Description(const Description<_description, U>& _field)
Expand Down Expand Up @@ -105,12 +105,12 @@ struct Description {
}

/// Assigns the underlying object.
Description<_description, T>& operator=(
const Description<_description, T>& _field) = default;
Description& operator=(
const Description& _field) = default;

/// Assigns the underlying object.
Description<_description, T>& operator=(
Description<_description, T>&& _field) = default;
Description& operator=(
Description&& _field) = default;

/// Assigns the underlying object.
template <class U>
Expand Down
8 changes: 4 additions & 4 deletions include/rfl/Field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ struct Field {

Field(Type&& _value) noexcept : value_(std::move(_value)) {}

Field(Field<_name, T>&& _field) noexcept = default;
Field(Field&& _field) noexcept = default;

Field(const Field<_name, T>& _field) = default;
Field(const Field& _field) = default;

template <class U>
Field(const Field<_name, U>& _field) : value_(_field.get()) {}
Expand Down Expand Up @@ -104,10 +104,10 @@ struct Field {
}

/// Assigns the underlying object.
Field<_name, T>& operator=(const Field<_name, T>& _field) = default;
Field& operator=(const Field& _field) = default;

/// Assigns the underlying object.
Field<_name, T>& operator=(Field<_name, T>&& _field) = default;
Field& operator=(Field&& _field) = default;

/// Assigns the underlying object.
template <class U>
Expand Down
18 changes: 9 additions & 9 deletions include/rfl/Flatten.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ struct Flatten {

Flatten(Type&& _value) noexcept : value_(std::forward<Type>(_value)) {}

Flatten(const Flatten<T>& _f) = default;
Flatten(const Flatten& _f) = default;

Flatten(Flatten<T>&& _f) noexcept = default;
Flatten(Flatten&& _f) noexcept = default;

template <class U>
Flatten(const Flatten<U>& _f) : value_(_f.get()) {}
Expand Down Expand Up @@ -54,41 +54,41 @@ struct Flatten {
const Type& operator()() const { return value_; }

/// Assigns the underlying object.
Flatten<T>& operator=(const T& _value) {
Flatten& operator=(const T& _value) {
value_ = _value;
return *this;
}

/// Assigns the underlying object.
Flatten<T>& operator=(T&& _value) {
Flatten& operator=(T&& _value) {
value_ = std::forward<Type>(_value);
return *this;
}

/// Assigns the underlying object.
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
bool>::type = true>
Flatten<T>& operator=(const U& _value) {
Flatten& operator=(const U& _value) {
value_ = _value;
return *this;
}

/// Assigns the underlying object.
Flatten<T>& operator=(const Flatten<T>& _f) = default;
Flatten& operator=(const Flatten& _f) = default;

/// Assigns the underlying object.
Flatten<T>& operator=(Flatten<T>&& _f) = default;
Flatten& operator=(Flatten&& _f) = default;

/// Assigns the underlying object.
template <class U>
Flatten<T>& operator=(const Flatten<U>& _f) {
Flatten& operator=(const Flatten<U>& _f) {
value_ = _f.get();
return *this;
}

/// Assigns the underlying object.
template <class U>
Flatten<T>& operator=(Flatten<U>&& _f) {
Flatten& operator=(Flatten<U>&& _f) {
value_ = std::forward<U>(_f);
return *this;
}
Expand Down
14 changes: 7 additions & 7 deletions include/rfl/Tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class Tuple {

Tuple() : Tuple(Types()...) {}

Tuple(const Tuple<Types...>& _other) { copy_from_other(_other, seq_); }
Tuple(const Tuple& _other) { copy_from_other(_other, seq_); }

Tuple(Tuple<Types...>&& _other) noexcept {
Tuple(Tuple&& _other) noexcept {
move_from_other(std::move(_other), seq_);
}

Expand All @@ -71,18 +71,18 @@ class Tuple {
}

/// Assigns the underlying object.
Tuple<Types...>& operator=(const Tuple<Types...>& _other) {
Tuple& operator=(const Tuple& _other) {
if (this == &_other) {
return *this;
}
auto temp = Tuple<Types...>(_other);
auto temp = Tuple(_other);
destroy_if_necessary(seq_);
move_from_other(std::move(temp), seq_);
return *this;
}

/// Assigns the underlying object.
Tuple<Types...>& operator=(Tuple<Types...>&& _other) noexcept {
Tuple& operator=(Tuple&& _other) noexcept {
if (this == &_other) {
return *this;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ class Tuple {

private:
template <int... _is>
void copy_from_other(const Tuple<Types...>& _other,
void copy_from_other(const Tuple& _other,
std::integer_sequence<int, _is...>) {
const auto copy_one = [this]<int _i>(const auto& _other,
std::integral_constant<int, _i>) {
Expand Down Expand Up @@ -161,7 +161,7 @@ class Tuple {
}

template <int... _is>
void move_from_other(Tuple<Types...>&& _other,
void move_from_other(Tuple&& _other,
std::integer_sequence<int, _is...>) {
const auto move_one = [this]<int _i>(auto&& _other,
std::integral_constant<int, _i>) {
Expand Down
14 changes: 7 additions & 7 deletions include/rfl/Validator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ struct Validator {
std::conditional_t<sizeof...(Vs) == 0, V, AllOf<V, Vs...>>;

/// Exception-free validation.
static Result<Validator<T, V, Vs...>> from_value(const T& _value) noexcept {
static Result<Validator> from_value(const T& _value) noexcept {
try {
return Validator<T, V, Vs...>(_value);
return Validator(_value);
} catch (std::exception& e) {
return error(e.what());
}
}

Validator() : value_(ValidationType::validate(T()).value()) {}

Validator(Validator<T, V, Vs...>&& _other) noexcept = default;
Validator(Validator&& _other) noexcept = default;

Validator(const Validator<T, V, Vs...>& _other) = default;
Validator(const Validator& _other) = default;

Validator(T&& _value) : value_(ValidationType::validate(_value).value()) {}

Expand Down Expand Up @@ -65,11 +65,11 @@ struct Validator {
}

/// Assigns the underlying object.
Validator<T, V, Vs...>& operator=(const Validator<T, V, Vs...>& _other) =
Validator& operator=(const Validator& _other) =
default;

/// Assigns the underlying object.
Validator<T, V, Vs...>& operator=(Validator<T, V, Vs...>&& _other) noexcept =
Validator& operator=(Validator&& _other) noexcept =
default;

/// Assigns the underlying object.
Expand All @@ -89,7 +89,7 @@ struct Validator {
}

/// Equality operator other Validators.
bool operator==(const Validator<T, V, Vs...>& _other) const {
bool operator==(const Validator& _other) const {
return value() == _other.value();
}

Expand Down
Loading
Loading