Skip to content

Commit

Permalink
Add: Iterator functions on fastgltf::span
Browse files Browse the repository at this point in the history
  • Loading branch information
spnda committed Feb 23, 2025
1 parent 7ae458f commit 63f5304
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions include/fastgltf/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1495,10 +1495,15 @@ namespace fastgltf {
using reference = T&;
using const_reference = const T&;

using iterator = pointer;
using reverse_iterator = std::reverse_iterator<iterator>;

pointer _ptr = nullptr;
size_type _size = 0;

public:
static constexpr std::size_t extent = Extent;

constexpr span() = default;

// std::span ctor (2)
Expand All @@ -1520,6 +1525,22 @@ namespace fastgltf {
constexpr span(const span& other) noexcept = default;
constexpr span& operator=(const span& other) = default;

[[nodiscard]] constexpr iterator begin() const noexcept {
return data();
}
[[nodiscard]] constexpr iterator end() const noexcept {
return data() + size;
}
[[nodiscard]] constexpr reverse_iterator rbegin() const noexcept {
return std::reverse_iterator(end());
}
[[nodiscard]] constexpr reverse_iterator rend() const noexcept {
return std::reverse_iterator(begin());
}

[[nodiscard]] constexpr reference front() const { return *begin(); }
[[nodiscard]] constexpr reference back() const { return *(end() - 1); }

[[nodiscard]] constexpr reference operator[](size_type idx) const {
return data()[idx];
}
Expand Down

0 comments on commit 63f5304

Please sign in to comment.