forked from LiteLDev/LeviLamina
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
133 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "mc/_HeaderOutputPredefine.h" | ||
#include "mc/world/item/registry/ItemStack.h" | ||
|
||
|
||
template <typename T, bool IsConst> | ||
class ContainerIterator { | ||
public: | ||
using difference_type = std::ptrdiff_t; | ||
using value_type = std::conditional_t<IsConst, ItemStack const, ItemStack>; | ||
using pointer = value_type*; | ||
using reference = value_type&; | ||
using iterator_category = std::random_access_iterator_tag; | ||
|
||
[[nodiscard]] constexpr ContainerIterator(const T* container, int position) | ||
: mContainer(const_cast<T*>(container)), | ||
mSlot(position) {} | ||
|
||
[[nodiscard]] constexpr bool operator==(const ContainerIterator& other) const { | ||
return mSlot == other.mSlot && mContainer == other.mContainer; | ||
} | ||
[[nodiscard]] constexpr std::strong_ordering operator<=>(const ContainerIterator& other) const { | ||
return mSlot <=> other.mSlot; | ||
} | ||
|
||
[[nodiscard]] constexpr reference operator*() { return mContainer->getItemNonConst(mSlot); } | ||
[[nodiscard]] constexpr reference operator*() const { return mContainer->getItem(mSlot); } | ||
[[nodiscard]] constexpr pointer operator->() { return mContainer->getItemNonConst(mSlot); } | ||
[[nodiscard]] constexpr pointer operator->() const { return &mContainer->getItem(mSlot); } | ||
|
||
constexpr ContainerIterator& operator++() { | ||
++mSlot; | ||
return *this; | ||
} | ||
constexpr ContainerIterator& operator--() { | ||
--mSlot; | ||
return *this; | ||
} | ||
|
||
constexpr ContainerIterator operator+(difference_type n) const { return ContainerIterator(mContainer, mSlot + n); } | ||
constexpr ContainerIterator operator-(difference_type n) const { return ContainerIterator(mContainer, mSlot - n); } | ||
|
||
constexpr ContainerIterator& operator+=(difference_type n) { | ||
mSlot += n; | ||
return *this; | ||
} | ||
constexpr ContainerIterator& operator-=(difference_type n) { | ||
mSlot -= n; | ||
return *this; | ||
} | ||
|
||
[[nodiscard]] constexpr reference operator[](difference_type n) const { return *(*this + n); } | ||
|
||
private: | ||
T* mContainer; | ||
int mSlot; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters