Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
Arcane::Span< T, Extent > Class Template Reference

View of an array of elements of type T. More...

#include <arccore/base/Span.h>

Public Types

using ThatClass = Span<T, Extent>
using BaseClass = SpanImpl<T, Int64, Extent>
using size_type = Int64
using value_type = typename BaseClass::value_type
using pointer = typename BaseClass::pointer
template<typename X>
using is_same_const_type = std::enable_if_t<std::is_same_v<X, T> || std::is_same_v<std::add_const_t<X>, T>>
Public Types inherited from Arcane::SpanImpl< T, Int64, Extent >
using ThatClass
using SubSpanType
using size_type
using ElementType
using element_type
using value_type
using const_value_type
using index_type
using difference_type
using pointer
using const_pointer
using reference
using const_reference
using iterator
using const_iterator
using view_type
using reverse_iterator
using const_reverse_iterator
using is_same_const_type
 Indicates if 'X' or 'const X' can be converted to 'T'.

Public Member Functions

 Span ()=default
 Constructs an empty view.
constexpr __host__ __device__ Span (const ArrayView< value_type > &from) noexcept
 Copy constructor from another view.
template<typename X, typename = std::enable_if_t<std::is_same_v<X, value_type>>>
constexpr __host__ __device__ Span (const ConstArrayView< X > &from) noexcept
template<typename X, Int64 XExtent, typename = std::enable_if_t<std::is_same_v<const X, T>>>
constexpr __host__ __device__ Span (const Span< X, XExtent > &from) noexcept
template<typename X, Int32 XExtent, typename = std::enable_if_t<std::is_same_v<const X, T>>>
constexpr __host__ __device__ Span (const SmallSpan< X, XExtent > &from) noexcept
template<Int64 XExtent>
constexpr __host__ __device__ Span (const SpanImpl< T, Int64, XExtent > &from) noexcept
template<Int32 XExtent>
constexpr __host__ __device__ Span (const SpanImpl< T, Int32, XExtent > &from) noexcept
constexpr __host__ __device__ Span (pointer ptr, Int64 asize) noexcept
template<std::size_t N, typename X, typename = is_same_const_type<X>>
constexpr __host__ __device__ Span (std::array< X, N > &from) noexcept
 Constructs a view from a std::array.
constexpr __host__ __device__ Span (T *ptr)
 Constructs a view from a pointer with a fixed size.
template<std::size_t N, typename X, typename = is_same_const_type<X>>
constexpr __host__ __device__ ThatClass & operator= (std::array< X, N > &from) noexcept
 Copy assignment operator.
constexpr __host__ __device__ Span< T, DynExtentsubspan (Int64 abegin, Int64 asize) const
 Sub-view starting from element abegin and containing asize elements.
constexpr __host__ __device__ Span< T, DynExtentsubSpan (Int64 abegin, Int64 asize) const
 Sub-view starting from element abegin and containing asize elements.
constexpr __host__ __device__ Span< T, DynExtentsubPart (Int64 abegin, Int64 asize) const
 Sub-view starting from element abegin and containing asize elements.
constexpr __host__ __device__ Span< T, DynExtentsubSpanInterval (Int64 index, Int64 nb_interval) const
 Sub-view corresponding to the interval index over nb_interval.
constexpr __host__ __device__ Span< T, DynExtentsubPartInterval (Int64 index, Int64 nb_interval) const
 Sub-view corresponding to the interval index over nb_interval.
constexpr __host__ __device__ Span< T > subView (Int64 abegin, Int64 asize) const
 Sub-view starting from element abegin and containing asize elements.
constexpr __host__ __device__ Span< T > subViewInterval (Int64 index, Int64 nb_interval) const
 Sub-view corresponding to the interval index over nb_interval.
Public Member Functions inherited from Arcane::SpanImpl< T, Int64, Extent >
constexpr __host__ __device__ SpanImpl () noexcept
 Constructs an empty view.
constexpr __host__ __device__ SpanImpl (const SpanImpl< X, Int64, XExtent > &from) noexcept
 Copy constructor from another view.
constexpr __host__ __device__ SpanImpl (const SpanImpl< T, Int64, XExtent > &from) noexcept
constexpr __host__ __device__ SpanImpl (pointer ptr, Int64 asize) noexcept
constexpr __host__ __device__ SpanImpl (std::array< X, N > &from)
 Constructs a view from a std::array.
