Blender V5.0
Span< T > Class Template Reference

#include <BLI_span.hh>

Inherited by blender::VArraySpan< T >.

Public Types

using value_type = T
using pointer = T *
using const_pointer = const T *
using reference = T &
using const_reference = const T &
using iterator = const T *
using size_type = int64_t

Public Member Functions

constexpr Span ()=default
constexpr Span (const T *start, int64_t size)
template<typename U, BLI_ENABLE_IF((is_span_convertible_pointer_v< U, T >))>
constexpr Span (const U *start, int64_t size)
constexpr Span (const std::initializer_list< T > &list)
constexpr Span (const std::vector< T > &vector)
template<std::size_t N>
constexpr Span (const std::array< T, N > &array)
template<typename U, BLI_ENABLE_IF((is_span_convertible_pointer_v< U, T >))>
constexpr Span (Span< U > span)
constexpr Span slice (int64_t start, int64_t size) const
constexpr Span slice (IndexRange range) const
constexpr Span slice_safe (const int64_t start, const int64_t size) const
constexpr Span slice_safe (IndexRange range) const
constexpr Span drop_front (int64_t n) const
constexpr Span drop_back (int64_t n) const
constexpr Span take_front (int64_t n) const
constexpr Span take_back (int64_t n) const
constexpr const Tdata () const
constexpr const Tbegin () const
constexpr const Tend () const
constexpr std::reverse_iterator< const T * > rbegin () const
constexpr std::reverse_iterator< const T * > rend () const
constexpr const Toperator[] (int64_t index) const
constexpr int64_t size () const
constexpr bool is_empty () const
constexpr int64_t size_in_bytes () const
constexpr bool contains (const T &value) const
constexpr bool contains_ptr (const T *ptr) const
constexpr int64_t count (const T &value) const
constexpr const Tfirst () const
constexpr const Tlast (const int64_t n=0) const
constexpr bool has_duplicates__linear_search () const
constexpr bool intersects__linear_search (Span other) const
constexpr int64_t first_index (const T &search_value) const
constexpr int64_t first_index_try (const T &search_value) const
constexpr IndexRange index_range () const
constexpr uint64_t hash () const
template<typename NewT>
Span< NewT > constexpr cast () const

Protected Attributes

const Tdata_ = nullptr
int64_t size_ = 0

Friends

bool operator== (const Span< T > a, const Span< T > b)
bool operator!= (const Span< T > a, const Span< T > b)

Detailed Description

template<typename T>
class Span< T >

References an array of type T that is owned by someone else. The data in the array cannot be modified.

Definition at line 74 of file BLI_span.hh.

Member Typedef Documentation

◆ const_pointer

template<typename T>
using blender::Span< T >::const_pointer = const T *

Definition at line 78 of file BLI_span.hh.

◆ const_reference

template<typename T>
using blender::Span< T >::const_reference = const T &

Definition at line 80 of file BLI_span.hh.

◆ iterator

template<typename T>
using blender::Span< T >::iterator = const T *

Definition at line 81 of file BLI_span.hh.

◆ pointer

template<typename T>
using blender::Span< T >::pointer = T *

Definition at line 77 of file BLI_span.hh.

◆ reference

template<typename T>
using blender::Span< T >::reference = T &

Definition at line 79 of file BLI_span.hh.

◆ size_type

template<typename T>
using blender::Span< T >::size_type = int64_t

Definition at line 82 of file BLI_span.hh.

◆ value_type

template<typename T>
using blender::Span< T >::value_type = T

Definition at line 76 of file BLI_span.hh.

Constructor & Destructor Documentation

◆ Span() [1/7]

template<typename T>
blender::Span< T >::Span ( )
constexprdefault

Create a reference to an empty array.

◆ Span() [2/7]

template<typename T>
blender::Span< T >::Span ( const T * start,
int64_t size )
inlineconstexpr

Definition at line 94 of file BLI_span.hh.

◆ Span() [3/7]

template<typename T>
template<typename U, BLI_ENABLE_IF((is_span_convertible_pointer_v< U, T >))>
blender::Span< T >::Span ( const U * start,
int64_t size )
inlineconstexpr

Definition at line 100 of file BLI_span.hh.

◆ Span() [4/7]

template<typename T>
blender::Span< T >::Span ( const std::initializer_list< T > & list)
inlineconstexpr

Reference an initializer_list. Note that the data in the initializer_list is only valid until the expression containing it is fully computed.

Do: call_function_with_array({1, 2, 3, 4});

