Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/BLI_span.hh
| Show First 20 Lines • Show All 402 Lines • ▼ Show 20 Lines | for (int64_t i = 0; i < size_; i++) { | ||||
| if (data_[i] == search_value) { | if (data_[i] == search_value) { | ||||
| return i; | return i; | ||||
| } | } | ||||
| } | } | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| /** | /** | ||||
| * Utility to make it more convenient to iterate over all indices that can be used with this | |||||
| * array. | |||||
| */ | |||||
| constexpr IndexRange index_range() const | |||||
| { | |||||
| return IndexRange(size_); | |||||
| } | |||||
| /** | |||||
| * Returns a new Span to the same underlying memory buffer. No conversions are done. | * Returns a new Span to the same underlying memory buffer. No conversions are done. | ||||
| */ | */ | ||||
| template<typename NewT> Span<NewT> constexpr cast() const | template<typename NewT> Span<NewT> constexpr cast() const | ||||
| { | { | ||||
| BLI_assert((size_ * sizeof(T)) % sizeof(NewT) == 0); | BLI_assert((size_ * sizeof(T)) % sizeof(NewT) == 0); | ||||
| int64_t new_size = size_ * sizeof(T) / sizeof(NewT); | int64_t new_size = size_ * sizeof(T) / sizeof(NewT); | ||||
| return Span<NewT>(reinterpret_cast<const NewT *>(data_), new_size); | return Span<NewT>(reinterpret_cast<const NewT *>(data_), new_size); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 220 Lines • ▼ Show 20 Lines | public: | ||||
| * due to implicit conversions. However, sometimes automatic type deduction needs some help. | * due to implicit conversions. However, sometimes automatic type deduction needs some help. | ||||
| */ | */ | ||||
| constexpr Span<T> as_span() const | constexpr Span<T> as_span() const | ||||
| { | { | ||||
| return Span<T>(data_, size_); | return Span<T>(data_, size_); | ||||
| } | } | ||||
| /** | /** | ||||
| * Utility to make it more convenient to iterate over all indices that can be used with this | |||||
| * array. | |||||
| */ | |||||
| constexpr IndexRange index_range() const | |||||
| { | |||||
| return IndexRange(size_); | |||||
| } | |||||
| /** | |||||
| * Returns a reference to the last element. This invokes undefined behavior when the array is | * Returns a reference to the last element. This invokes undefined behavior when the array is | ||||
| * empty. | * empty. | ||||
| */ | */ | ||||
| constexpr T &last() const | constexpr T &last() const | ||||
| { | { | ||||
| BLI_assert(size_ > 0); | BLI_assert(size_ > 0); | ||||
| return data_[size_ - 1]; | return data_[size_ - 1]; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines | |||||