constexpr __host__ __device__ SpanImpl (T *ptr)
 Constructs a view from a pointer with a fixed size.
constexpr __host__ __device__ ThatClass & operator= (std::array< X, N > &from)
 Copy assignment operator.
constexpr __host__ __device__ reference operator[] (Int64 i) const
 i-th element of the array.
constexpr __host__ __device__ reference operator() (Int64 i) const
 i-th element of the array.
constexpr __host__ __device__ reference item (Int64 i) const
 i-th element of the array.
constexpr __host__ __device__ void setItem (Int64 i, const_reference v) noexcept
 Sets the i-th element of the array.
constexpr __host__ __device__ Int64 size () const noexcept
 Returns the size of the array.
constexpr __host__ __device__ Int64 sizeBytes () const noexcept
 Returns the size of the array in bytes.
constexpr __host__ __device__ Int64 length () const noexcept
 Number of elements in the array.
constexpr __host__ __device__ iterator begin () const noexcept
 Iterator for the first element of the array.
constexpr __host__ __device__ iterator end () const noexcept
 Iterator for the element after the end of the array.
constexpr __host__ __device__ reverse_iterator rbegin () const noexcept
 Reverse iterator for the first element of the array.
constexpr __host__ __device__ reverse_iterator rend () const noexcept
 Reverse iterator for the element after the end of the array.
ArrayRange< pointer > range () const
 Iteration range from the first to the last element.
constexpr __host__ __device__ pointer ptrAt (Int64 index) const
 Address of the index-th element.
constexpr __host__ __device__ reference at (Int64 i) const
constexpr __host__ __device__ void setAt (Int64 i, const_reference value)
__host__ __device__ void fill (T o)
 Fills the array with the value o.
constexpr view_type smallView ()
 Constant view of this view.
constexpr ConstArrayView< value_type > constSmallView () const
 Constant view of this view.
constexpr __host__ __device__ SubSpanType subSpan (Int64 abegin, Int64 asize) const
 Sub-view starting from element abegin and containing asize elements.
constexpr __host__ __device__ SubSpanType subPart (Int64 abegin, Int64 asize) const
 Sub-view starting from element abegin and containing asize elements.
constexpr SubSpanType subView (Int64 abegin, Int64 asize) const
 Sub-view starting from element abegin and containing asize elements.
constexpr __host__ __device__ SubSpanType subspan (Int64 abegin, Int64 asize) const
 For C++20 compatibility.
constexpr SubSpanType subViewInterval (Int64 index, Int64 nb_interval) const
 Sub-view corresponding to the interval index over nb_interval.
constexpr SubSpanType subSpanInterval (Int64 index, Int64 nb_interval) const
 Sub-view corresponding to the interval index over nb_interval.
constexpr SubSpanType subPartInterval (Int64 index, Int64 nb_interval) const
 Sub-view corresponding to the interval index over nb_interval.
__host__ __device__ void copy (const U &copy_array)
 Copies the array copy_array into the instance.
constexpr __host__ __device__ bool empty () const noexcept
 Returns true if the array is empty (zero dimension).
__host__ __device__ bool contains (const_reference v) const
 Returns true if the array contains the element with value v.
std::optional< Int64findFirst (const_reference v) const
constexpr __host__ __device__ void setArray (const ArrayView< T > &v) noexcept
constexpr __host__ __device__ void setArray (const Span< T > &v) noexcept
constexpr __host__ __device__ pointer data () const noexcept
 Pointer to the start of the view.
constexpr __host__ __device__ SpanImpl () noexcept
 Constructs an empty view.
constexpr __host__ __device__ SpanImpl (const SpanImpl< X, Int64, XExtent > &from) noexcept
 Copy constructor from another view.
constexpr __host__ __device__ SpanImpl (const SpanImpl< T, Int64, XExtent > &from) noexcept
constexpr __host__ __device__ SpanImpl (pointer ptr, Int64 asize) noexcept
constexpr __host__ __device__ SpanImpl (std::array< X, N > &from)
 Constructs a view from a std::array.
constexpr __host__ __device__ SpanImpl (T *ptr)
 Constructs a view from a pointer with a fixed size.
constexpr __host__ __device__ ThatClass & operator= (std::array< X, N > &from)
 Copy assignment operator.
