Modifiable view of an array of type T. More...
#include <arccore/base/ArrayView.h>
Public Types | |
| using | ThatClass = ArrayView<T> |
| typedef T | value_type |
| Type of the array elements. | |
| typedef value_type * | pointer |
| Pointer type of an array element. | |
| typedef const value_type * | const_pointer |
| Constant pointer type of an array element. | |
| typedef ArrayIterator< pointer > | iterator |
| Type of the iterator over an array element. | |
| typedef ArrayIterator< const_pointer > | const_iterator |
| Type of the constant iterator over an array element. | |
| typedef value_type & | reference |
| Reference type of an array element. | |
| typedef const value_type & | const_reference |
| Constant reference type of an array element. | |
| typedef Integer | size_type |
| Type indexing the array. | |
| typedef std::ptrdiff_t | difference_type |
| Type of a distance between array iterator elements. | |
| typedef IterT< ArrayView< T > > | iter |
| Type of an iterator over the entire array. | |
| typedef ConstIterT< ArrayView< T > > | const_iter |
| Type of a constant iterator over the entire array. | |
| typedef std::reverse_iterator< iterator > | reverse_iterator |
| typedef std::reverse_iterator< const_iterator > | const_reverse_iterator |
Public Member Functions | |
| constexpr | ArrayView () noexcept |
| Constructs an empty view. | |
| ArrayView (const ArrayView< T > &from)=default | |
| Copy constructor from another view. | |
| constexpr | ArrayView (Integer asize, pointer ptr) noexcept |
| Constructs a view over a memory region starting at ptr and. | |
| template<std::size_t N> | |
| constexpr | ArrayView (std::array< T, N > &v) |
| ArrayView< T > & | operator= (const ArrayView< T > &from)=default |
| Copy assignment operator. | |
| template<std::size_t N> | |
| constexpr ArrayView< T > & | operator= (std::array< T, N > &from) |
| constexpr reference | operator[] (Integer i) |
| i-th element of the array. | |
| constexpr const_reference | operator[] (Integer i) const |
| i-th element of the array. | |
| constexpr reference | operator() (Integer i) |
| i-th element of the array. | |
| constexpr const_reference | operator() (Integer i) const |
| i-th element of the array. | |
| constexpr const_reference | item (Integer i) const |
| i-th element of the array. | |
| constexpr void | setItem (Integer i, const_reference v) |
| Sets the i-th element of the array. | |
| constexpr Integer | size () const noexcept |
| Returns the size of the array. | |
| constexpr Integer | length () const noexcept |
| Number of elements in the array. | |
| constexpr iterator | begin () noexcept |
| Iterator to the first element of the array. | |
| constexpr iterator | end () noexcept |
| Iterator to the first element after the end of the array. | |
| constexpr const_iterator | begin () const noexcept |
| Constant iterator to the first element of the array. | |
| constexpr const_iterator | end () const noexcept |
| Constant iterator to the first element after the end of the array. | |
| constexpr reverse_iterator | rbegin () noexcept |
| Reverse iterator to the first element of the array. | |
| constexpr const_reverse_iterator | rbegin () const noexcept |
| Reverse iterator to the first element of the array. | |
| constexpr reverse_iterator | rend () noexcept |
| Reverse iterator to the first element after the end of the array. | |
| constexpr const_reverse_iterator | rend () const noexcept |
| Reverse iterator to the first element after the end of the array. | |
| ArrayRange< pointer > | range () |
| Iteration range from the first to the last element. | |
| ArrayRange< const_pointer > | range () const |
| Iteration range from the first to the last element. | |
| constexpr pointer | ptrAt (Integer index) |
| Address of the index-th element. | |
| constexpr const_pointer | ptrAt (Integer index) const |
| Address of the index-th element. | |
| constexpr const_reference | at (Integer i) const |
| void | setAt (Integer i, const_reference value) |
| void | fill (const T &o) noexcept |
| Fills the array with the value o. | |
| constexpr ConstArrayView< T > | constView () const noexcept |
| Constant view of this view. | |
| constexpr ArrayView< T > | subView (Integer abegin, Integer asize) noexcept |
| Sub-view starting from element abegin and containing asize elements. | |
| constexpr ThatClass | subPart (Integer abegin, Integer asize) noexcept |
| Sub-view starting from element abegin and containing asize elements. | |
| constexpr ConstArrayView< T > | subConstView (Integer abegin, Integer asize) const noexcept |
| Constant sub-view starting from element abegin and containing asize elements. | |
| constexpr ArrayView< T > | subViewInterval (Integer index, Integer nb_interval) |
| Sub-view corresponding to the interval index over nb_interval. | |
| constexpr ThatClass | subPartInterval (Integer index, Integer nb_interval) |
| Sub-view corresponding to the interval index over nb_interval. | |
| template<class U> | |
| void | copy (const U ©_array) |
| Copies the array copy_array into the instance. | |
| constexpr bool | empty () const noexcept |
| Returns true if the array is empty (zero dimension). | |
| bool | contains (const_reference v) const |
| true if the array contains the element with value v | |
| void | setArray (const ArrayView< T > &v) noexcept |
| constexpr pointer | unguardedBasePointer () noexcept |
| Pointer to the beginning of the view. | |
| constexpr const_pointer | unguardedBasePointer () const noexcept |
| Constant pointer to the start of the view. | |
| constexpr const_pointer | data () const noexcept |
| Pointer to the start of the view. | |
| constexpr pointer | data () noexcept |
| Constant pointer to the start of the view. | |
Static Public Member Functions | |
| static constexpr ThatClass | create (pointer ptr, Integer asize) noexcept |
| Constructs a view over a memory region starting at ptr and. | |
Protected Member Functions | |
| constexpr pointer | _ptr () noexcept |
| Returns a pointer to the array. | |
| constexpr const_pointer | _ptr () const noexcept |
| Returns a pointer to the array. | |
| void | _setArray (pointer v, Integer s) noexcept |
| Modifies the pointer and size of the array. | |
| void | _setPtr (pointer v) noexcept |
| Modifies the pointer to the start of the array. | |
| void | _setSize (Integer s) noexcept |
| Modifies the size of the array. | |
Friends | |
| template<typename T2, Int64 Extent> | |
| class | Span |
| template<typename T2, Int32 Extent> | |
| class | SmallSpan |
| bool | operator== (const ArrayView< T > &rhs, const ArrayView< T > &lhs) |
| bool | operator!= (const ArrayView< T > &rhs, const ArrayView< T > &lhs) |
| std::ostream & | operator<< (std::ostream &o, const ArrayView< T > &val) |
Modifiable view of an array of type T.
This template class allows accessing and using an array of elements of type T in the same way as a standard C array. It also maintains the size of the array. The size() function allows knowing the number of elements in the array, and the operator operator[]() allows accessing a given element.
It is guaranteed that all elements of the view are consecutive in memory.
This class does not manage any memory; the associated container manages it. Possible containers provided by Arccore are the classes Array, UniqueArray or SharedArray. A view is only valid as long as the associated container is not reallocated. Similarly, the constructor and the copy operator only copy the pointers without reallocating memory. Therefore, they must be used with caution.
If Arccore is compiled in check mode (ARCCORE_CHECK is defined), accesses via the operator operator[]() are checked, and an IndexOutOfRangeException exception is thrown if an array overflow occurs. By attaching a debug session to the process, it is possible to see the call stack at the time of the overflow.
Here are some usage examples:
It is also possible to access the array elements using iterators in the same way as with STL containers.
The following example creates an iterator i on the array a and iterates over the entire array (method i()) and displays the elements:
The following example calculates the sum of the first 3 elements of the array:
Definition at line 95 of file arccore/src/base/arccore/base/ArrayView.h.
| typedef ConstIterT<ArrayView<T> > Arcane::ArrayView< T >::const_iter |
Type of a constant iterator over the entire array.
Definition at line 126 of file arccore/src/base/arccore/base/ArrayView.h.
| typedef ArrayIterator<const_pointer> Arcane::ArrayView< T >::const_iterator |
Type of the constant iterator over an array element.
Definition at line 113 of file arccore/src/base/arccore/base/ArrayView.h.
| typedef const value_type* Arcane::ArrayView< T >::const_pointer |
Constant pointer type of an array element.
Definition at line 109 of file arccore/src/base/arccore/base/ArrayView.h.
| typedef const value_type& Arcane::ArrayView< T >::const_reference |
Constant reference type of an array element.
Definition at line 117 of file arccore/src/base/arccore/base/ArrayView.h.
| typedef std::reverse_iterator<const_iterator> Arcane::ArrayView< T >::const_reverse_iterator |
Definition at line 129 of file arccore/src/base/arccore/base/ArrayView.h.
| typedef std::ptrdiff_t Arcane::ArrayView< T >::difference_type |
Type of a distance between array iterator elements.
Definition at line 121 of file arccore/src/base/arccore/base/ArrayView.h.
| typedef IterT<ArrayView<T> > Arcane::ArrayView< T >::iter |
Type of an iterator over the entire array.
Definition at line 124 of file arccore/src/base/arccore/base/ArrayView.h.
| typedef ArrayIterator<pointer> Arcane::ArrayView< T >::iterator |
Type of the iterator over an array element.
Definition at line 111 of file arccore/src/base/arccore/base/ArrayView.h.
| typedef value_type* Arcane::ArrayView< T >::pointer |
Pointer type of an array element.
Definition at line 107 of file arccore/src/base/arccore/base/ArrayView.h.
| typedef value_type& Arcane::ArrayView< T >::reference |
Reference type of an array element.
Definition at line 115 of file arccore/src/base/arccore/base/ArrayView.h.
| typedef std::reverse_iterator<iterator> Arcane::ArrayView< T >::reverse_iterator |
Definition at line 128 of file arccore/src/base/arccore/base/ArrayView.h.
| typedef Integer Arcane::ArrayView< T >::size_type |
Type indexing the array.
Definition at line 119 of file arccore/src/base/arccore/base/ArrayView.h.
| using Arcane::ArrayView< T >::ThatClass = ArrayView<T> |
Definition at line 102 of file arccore/src/base/arccore/base/ArrayView.h.
| typedef T Arcane::ArrayView< T >::value_type |
Type of the array elements.
Definition at line 105 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Constructs an empty view.
Definition at line 134 of file arccore/src/base/arccore/base/ArrayView.h.
Referenced by Arcane::CaseOptionMultiEnumT< T >::_allocate(), Arcane::CaseOptionMultiSimpleT< T >::operator ArrayView< T >(), Arcane::CaseOptionMultiSimpleT< T >::operator ConstArrayView< T >(), Arcane::ArrayView< Type >::subView(), and Arcane::VariableRefArrayT< T >::VariableRefArrayT().
|
inlineconstexprnoexcept |
Constructs a view over a memory region starting at ptr and.
Definition at line 144 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexpr |
Constructs a view over a memory region starting at ptr and containing asize elements.
Definition at line 152 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprprotectednoexcept |
Returns a pointer to the array.
This method is identical to unguardedBasePointer() (i.e.: it will be necessary to consider deleting it)
Definition at line 495 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprprotectednoexcept |
Returns a pointer to the array.
This method is identical to unguardedBasePointer() (i.e.: it will be necessary to consider deleting it)
Definition at line 488 of file arccore/src/base/arccore/base/ArrayView.h.
Referenced by Arcane::CaseOptionMultiSimpleT< T >::print().
|
inlineprotectednoexcept |
Modifies the pointer and size of the array.
It is up to the derived class to verify the consistency between the pointer allocated and the given dimension.
Definition at line 503 of file arccore/src/base/arccore/base/ArrayView.h.
Referenced by Arcane::CaseOptionMultiSimpleT< T >::_search().
|
inlineprotectednoexcept |
Modifies the pointer to the start of the array.
It is up to the derived class to verify the consistency between the pointer allocated and the given dimension.
Definition at line 515 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineprotectednoexcept |
Modifies the size of the array.
It is up to the derived class to verify the consistency between the pointer allocated and the given dimension.
Definition at line 523 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexpr |
Definition at line 299 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Constant iterator to the first element of the array.
Definition at line 255 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Iterator to the first element of the array.
Definition at line 251 of file arccore/src/base/arccore/base/ArrayView.h.
Referenced by Arcane::ArrayView< Type >::rend(), and Arcane::ArrayView< Type >::rend().
|
inlineconstexprnoexcept |
Constant view of this view.
Definition at line 322 of file arccore/src/base/arccore/base/ArrayView.h.
Referenced by Arcane::math::mult().
|
inline |
true if the array contains the element with value v
Definition at line 405 of file arccore/src/base/arccore/base/ArrayView.h.
|
inline |
Copies the array copy_array into the instance.
Since no memory allocation is performed, the number of elements in copy_array must be less than or equal to the current number of elements. If it is smaller, the elements of the current array located at the end of the array remain unchanged.
Definition at line 390 of file arccore/src/base/arccore/base/ArrayView.h.
Referenced by Arcane::MessagePassing::namedBarrier(), and Arcane::ItemGroupImpl::setItems().
|
inlinestaticconstexprnoexcept |
Constructs a view over a memory region starting at ptr and.
Definition at line 172 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Pointer to the start of the view.
Definition at line 450 of file arccore/src/base/arccore/base/ArrayView.h.
Referenced by Arcane::math::add(), Arcane::math::add(), Arcane::DataTypeTraitsT< Real2 >::fillNan(), Arcane::DataTypeTraitsT< Real2x2 >::fillNan(), Arcane::DataTypeTraitsT< Real3 >::fillNan(), Arcane::DataTypeTraitsT< Real3x3 >::fillNan(), Arcane::math::mult(), Arcane::math::mult(), Arcane::ConstArrayView< Type >::operator=(), Arcane::math::power(), Arcane::Hdf5Utils::StandardArrayT< DataType >::read(), Arcane::math::sub(), and Arcane::math::sub().
|
inlineconstexprnoexcept |
Constant pointer to the start of the view.
Definition at line 460 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Returns true if the array is empty (zero dimension).
Definition at line 403 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Constant iterator to the first element after the end of the array.
Definition at line 257 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Iterator to the first element after the end of the array.
Definition at line 253 of file arccore/src/base/arccore/base/ArrayView.h.
Referenced by Arcane::ArrayView< Type >::rbegin(), and Arcane::ArrayView< Type >::rbegin().
|
inlinenoexcept |
Fills the array with the value o.
Definition at line 313 of file arccore/src/base/arccore/base/ArrayView.h.
Referenced by Arcane::MessagePassing::mpWait(), and Arcane::MessagePassing::namedBarrier().
|
inlineconstexpr |
i-th element of the array.
In check mode, checks for overflows.
Definition at line 228 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Number of elements in the array.
Definition at line 248 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexpr |
i-th element of the array.
In check mode, checks for overflows.
Definition at line 206 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexpr |
i-th element of the array.
In check mode, checks for overflows.
Definition at line 217 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexpr |
Definition at line 161 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexpr |
i-th element of the array.
In check mode, checks for overflows.
Definition at line 184 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexpr |
i-th element of the array.
In check mode, checks for overflows.
Definition at line 195 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexpr |
Address of the index-th element.
Definition at line 285 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexpr |
Address of the index-th element.
Definition at line 292 of file arccore/src/base/arccore/base/ArrayView.h.
|
inline |
Iteration range from the first to the last element.
Definition at line 271 of file arccore/src/base/arccore/base/ArrayView.h.
|
inline |
Iteration range from the first to the last element.
Definition at line 277 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Reverse iterator to the first element of the array.
Definition at line 261 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Reverse iterator to the first element of the array.
Definition at line 259 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Reverse iterator to the first element after the end of the array.
Definition at line 265 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Reverse iterator to the first element after the end of the array.
Definition at line 263 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlinenoexcept |
Definition at line 416 of file arccore/src/base/arccore/base/ArrayView.h.
|
inline |
Definition at line 306 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexpr |
Sets the i-th element of the array.
In check mode, checks for overflows.
Definition at line 239 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Returns the size of the array.
Definition at line 246 of file arccore/src/base/arccore/base/ArrayView.h.
Referenced by Arcane::CaseOptionMultiEnumT< T >::_allocate(), Arcane::CaseOptionMultiEnumT< T >::_nbElem(), Arcane::math::add(), Arcane::math::add(), Arcane::IBinaryMathFunctor< Arg1, Arg2, ReturnType >::apply(), Arcane::VariableRefArrayT< DataType >::arraySize(), Arcane::ItemGroupImpl::changeIds(), Arcane::DataTypeTraitsT< Real2 >::fillNan(), Arcane::DataTypeTraitsT< Real2x2 >::fillNan(), Arcane::DataTypeTraitsT< Real3 >::fillNan(), Arcane::DataTypeTraitsT< Real3x3 >::fillNan(), Arcane::math::mult(), Arcane::math::mult(), Arcane::MessagePassing::namedBarrier(), Arcane::ConstArrayView< Type >::operator=(), Arcane::math::power(), Arcane::MeshUtils::removeItemAndKeepOrder(), Arcane::math::sub(), Arcane::math::sub(), and Arcane::math::truncateDouble().
|
inlineconstexprnoexcept |
Constant 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 361 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
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 349 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexpr |
Sub-view corresponding to the interval index over nb_interval.
Definition at line 376 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
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 334 of file arccore/src/base/arccore/base/ArrayView.h.
Referenced by Arcane::ArrayView< Type >::subPart().
|
inlineconstexpr |
Sub-view corresponding to the interval index over nb_interval.
Definition at line 370 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Constant pointer to the start of the view.
Definition at line 440 of file arccore/src/base/arccore/base/ArrayView.h.
|
inlineconstexprnoexcept |
Pointer to the beginning of the view.
Definition at line 430 of file arccore/src/base/arccore/base/ArrayView.h.
Referenced by Arcane::MessagePassing::namedBarrier().
Definition at line 469 of file arccore/src/base/arccore/base/ArrayView.h.
|
friend |
Definition at line 474 of file arccore/src/base/arccore/base/ArrayView.h.
Definition at line 464 of file arccore/src/base/arccore/base/ArrayView.h.
Definition at line 98 of file arccore/src/base/arccore/base/ArrayView.h.
Definition at line 97 of file arccore/src/base/arccore/base/ArrayView.h.