Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/BLI_index_range.hh
| Context not available. | |||||
| return this->slice(range.start(), range.size()); | return this->slice(range.start(), range.size()); | ||||
| } | } | ||||
| /** | |||||
| * Returns a new Span with n elements removed from the beginning. This invokes undefined | |||||
JacquesLucke: `Span` -> `IndexRange`. | |||||
| * behavior when n is negative. | |||||
| */ | |||||
| constexpr IndexRange drop_front(int64_t n) const | |||||
| { | |||||
| BLI_assert(n >= 0); | |||||
| const int64_t new_size = std::max<int64_t>(0, size_ - n); | |||||
| return IndexRange(start_ + n, new_size); | |||||
| } | |||||
| /** | |||||
| * Returns a new IndexRange with n elements removed from the beginning. This invokes undefined | |||||
| * behavior when n is negative. | |||||
| */ | |||||
| constexpr IndexRange drop_back(int64_t n) const | |||||
| { | |||||
| BLI_assert(n >= 0); | |||||
| const int64_t new_size = std::max<int64_t>(0, size_ - n); | |||||
| return IndexRange(start_, new_size); | |||||
| } | |||||
| /** | |||||
| * Returns a new IndexRange that only contains the first n elements. This invokes undefined | |||||
| * behavior when n is negative. | |||||
| */ | |||||
| constexpr IndexRange take_front(int64_t n) const | |||||
| { | |||||
| BLI_assert(n >= 0); | |||||
| const int64_t new_size = std::min<int64_t>(size_, n); | |||||
| return IndexRange(start_, new_size); | |||||
| } | |||||
| /** | |||||
| * Returns a new IndexRange that only contains the last n elements. This invokes undefined | |||||
| * behavior when n is negative. | |||||
| */ | |||||
| constexpr IndexRange take_back(int64_t n) const | |||||
| { | |||||
HooglyBooglyAuthorUnsubmitted Done Inline ActionsI'll add some tests for these if you think they're reasonable. And I can split them to a separate commit if you'd prefer too. HooglyBoogly: I'll add some tests for these if you think they're reasonable. And I can split them to a… | |||||
JacquesLuckeUnsubmitted Not Done Inline ActionsAdding some tests would be good. A separate commit too, doesn't need separate review though. JacquesLucke: Adding some tests would be good. A separate commit too, doesn't need separate review though. | |||||
| BLI_assert(n >= 0); | |||||
| const int64_t new_size = std::min<int64_t>(size_, n); | |||||
| return IndexRange(start_ + size_ - new_size, new_size); | |||||
| } | |||||
| /** | /** | ||||
| * Get read-only access to a memory buffer that contains the range as actual numbers. | * Get read-only access to a memory buffer that contains the range as actual numbers. | ||||
| */ | */ | ||||
| Context not available. | |||||
Span -> IndexRange.