constexpr __host__ __device__ reference operator[] (Int64 i) const
 i-th element of the array.
constexpr __host__ __device__ reference operator() (Int64 i) const
 i-th element of the array.
constexpr __host__ __device__ reference item (Int64 i) const
 i-th element of the array.
constexpr __host__ __device__ void setItem (Int64 i, const_reference v) noexcept
 Sets the i-th element of the array.
constexpr __host__ __device__ Int64 size () const noexcept
 Returns the size of the array.
constexpr __host__ __device__ Int64 sizeBytes () const noexcept
 Returns the size of the array in bytes.
constexpr __host__ __device__ Int64 length () const noexcept
 Number of elements in the array.
constexpr __host__ __device__ iterator begin () const noexcept
 Iterator for the first element of the array.
constexpr __host__ __device__ iterator end () const noexcept
 Iterator for the element after the end of the array.
constexpr __host__ __device__ reverse_iterator rbegin () const noexcept
 Reverse iterator for the first element of the array.
constexpr __host__ __device__ reverse_iterator rend () const noexcept
 Reverse iterator for the element after the end of the array.
ArrayRange< pointer > range () const
 Iteration range from the first to the last element.
constexpr __host__ __device__ pointer ptrAt (Int64 index) const
 Address of the index-th element.
constexpr __host__ __device__ reference at (Int64 i) const
constexpr __host__ __device__ void setAt (Int64 i, const_reference value)
__host__ __device__ void fill (T o)
 Fills the array with the value o.
constexpr view_type smallView ()
 Constant view of this view.
constexpr ConstArrayView< value_type > constSmallView () const
 Constant view of this view.
constexpr __host__ __device__ SubSpanType subSpan (Int64 abegin, Int64 asize) const
 Sub-view starting from element abegin and containing asize elements.
constexpr __host__ __device__ SubSpanType subPart (Int64 abegin, Int64 asize) const
 Sub-view starting from element abegin and containing asize elements.
constexpr SubSpanType subView (Int64 abegin, Int64 asize) const
 Sub-view starting from element abegin and containing asize elements.
constexpr __host__ __device__ SubSpanType subspan (Int64 abegin, Int64 asize) const
 For C++20 compatibility.
constexpr SubSpanType subViewInterval (Int64 index, Int64 nb_interval) const
 Sub-view corresponding to the interval index over nb_interval.
constexpr SubSpanType subSpanInterval (Int64 index, Int64 nb_interval) const
 Sub-view corresponding to the interval index over nb_interval.
constexpr SubSpanType subPartInterval (Int64 index, Int64 nb_interval) const
 Sub-view corresponding to the interval index over nb_interval.
__host__ __device__ void copy (const U &copy_array)
 Copies the array copy_array into the instance.
constexpr __host__ __device__ bool empty () const noexcept
 Returns true if the array is empty (zero dimension).
__host__ __device__ bool contains (const_reference v) const
 Returns true if the array contains the element with value v.
std::optional< Int64findFirst (const_reference v) const
constexpr __host__ __device__ void setArray (const ArrayView< T > &v) noexcept
constexpr __host__ __device__ void setArray (const Span< T > &v) noexcept
constexpr __host__ __device__ pointer data () const noexcept
 Pointer to the start of the view.

Static Public Member Functions

static constexpr ThatClass create (pointer ptr, size_type asize) noexcept
 Constructs a view on a memory area starting at ptr and.
Static Public Member Functions inherited from Arcane::SpanImpl< T, Int64, Extent >
static constexpr ThatClass create (pointer ptr, Int64 asize) noexcept
 Constructs a view on a memory region starting at ptr and.
static constexpr ThatClass create (pointer ptr, Int64 asize) noexcept
 Constructs a view on a memory region starting at ptr and.

Static Public Attributes

static constexpr bool IsDynamic = (Extent == DynExtent)
Static Public Attributes inherited from Arcane::SpanImpl< T, Int64, Extent >
static constexpr bool IsDynamic
static constexpr bool IsDynamic

Additional Inherited Members

Protected Member Functions inherited from Arcane::SpanImpl< T, Int64, Extent >
constexpr void _setArray (pointer v, Int64 s) noexcept
 Modifies the array pointer and size.