Don't: Span<int> span = {1, 2, 3, 4}; call_function_with_array(span);

Definition at line 116 of file BLI_span.hh.

◆ Span() [5/7]

template<typename T>
blender::Span< T >::Span ( const std::vector< T > & vector)
inlineconstexpr

Definition at line 120 of file BLI_span.hh.

◆ Span() [6/7]

template<typename T>
template<std::size_t N>
blender::Span< T >::Span ( const std::array< T, N > & array)
inlineconstexpr

Definition at line 122 of file BLI_span.hh.

◆ Span() [7/7]

template<typename T>
template<typename U, BLI_ENABLE_IF((is_span_convertible_pointer_v< U, T >))>
blender::Span< T >::Span ( Span< U > span)
inlineconstexpr

Support implicit conversions like the one below: Span<T *> -> Span<const T *>

Definition at line 129 of file BLI_span.hh.

Member Function Documentation

◆ begin()

template<typename T>
const T * blender::Span< T >::begin ( ) const
inlineconstexpr

Definition at line 220 of file BLI_span.hh.

Referenced by blender::bke::pbvh::node_update_visibility_grids().

◆ cast()

template<typename T>
template<typename NewT>
Span< NewT > constexpr blender::Span< T >::cast ( ) const
inlineconstexpr

Returns a new Span to the same underlying memory buffer. No conversions are done.

Definition at line 418 of file BLI_span.hh.

◆ contains()

template<typename T>
bool blender::Span< T >::contains ( const T & value) const
inlineconstexpr

Does a linear search to see of the value is in the array. Returns true if it is, otherwise false.

Definition at line 277 of file BLI_span.hh.

Referenced by acf_fcurve_name(), and blender::animrig::tests::TEST_F().

◆ contains_ptr()

template<typename T>
bool blender::Span< T >::contains_ptr ( const T * ptr) const
inlineconstexpr

Does a constant time check to see if the pointer points to a value in the referenced array. Return true if it is, otherwise false.

Definition at line 291 of file BLI_span.hh.

◆ count()

template<typename T>
int64_t blender::Span< T >::count ( const T & value) const
inlineconstexpr

Does a linear search to count how often the value is in the array. Returns the number of occurrences.

Definition at line 300 of file BLI_span.hh.

◆ data()

template<typename T>
const T * blender::Span< T >::data ( ) const
inlineconstexpr

Returns the pointer to the beginning of the referenced array. This may be nullptr when the size is zero.

Definition at line 215 of file BLI_span.hh.

Referenced by closest_point_on_surface(), find_internal_spring_target_vertex(), blender::bke::Instances::reference_user_counts(), blender::bke::tests::TEST(), and blender::bke::Instances::unique_ids().

◆ drop_back()

template<typename T>
Span blender::Span< T >::drop_back ( int64_t n) const
inlineconstexpr

Returns a new Span with n elements removed from the end. This invokes undefined behavior when n is negative.

Definition at line 182 of file BLI_span.hh.

Referenced by blender::create_envelope_strokes().

◆ drop_front()

template<typename T>
Span blender::Span< T >::drop_front ( int64_t n) const
inlineconstexpr

Returns a new Span with n elements removed from the beginning. This invokes undefined behavior when n is negative.

Definition at line 171 of file BLI_span.hh.

Referenced by blender::InplacePriorityQueue< T, FirstHasHigherPriority >::inactive_indices(), and blender::bke::pbvh::update_normals_mesh().

◆ end()

template<typename T>
const T * blender::Span< T >::end ( ) const
inlineconstexpr

Definition at line 224 of file BLI_span.hh.

Referenced by blender::bke::pbvh::node_update_visibility_grids().

◆ first()

template<typename T>
const T & blender::Span< T >::first ( ) const
inlineconstexpr

Return a reference to the first element in the array. This invokes undefined behavior when the array is empty.

Definition at line 315 of file BLI_span.hh.

Referenced by version_geometry_nodes_extrude_smooth_propagation().

◆ first_index()

template<typename T>
int64_t blender::Span< T >::first_index ( const T & search_value) const
inlineconstexpr

Returns the index of the first occurrence of the given value. This invokes undefined behavior when the value is not in the array.

Definition at line 377 of file BLI_span.hh.

◆ first_index_try()

template<typename T>
int64_t blender::Span< T >::first_index_try ( const T & search_value) const
inlineconstexpr

Returns the index of the first occurrence of the given value or -1 if it does not exist.

Definition at line 387 of file BLI_span.hh.

◆ has_duplicates__linear_search()

