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
33 changes: 10 additions & 23 deletions core/variant/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,24 @@ class Array {

public:
struct ConstIterator {
_FORCE_INLINE_ const Variant &operator*() const;
_FORCE_INLINE_ const Variant *operator->() const;
_FORCE_INLINE_ const Variant &operator*() const { return *element_ptr; }
_FORCE_INLINE_ const Variant *operator->() const { return element_ptr; }

_FORCE_INLINE_ ConstIterator &operator++();
_FORCE_INLINE_ ConstIterator &operator--();

_FORCE_INLINE_ bool operator==(const ConstIterator &p_other) const { return element_ptr == p_other.element_ptr; }
_FORCE_INLINE_ bool operator!=(const ConstIterator &p_other) const { return element_ptr != p_other.element_ptr; }

ConstIterator() = default;

_FORCE_INLINE_ ConstIterator(const Variant *p_element_ptr) :
element_ptr(p_element_ptr) {}
_FORCE_INLINE_ ConstIterator() {}
_FORCE_INLINE_ ConstIterator(const ConstIterator &p_other) :
element_ptr(p_other.element_ptr) {}

_FORCE_INLINE_ ConstIterator &operator=(const ConstIterator &p_other) {
element_ptr = p_other.element_ptr;
return *this;
}

private:
const Variant *element_ptr = nullptr;
};
static_assert(std::is_trivially_copyable_v<ConstIterator>, "ConstIterator must be trivially copyable");

struct Iterator {
_FORCE_INLINE_ Variant &operator*() const;
Expand All @@ -85,26 +80,18 @@ class Array {
_FORCE_INLINE_ bool operator==(const Iterator &p_other) const { return element_ptr == p_other.element_ptr; }
_FORCE_INLINE_ bool operator!=(const Iterator &p_other) const { return element_ptr != p_other.element_ptr; }

_FORCE_INLINE_ Iterator(Variant *p_element_ptr, Variant *p_read_only = nullptr) :
element_ptr(p_element_ptr), read_only(p_read_only) {}
_FORCE_INLINE_ Iterator() {}
_FORCE_INLINE_ Iterator(const Iterator &p_other) :
element_ptr(p_other.element_ptr), read_only(p_other.read_only) {}
_FORCE_INLINE_ operator ConstIterator() const { return ConstIterator(element_ptr); }

_FORCE_INLINE_ Iterator &operator=(const Iterator &p_other) {
element_ptr = p_other.element_ptr;
read_only = p_other.read_only;
return *this;
}
Iterator() = default;

operator ConstIterator() const {
return ConstIterator(element_ptr);
}
_FORCE_INLINE_ Iterator(Variant *p_element_ptr, Variant *p_read_only = nullptr) :
element_ptr(p_element_ptr), read_only(p_read_only) {}

private:
Variant *element_ptr = nullptr;
Variant *read_only = nullptr;
};
static_assert(std::is_trivially_copyable_v<Iterator>, "Iterator must be trivially copyable");

Iterator begin();
Iterator end();
Expand Down
8 changes: 0 additions & 8 deletions core/variant/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -974,14 +974,6 @@ Array::Iterator &Array::Iterator::operator--() {
return *this;
}

const Variant &Array::ConstIterator::operator*() const {
return *element_ptr;
}

const Variant *Array::ConstIterator::operator->() const {
return element_ptr;
}

Array::ConstIterator &Array::ConstIterator::operator++() {
element_ptr++;
return *this;
Expand Down