constexpr void _setPtr (pointer v) noexcept
 Modifies the array start pointer.
constexpr void _setSize (Int64 s) noexcept
 Modifies the array size.
constexpr void _setArray (pointer v, Int64 s) noexcept
 Modifies the array pointer and size.
constexpr void _setPtr (pointer v) noexcept
 Modifies the array start pointer.
constexpr void _setSize (Int64 s) noexcept
 Modifies the array size.

Detailed Description

template<typename T, Int64 Extent>
class Arcane::Span< T, Extent >

View of an array of elements of type T.

The view is non-modifiable if the template argument is of type 'const T'. Cette class allows accessing and using an array of elements of type T in the same way as a standard C array. It is similar to ArrayView, except that the number of elements is stored as an 'Int64' and can therefore exceed 2GB. It is designed to be similar to the C++20 std::span class.

Definition at line 633 of file Span.h.

Member Typedef Documentation

◆ BaseClass

template<typename T, Int64 Extent>
using Arcane::Span< T, Extent >::BaseClass = SpanImpl<T, Int64, Extent>

Definition at line 639 of file Span.h.

◆ is_same_const_type

template<typename T, Int64 Extent>
template<typename X>
using Arcane::Span< T, Extent >::is_same_const_type = std::enable_if_t<std::is_same_v<X, T> || std::is_same_v<std::add_const_t<X>, T>>

Definition at line 644 of file Span.h.

◆ pointer

template<typename T, Int64 Extent>
using Arcane::Span< T, Extent >::pointer = typename BaseClass::pointer

Definition at line 642 of file Span.h.

◆ size_type

template<typename T, Int64 Extent>
using Arcane::Span< T, Extent >::size_type = Int64

Definition at line 640 of file Span.h.

◆ ThatClass

template<typename T, Int64 Extent>
using Arcane::Span< T, Extent >::ThatClass = Span<T, Extent>

Definition at line 638 of file Span.h.

◆ value_type

template<typename T, Int64 Extent>
using Arcane::Span< T, Extent >::value_type = typename BaseClass::value_type

Definition at line 641 of file Span.h.

Constructor & Destructor Documentation

◆ Span() [1/9]

template<typename T, Int64 Extent>
__host__ __device__ Arcane::Span< T, Extent >::Span ( const ArrayView< value_type > & from)
inlineconstexprnoexcept

Copy constructor from another view.

Definition at line 652 of file Span.h.

◆ Span() [2/9]

template<typename T, Int64 Extent>
template<typename X, typename = std::enable_if_t<std::is_same_v<X, value_type>>>
__host__ __device__ Arcane::Span< T, Extent >::Span ( const ConstArrayView< X > & from)
inlineconstexprnoexcept

Definition at line 658 of file Span.h.

◆ Span() [3/9]

template<typename T, Int64 Extent>
template<typename X, Int64 XExtent, typename = std::enable_if_t<std::is_same_v<const X, T>>>
__host__ __device__ Arcane::Span< T, Extent >::Span ( const Span< X, XExtent > & from)
inlineconstexprnoexcept

Definition at line 663 of file Span.h.

◆ Span() [4/9]

template<typename T, Int64 Extent>
template<typename X, Int32 XExtent, typename = std::enable_if_t<std::is_same_v<const X, T>>>
__host__ __device__ Arcane::Span< T, Extent >::Span ( const SmallSpan< X, XExtent > & from)
inlineconstexprnoexcept

Definition at line 668 of file Span.h.

◆ Span() [5/9]

template<typename T, Int64 Extent>
template<Int64 XExtent>
__host__ __device__ Arcane::Span< T, Extent >::Span ( const SpanImpl< T, Int64, XExtent > & from)
inlineconstexprnoexcept

Definition at line 672 of file Span.h.

◆ Span() [6/9]

template<typename T, Int64 Extent>
template<Int32 XExtent>
__host__ __device__ Arcane::Span< T, Extent >::Span ( const SpanImpl< T, Int32, XExtent > & from)
inlineconstexprnoexcept

Definition at line 676 of file Span.h.

◆ Span() [7/9]

template<typename T, Int64 Extent>
__host__ __device__ Arcane::Span< T, Extent >::Span ( pointer ptr,
Int64 asize )
inlineconstexprnoexcept

Constructs a view on a memory area starting at ptr and containing asize elements.