template<typename T>
bool blender::Span< T >::has_duplicates__linear_search ( ) const
inlineconstexpr

Check if the array contains duplicates. Does a linear search for every element. So the total running time is O(n^2). Only use this for small arrays.

Definition at line 336 of file BLI_span.hh.

◆ hash()

template<typename T>
uint64_t blender::Span< T >::hash ( ) const
inlineconstexpr

Definition at line 406 of file BLI_span.hh.

◆ index_range()

template<typename T>
IndexRange blender::Span< T >::index_range ( ) const
inlineconstexpr

Utility to make it more convenient to iterate over all indices that can be used with this array.

Definition at line 401 of file BLI_span.hh.

Referenced by BPy_GeometrySet_get_instance_references(), blender::draw::interpolate_face_corner_attribute_to_curve(), paintvert_select_less(), paintvert_select_linked_vertices(), and paintvert_select_more().

◆ intersects__linear_search()

template<typename T>
bool blender::Span< T >::intersects__linear_search ( Span< T > other) const
inlineconstexpr

Returns true when this and the other array have an element in common. This should only be called on small arrays, because it has a running time of O(n*m) where n and m are the sizes of the arrays.

Definition at line 358 of file BLI_span.hh.

◆ is_empty()

◆ last()

template<typename T>
const T & blender::Span< T >::last ( const int64_t n = 0) const
inlineconstexpr

◆ operator[]()

template<typename T>
const T & blender::Span< T >::operator[] ( int64_t index) const
inlineconstexpr

Access an element in the array. This invokes undefined behavior when the index is out of bounds.

Definition at line 242 of file BLI_span.hh.

◆ rbegin()

template<typename T>
std::reverse_iterator< const T * > blender::Span< T >::rbegin ( ) const
inlineconstexpr

Definition at line 229 of file BLI_span.hh.

◆ rend()

template<typename T>
std::reverse_iterator< const T * > blender::Span< T >::rend ( ) const
inlineconstexpr

Definition at line 233 of file BLI_span.hh.

◆ size()

◆ size_in_bytes()

template<typename T>
int64_t blender::Span< T >::size_in_bytes ( ) const
inlineconstexpr

Returns the number of bytes referenced by this Span.

Definition at line 268 of file BLI_span.hh.

Referenced by blender::draw::extract_points_mesh(), blender::draw::extract_positions_mesh(), and blender::ed::sculpt_paint::undo::node_size_in_bytes().

◆ slice() [1/2]

template<typename T>
Span blender::Span< T >::slice ( IndexRange range) const
inlineconstexpr

Definition at line 145 of file BLI_span.hh.

◆ slice() [2/2]

◆ slice_safe() [1/2]

template<typename T>
Span blender::Span< T >::slice_safe ( const int64_t start,
const int64_t size ) const
inlineconstexpr

Returns a contiguous part of the array. This invokes undefined behavior when the start or size is negative. Clamps the size of the new span so it fits in the current one.

Definition at line 154 of file BLI_span.hh.

◆ slice_safe() [2/2]

template<typename T>
Span blender::Span< T >::slice_safe ( IndexRange range) const
inlineconstexpr

Definition at line 162 of file BLI_span.hh.

◆ take_back()

template<typename T>
Span blender::Span< T >::take_back ( int64_t n) const
inlineconstexpr

Returns a new Span that only contains the last n elements. This invokes undefined behavior when n is negative.

Definition at line 204 of file BLI_span.hh.

◆ take_front()

template<typename T>
Span blender::Span< T >::take_front ( int64_t n) const
inlineconstexpr

Returns a new Span that only contains the first n elements. This invokes undefined behavior when n is negative.

Definition at line 193 of file BLI_span.hh.

Referenced by blender::InplacePriorityQueue< T, FirstHasHigherPriority >::active_indices(), and blender::ed::sculpt_paint::undo::restore_mask_mesh().

◆ operator!=

template<typename T>
bool operator!= ( const Span< T > a,
const Span< T > b )
friend

Definition at line 433 of file BLI_span.hh.

◆ operator==

template<typename T>
bool operator== ( const Span< T > a,
const Span< T > b )
friend

Definition at line 425 of file BLI_span.hh.

Member Data Documentation

◆ data_

template<typename T>
const T* blender::Span< T >::data_ = nullptr
protected

Definition at line 85 of file BLI_span.hh.

◆ size_

template<typename T>
int64_t blender::Span< T >::size_ = 0
protected

Definition at line 86 of file BLI_span.hh.


The documentation for this class was generated from the following files: