Blender  V2.93
Public Types | Public Member Functions | Friends | List of all members
blender::Span< T > Class Template Reference

#include <BLI_span.hh>

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 , typename std::enable_if_t< is_span_convertible_pointer_v< U, T >> * = nullptr>
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 , typename std::enable_if_t< is_span_convertible_pointer_v< U, T >> * = nullptr>
constexpr Span (Span< U > span)
 
constexpr Span slice (int64_t start, int64_t size) const
 
constexpr Span slice (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
 
constexpr T get (int64_t index, const T &fallback) 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
 
template<typename NewT >
constexpr Span< NewT > cast () const
 
template<typename PrintLineF >
void print_as_lines (std::string name, PrintLineF print_line) const
 
void print_as_lines (std::string name) const
 

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 blender::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 87 of file BLI_span.hh.

Member Typedef Documentation

◆ const_pointer

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

Definition at line 91 of file BLI_span.hh.

◆ const_reference

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

Definition at line 93 of file BLI_span.hh.

◆ iterator

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

Definition at line 94 of file BLI_span.hh.

◆ pointer

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

Definition at line 90 of file BLI_span.hh.

◆ reference

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

Definition at line 92 of file BLI_span.hh.

◆ size_type

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

Definition at line 95 of file BLI_span.hh.

◆ value_type

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

Definition at line 89 of file BLI_span.hh.

Constructor & Destructor Documentation

◆ Span() [1/7]

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

◆ Span() [2/7]

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

Definition at line 107 of file BLI_span.hh.

References BLI_assert, data_, and blender::Span< T >::size().

◆ Span() [3/7]

template<typename T >
template<typename U , typename std::enable_if_t< is_span_convertible_pointer_v< U, T >> * = nullptr>
constexpr blender::Span< T >::Span ( const U start,
int64_t  size 
)
inlineconstexpr

Definition at line 113 of file BLI_span.hh.

References BLI_assert, data_, and blender::Span< T >::size().

◆ Span() [4/7]

template<typename T >
constexpr 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 129 of file BLI_span.hh.

◆ Span() [5/7]

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

Definition at line 134 of file BLI_span.hh.

◆ Span() [6/7]

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

Definition at line 139 of file BLI_span.hh.

◆ Span() [7/7]

template<typename T >
template<typename U , typename std::enable_if_t< is_span_convertible_pointer_v< U, T >> * = nullptr>
constexpr blender::Span< T >::Span ( Span< U span)
inlineconstexpr

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

Definition at line 148 of file BLI_span.hh.

References data_.

Member Function Documentation

◆ begin()

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

◆ cast()

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

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

Definition at line 422 of file BLI_span.hh.

References BLI_assert, data_, and T.

Referenced by blender::nodes::MFNetworkTreeMap::add_try_match(), and blender::tests::TEST().

◆ contains()

template<typename T >
constexpr 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 279 of file BLI_span.hh.

References element, and T.

Referenced by blender::Span< T >::intersects__linear_search(), and blender::tests::TEST().

◆ contains_ptr()

template<typename T >
constexpr 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 293 of file BLI_span.hh.

References blender::Span< T >::begin(), blender::Span< T >::end(), and ptr.

Referenced by blender::tests::TEST().

◆ count()

template<typename T >
constexpr 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 302 of file BLI_span.hh.

References element, and T.

Referenced by blender::nodes::separate_points_from_component(), and blender::tests::TEST().

◆ data()

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

◆ drop_back()

template<typename T >
constexpr Span blender::Span< T >::drop_back ( 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 184 of file BLI_span.hh.

References BLI_assert, data_, and blender::Span< T >::Span().

Referenced by compute_geometry(), modifyGeometry(), node_errors_tooltip_fn(), and blender::tests::TEST().

◆ drop_front()

template<typename T >
constexpr 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 173 of file BLI_span.hh.

References BLI_assert, data_, and blender::Span< T >::Span().

Referenced by compute_geometry(), blender::InplacePriorityQueue< T, FirstHasHigherPriority >::inactive_indices(), blender::Stack< T, InlineBufferCapacity, Allocator >::push_multiple(), and blender::tests::TEST().

◆ end()

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

◆ first()

template<typename T >
constexpr 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 317 of file BLI_span.hh.

References BLI_assert, and data_.

Referenced by blender::IndexMask::as_range(), blender::IndexMask::is_range(), and blender::tests::TEST().

◆ first_index()

template<typename T >
constexpr 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 390 of file BLI_span.hh.

References BLI_assert, and blender::Span< T >::first_index_try().

Referenced by blender::fn::MFFunctionNode::input_for_param(), blender::fn::MFFunctionNode::output_for_param(), and blender::tests::TEST().

◆ first_index_try()

template<typename T >
constexpr 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 400 of file BLI_span.hh.

References data_.

Referenced by blender::Span< T >::first_index().

◆ get()

template<typename T >
constexpr T blender::Span< T >::get ( int64_t  index,
const T fallback 
) const
inlineconstexpr

Returns the element at the given index. If the index is out of range, return the fallback value.

Definition at line 337 of file BLI_span.hh.

References data_.

Referenced by compute_vertex_mask__armature_mode(), and blender::tests::TEST().

◆ has_duplicates__linear_search()

template<typename T >
constexpr 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 349 of file BLI_span.hh.

References BLI_assert, data_, and T.

◆ index_range()

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

◆ intersects__linear_search()

template<typename T >
constexpr 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 371 of file BLI_span.hh.

References BLI_assert, blender::Span< T >::contains(), data_, and T.

◆ is_empty()

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

◆ last()

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

Returns a reference to the last element in the array. This invokes undefined behavior when the array is empty.

Definition at line 327 of file BLI_span.hh.

References BLI_assert, and data_.

Referenced by blender::IndexMask::is_range(), blender::IndexMask::last(), blender::IndexMask::min_array_size(), node_errors_tooltip_fn(), and blender::tests::TEST().

◆ operator[]()

template<typename T >
constexpr 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 244 of file BLI_span.hh.

References BLI_assert, and data_.

◆ print_as_lines() [1/2]

template<typename T >
void blender::Span< T >::print_as_lines ( std::string  name) const
inline

A debug utility to print the content of the span. Every element be printed on a separate line.

Definition at line 460 of file BLI_span.hh.

References blender::Span< T >::print_as_lines(), and T.

◆ print_as_lines() [2/2]

template<typename T >
template<typename PrintLineF >
void blender::Span< T >::print_as_lines ( std::string  name,
PrintLineF  print_line 
) const
inline

A debug utility to print the content of the Span. Every element will be printed on a separate line using the given callback.

Definition at line 446 of file BLI_span.hh.

References T.

Referenced by blender::Span< T >::print_as_lines().

◆ rbegin()

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

Definition at line 231 of file BLI_span.hh.

References blender::Span< T >::end().

Referenced by blender::tests::TEST().

◆ rend()

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

Definition at line 235 of file BLI_span.hh.

References blender::Span< T >::begin().

Referenced by blender::tests::TEST().

◆ size()

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

Returns the number of elements in the referenced array.

Definition at line 254 of file BLI_span.hh.

Referenced by blender::fn::MFNetwork::add_dummy(), blender::IndexMask::as_range(), compute_masked_vertices(), blender::nodes::compute_special_attributes(), computed_masked_polygons(), blender::LinearAllocator< Allocator >::construct_array_copy(), blender::MutableSpan< T >::copy_from(), copy_masked_edges_to_new_mesh(), copy_masked_vertices_to_new_mesh(), blender::double3::cross_poly(), blender::gpu::ShaderInterface::debug_print(), blender::meshintersect::direct_mesh_boolean(), blender::ed::spreadsheet::SpreadsheetLayoutDrawer::draw_float_vector(), blender::VectorAdaptor< T >::extend(), generate_unique_instance_ids(), blender::nodes::geo_node_point_distribute_exec(), blender::nodes::DOutputSocket::get_active_corresponding_group_output_socket(), get_dupliface_transform_from_coords(), gpu_select_query_end(), blender::IndexMask::IndexMask(), blender::nodes::interpolate_attribute_corner(), blender::nodes::interpolate_attribute_face(), blender::nodes::interpolate_attribute_point(), blender::nodes::interpolate_existing_attributes(), blender::IndexMask::is_range(), blender::nodes::MFNetworkTreeMap::lookup_dummy(), blender::string_search::match_word_initials(), blender::IndexMask::min_array_size(), modifyGeometry(), blender::dot::NodeWithSocketsRef::NodeWithSocketsRef(), blender::gpu::Shader::print_log(), blender::Stack< T, InlineBufferCapacity, Allocator >::push_multiple(), blender::string_search::score_query_against_words(), blender::IndexMask::size(), blender::Span< T >::slice(), blender::Span< T >::Span(), spreadsheet_main_region_draw(), blender::ed::spreadsheet::SpreadsheetLayoutDrawer::SpreadsheetLayoutDrawer(), blender::tests::TEST(), blender::tests::test_ref_from_initializer_list(), and blender::gpu::GLShader::transform_feedback_names_set().

◆ size_in_bytes()

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

Returns the number of bytes referenced by this Span.

Definition at line 270 of file BLI_span.hh.

References T.

Referenced by blender::tests::TEST().

◆ slice() [1/2]

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

◆ slice() [2/2]

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

Returns a contiguous part of the array. This invokes undefined behavior when the start or size is negative.

Definition at line 156 of file BLI_span.hh.

References BLI_assert, data_, min, blender::Span< T >::size(), and blender::Span< T >::Span().

Referenced by blender::Span< T >::slice(), and blender::tests::TEST().

◆ take_back()

template<typename T >
constexpr 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 206 of file BLI_span.hh.

References BLI_assert, data_, and blender::Span< T >::Span().

Referenced by blender::tests::TEST().

◆ take_front()

template<typename T >
constexpr 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 195 of file BLI_span.hh.

References BLI_assert, data_, and blender::Span< T >::Span().

Referenced by blender::InplacePriorityQueue< T, FirstHasHigherPriority >::active_indices(), and blender::tests::TEST().

Friends And Related Function Documentation

◆ operator!=

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

Definition at line 437 of file BLI_span.hh.

◆ operator==

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

Definition at line 429 of file BLI_span.hh.


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