Definition at line 682 of file Span.h.

◆ Span() [8/9]

template<typename T, Int64 Extent>
template<std::size_t N, typename X, typename = is_same_const_type<X>>
__host__ __device__ Arcane::Span< T, Extent >::Span ( std::array< X, N > & from)
inlineconstexprnoexcept

Constructs a view from a std::array.

Definition at line 688 of file Span.h.

◆ Span() [9/9]

template<typename T, Int64 Extent>
__host__ __device__ Arcane::Span< T, Extent >::Span ( T * ptr)
inlineexplicitconstexpr

Constructs a view from a pointer with a fixed size.

Definition at line 693 of file Span.h.

Member Function Documentation

◆ create()

template<typename T, Int64 Extent>
constexpr ThatClass Arcane::Span< T, Extent >::create ( pointer ptr,
size_type asize )
inlinestaticconstexprnoexcept

Constructs a view on a memory area starting at ptr and.

Definition at line 710 of file Span.h.

◆ operator=()

template<typename T, Int64 Extent>
template<std::size_t N, typename X, typename = is_same_const_type<X>>
__host__ __device__ ThatClass & Arcane::Span< T, Extent >::operator= ( std::array< X, N > & from)
inlineconstexprnoexcept

Copy assignment operator.

Definition at line 699 of file Span.h.

◆ subPart()

template<typename T, Int64 Extent>
__host__ __device__ Span< T, DynExtent > Arcane::Span< T, Extent >::subPart ( Int64 abegin,
Int64 asize ) const
inlineconstexpr

Sub-view starting from element abegin and containing asize elements.

If (abegin+asize) is greater than the size of the array, the view is truncated to this size, potentially returning an empty view.

Definition at line 748 of file Span.h.

◆ subPartInterval()

template<typename T, Int64 Extent>
__host__ __device__ Span< T, DynExtent > Arcane::Span< T, Extent >::subPartInterval ( Int64 index,
Int64 nb_interval ) const
inlineconstexpr

Sub-view corresponding to the interval index over nb_interval.

Definition at line 760 of file Span.h.

◆ subSpan()

template<typename T, Int64 Extent>
__host__ __device__ Span< T, DynExtent > Arcane::Span< T, Extent >::subSpan ( Int64 abegin,
Int64 asize ) const
inlineconstexpr

Sub-view starting from element abegin and containing asize elements.

If (abegin+asize) is greater than the size of the array, the view is truncated to this size, potentially returning an empty view.

Definition at line 736 of file Span.h.

◆ subspan()

template<typename T, Int64 Extent>
__host__ __device__ Span< T, DynExtent > Arcane::Span< T, Extent >::subspan ( Int64 abegin,
Int64 asize ) const
inlineconstexpr

Sub-view starting from element abegin and containing asize elements.

If (abegin+asize is greater than the size of the array, the view is truncated to this size, potentially returning an empty view.

Definition at line 724 of file Span.h.

Referenced by Arcane::Span< DataType >::subView().

◆ subSpanInterval()

template<typename T, Int64 Extent>
__host__ __device__ Span< T, DynExtent > Arcane::Span< T, Extent >::subSpanInterval ( Int64 index,
Int64 nb_interval ) const
inlineconstexpr

Sub-view corresponding to the interval index over nb_interval.

Definition at line 754 of file Span.h.

◆ subView()

template<typename T, Int64 Extent>
__host__ __device__ Span< T > Arcane::Span< T, Extent >::subView ( Int64 abegin,
Int64 asize ) const
inlineconstexpr

Sub-view starting from element abegin and containing asize elements.

If (abegin+asize) is greater than the size of the array, the view is truncated to this size, potentially returning an empty view.

Definition at line 773 of file Span.h.

◆ subViewInterval()

template<typename T, Int64 Extent>
__host__ __device__ Span< T > Arcane::Span< T, Extent >::subViewInterval ( Int64 index,
Int64 nb_interval ) const
inlineconstexpr

Sub-view corresponding to the interval index over nb_interval.

Definition at line 780 of file Span.h.

Member Data Documentation

◆ IsDynamic

template<typename T, Int64 Extent>
bool Arcane::Span< T, Extent >::IsDynamic = (Extent == DynExtent)
staticconstexpr

Definition at line 645 of file Span.h.


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