Arcane  4.2.1.0
User documentation
Loading...
Searching...
No Matches
Span.h
Go to the documentation of this file.
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Span.h (C) 2000-2026 */
9/* */
10/* Views on C arrays. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_BASE_SPAN_H
13#define ARCCORE_BASE_SPAN_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19#include <type_traits>
20#include <optional>
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane::Impl
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31// To indicate that Span<T>::view() returns an ArrayView
32// and Span<const T>::view() returns a ConstArrayView.
33template <typename T>
35{
36 public:
37
38 using view_type = ArrayView<T>;
39};
40template <typename T>
41class ViewTypeT<const T>
42{
43 public:
44
45 using view_type = ConstArrayView<T>;
46};
47
48//! To have the type (SmallSpan or Span) depending on the size (Int32 or Int64)
49template <typename T, typename SizeType>
51
52template <typename T>
54{
55 public:
56
57 using SpanType = SmallSpan<T>;
58};
59
60template <typename T>
62{
63 public:
64
65 using SpanType = Span<T>;
66};
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
70/*!
71 * \brief Class to store the size of a SpanImpl.
72 *
73 * If Extent != DynExtent, it is not necessary to keep
74 * track of the number of elements in a field of the instance.
75 */
76template <typename SizeType>
77class DynamicExtentStorage
78{
79 template <typename T, typename SpanSizeType, SpanSizeType SpanExtent>
80 friend class ::Arcane::SpanImpl;
81
82 public:
83
84 explicit constexpr DynamicExtentStorage(SizeType s) noexcept
85 : m_size(s)
86 {}
87
88 public:
89
90 constexpr SizeType size() const noexcept { return m_size; }
91
92 private:
93
94 SizeType m_size;
95};
96
97class ARCCORE_BASE_EXPORT ExtentStorageBase
98{
99 public:
100
101 static void _throwBadSize [[noreturn]] (Int64 wanted_size, Int64 expected_size);
102};
103
104//! Specialization for the compile-time known number of elements
105template <typename SizeType, SizeType FixedExtent>
106class ExtentStorage
107{
108 template <typename T, typename SpanSizeType, SpanSizeType SpanExtent>
109 friend class ::Arcane::SpanImpl;
110
111 public:
112
113 explicit constexpr ExtentStorage([[maybe_unused]] SizeType s) noexcept
114 {
115#if defined(ARCCORE_CHECK) && !defined(ARCCORE_DEVICE_CODE)
116 if (s != FixedExtent)
117 ExtentStorageBase::_throwBadSize(s, FixedExtent);
118#endif
119 }
120 ExtentStorage() = default;
121
122 public:
123
124 constexpr SizeType size() const noexcept { return FixedExtent; }
125
126 private:
127
128 static constexpr SizeType m_size = FixedExtent;
129};
130
131//! Specialization for the dynamic number of elements
132template <>
133class ExtentStorage<Int32, DynExtent>
134: public DynamicExtentStorage<Int32>
135{
136 using BaseClass = DynamicExtentStorage<Int32>;
137
138 public:
139
140 explicit constexpr ExtentStorage(Int32 s) noexcept
141 : BaseClass(s)
142 {}
143};
144
145//! Specialization for the dynamic number of elements
146template <>
147class ExtentStorage<Int64, DynExtent>
148: public DynamicExtentStorage<Int64>
149{
150 using BaseClass = DynamicExtentStorage<Int64>;
151
152 public:
153
154 explicit constexpr ExtentStorage(Int64 s) noexcept
155 : BaseClass(s)
156 {}
157};
158
159/*---------------------------------------------------------------------------*/
160/*---------------------------------------------------------------------------*/
161
162} // namespace Arcane::Impl
163
164/*---------------------------------------------------------------------------*/
165/*---------------------------------------------------------------------------*/
166
167namespace Arcane
168{
169
170/*---------------------------------------------------------------------------*/
171/*---------------------------------------------------------------------------*/
172/*!
173 * \ingroup Collection
174 * \brief View of an array of elements of type \a T.
175 *
176 * This class should not be used directly. Span or SmallSpan must be used instead.
177 *
178 * The view is non-modifiable if the template argument is of type 'const T'.
179 * This class allows accessing and using an array of elements of type \a T
180 * in the same way as a standard C array. \a SizeType is the
181 * type used to store the number of elements in the array. This can
182 * be 'Int32' or 'Int64'.
183 *
184 * If \a Extent is different from DynExtent (the default), the size is
185 * variable; otherwise, it is fixed and has the value \a Extent.
186 */
187template <typename T, typename SizeType, SizeType Extent>
189{
190 using ExtentStorageType = Impl::ExtentStorage<SizeType, Extent>;
191
192 public:
193
194 using ThatClass = SpanImpl<T, SizeType, Extent>;
195 using SubSpanType = SpanImpl<T, SizeType, DynExtent>;
196 using size_type = SizeType;
197 using ElementType = T;
198 using element_type = ElementType;
199 using value_type = typename std::remove_cv_t<ElementType>;
200 using const_value_type = typename std::add_const_t<value_type>;
201 using index_type = SizeType;
202 using difference_type = SizeType;
203 using pointer = ElementType*;
204 using const_pointer = const ElementType*;
205 using reference = ElementType&;
206 using const_reference = const ElementType&;
207 using iterator = ArrayIterator<pointer>;
208 using const_iterator = ArrayIterator<const_pointer>;
209 using view_type = typename Impl::ViewTypeT<ElementType>::view_type;
210 using reverse_iterator = std::reverse_iterator<iterator>;
211 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
212
213 //! Indicates if 'X' or 'const X' can be converted to 'T'
214 template <typename X>
215 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>>;
216
217 static constexpr bool IsDynamic = (Extent == DynExtent);
218
219 public:
220
221 //! Constructs an empty view.
222 constexpr ARCCORE_HOST_DEVICE SpanImpl() noexcept
223 : m_ptr(nullptr)
224 , m_size(0)
225 {}
226
227 //! Copy constructor from another view
228 // For a Span<const T>, it is allowed to construct from a Span<T>
229 template <typename X, SizeType XExtent, typename = std::enable_if_t<std::is_same_v<const X, T>>>
230 constexpr ARCCORE_HOST_DEVICE SpanImpl(const SpanImpl<X, SizeType, XExtent>& from) noexcept
231 : m_ptr(from.data())
232 , m_size(from.size())
233 {}
234
235 template <SizeType XExtent>
236 constexpr ARCCORE_HOST_DEVICE SpanImpl(const SpanImpl<T, SizeType, XExtent>& from) noexcept
237 : m_ptr(from.data())
238 , m_size(from.size())
239 {}
240
241 //! Constructs a view on a memory region starting at \a ptr and
242 //! containing \a asize elements.
243 constexpr ARCCORE_HOST_DEVICE SpanImpl(pointer ptr, SizeType asize) noexcept
244 : m_ptr(ptr)
245 , m_size(asize)
246 {}
247
248 //! Constructs a view from a std::array
249 template <std::size_t N, typename X, typename = is_same_const_type<X>>
250 constexpr ARCCORE_HOST_DEVICE SpanImpl(std::array<X, N>& from)
251 : m_ptr(from.data())
252 , m_size(ArraySizeChecker<SizeType>::check(from.size()))
253 {}
254
255 //! Constructs a view from a pointer with a fixed size
256 explicit constexpr ARCCORE_HOST_DEVICE SpanImpl(T* ptr) requires(!IsDynamic)
257 : m_ptr(ptr)
258 {}
259
260 //! Copy assignment operator
261 template <std::size_t N, typename X, typename = is_same_const_type<X>>
262 constexpr ARCCORE_HOST_DEVICE ThatClass& operator=(std::array<X, N>& from)
263 {
264 m_ptr = from.data();
265 m_size = ExtentStorageType(ArraySizeChecker<SizeType>::check(from.size()));
266 return (*this);
267 }
268
269 public:
270
271 //! Constructs a view on a memory region starting at \a ptr and
272 // containing \a asize elements.
273 static constexpr ThatClass create(pointer ptr, SizeType asize) noexcept
274 {
275 return ThatClass(ptr, asize);
276 }
277
278 public:
279
280 /*!
281 * \brief i-th element of the array.
282 *
283 * In \a check mode, bounds checking is performed.
284 */
285 constexpr ARCCORE_HOST_DEVICE reference operator[](SizeType i) const
286 {
287 ARCCORE_CHECK_AT(i, m_size.m_size);
288 return m_ptr[i];
289 }
290
291 /*!
292 * \brief i-th element of the array.
293 *
294 * In \a check mode, bounds checking is performed.
295 */
296 constexpr ARCCORE_HOST_DEVICE reference operator()(SizeType i) const
297 {
298 ARCCORE_CHECK_AT(i, m_size.m_size);
299 return m_ptr[i];
300 }
301
302 /*!
303 * \brief i-th element of the array.
304 *
305 * In \a check mode, bounds checking is performed.
306 */
307 constexpr ARCCORE_HOST_DEVICE reference item(SizeType i) const
308 {
309 ARCCORE_CHECK_AT(i, m_size.m_size);
310 return m_ptr[i];
311 }
312
313 /*!
314 * \brief Sets the i-th element of the array.
315 *
316 * In \a check mode, bounds checking is performed.
317 */
318 constexpr ARCCORE_HOST_DEVICE void setItem(SizeType i, const_reference v) noexcept
319 {
320 ARCCORE_CHECK_AT(i, m_size.m_size);
321 m_ptr[i] = v;
322 }
323
324 //! Returns the size of the array
325 constexpr ARCCORE_HOST_DEVICE SizeType size() const noexcept { return m_size.m_size; }
326 //! Returns the size of the array in bytes
327 constexpr ARCCORE_HOST_DEVICE SizeType sizeBytes() const noexcept
328 {
329 // TODO: always return an Int64
330 return static_cast<SizeType>(m_size.m_size * sizeof(value_type));
331 }
332 //! Number of elements in the array
333 constexpr ARCCORE_HOST_DEVICE SizeType length() const noexcept { return m_size.m_size; }
334
335 /*!
336 * \brief Iterator for the first element of the array.
337 */
338 constexpr ARCCORE_HOST_DEVICE iterator begin() const noexcept { return iterator(m_ptr); }
339 /*!
340 * \brief Iterator for the element after the end of the array.
341 */
342 constexpr ARCCORE_HOST_DEVICE iterator end() const noexcept { return iterator(m_ptr + m_size.m_size); }
343 //! Reverse iterator for the first element of the array.
344 constexpr ARCCORE_HOST_DEVICE reverse_iterator rbegin() const noexcept { return std::make_reverse_iterator(end()); }
345 //! Reverse iterator for the element after the end of the array.
346 constexpr ARCCORE_HOST_DEVICE reverse_iterator rend() const noexcept { return std::make_reverse_iterator(begin()); }
347
348 public:
349
350 //! Iteration range from the first to the last element.
351 ARCCORE_DEPRECATED_REASON("Y2023: Use begin()/end() instead")
352 ArrayRange<pointer> range() const
353 {
354 return ArrayRange<pointer>(m_ptr, m_ptr + m_size.m_size);
355 }
356
357 public:
358
359 //! Address of the index-th element
360 constexpr ARCCORE_HOST_DEVICE pointer ptrAt(SizeType index) const
361 {
362 ARCCORE_CHECK_AT(index, m_size.m_size);
363 return m_ptr + index;
364 }
365
366 // Element at index \a i. Always checks for bounds.
367 constexpr ARCCORE_HOST_DEVICE reference at(SizeType i) const
368 {
369 arccoreCheckAt(i, m_size.m_size);
370 return m_ptr[i];
371 }
372
373 // Sets the element at index \a i. Always checks for bounds.
374 constexpr ARCCORE_HOST_DEVICE void setAt(SizeType i, const_reference value)
375 {
376 arccoreCheckAt(i, m_size.m_size);
377 m_ptr[i] = value;
378 }
379
380 //! Fills the array with the value \a o
381 ARCCORE_HOST_DEVICE inline void fill(T o)
382 {
383 for (SizeType i = 0, n = m_size.m_size; i < n; ++i)
384 m_ptr[i] = o;
385 }
386
387 /*!
388 * \brief Constant view of this view.
389 */
390 constexpr view_type smallView()
391 {
392 Integer s = arccoreCheckArraySize(m_size.m_size);
393 return view_type(s, m_ptr);
394 }
395
396 /*!
397 * \brief Constant view of this view.
398 */
400 {
401 Integer s = arccoreCheckArraySize(m_size.m_size);
402 return ConstArrayView<value_type>(s, m_ptr);
403 }
404
405 /*!
406 * \brief Sub-view starting from element \a abegin
407 * and containing \a asize elements.
408 *
409 * If `(abegin+asize` is greater than the size of the array,
410 * the view is truncated to this size, potentially returning an empty view.
411 */
412 constexpr ARCCORE_HOST_DEVICE SubSpanType subSpan(SizeType abegin, SizeType asize) const
413 {
414 if (abegin >= m_size.m_size)
415 return {};
416 asize = _min(asize, m_size.m_size - abegin);
417 return { m_ptr + abegin, asize };
418 }
419
420 /*!
421 * \brief Sub-view starting from element \a abegin and containing \a asize elements.
422 * \sa subSpan()
423 */
424 constexpr ARCCORE_HOST_DEVICE SubSpanType subPart(SizeType abegin, SizeType asize) const
425 {
426 return subSpan(abegin, asize);
427 }
428
429 /*!
430 * \brief Sub-view starting from element \a abegin
431 * and containing \a asize elements.
432 *
433 * If `(abegin+asize)` is greater than the size of the array,
434 * the view is truncated to this size, potentially returning an empty view.
435 */
436 ARCCORE_DEPRECATED_REASON("Y2023: use subSpan() instead")
437 constexpr SubSpanType subView(SizeType abegin, SizeType asize) const
438 {
439 return subSpan(abegin, asize);
440 }
441
442 //! For C++20 compatibility
443 constexpr ARCCORE_HOST_DEVICE SubSpanType subspan(SizeType abegin, SizeType asize) const
444 {
445 return subSpan(abegin, asize);
446 }
447
448 //! Sub-view corresponding to the interval \a index over \a nb_interval
449 ARCCORE_DEPRECATED_REASON("Y2023: use subSpanInterval() instead")
450 constexpr SubSpanType subViewInterval(SizeType index, SizeType nb_interval) const
451 {
452 return Arcane::Impl::subViewInterval<ThatClass>(*this, index, nb_interval);
453 }
454
455 //! Sub-view corresponding to the interval \a index over \a nb_interval
456 constexpr SubSpanType subSpanInterval(SizeType index, SizeType nb_interval) const
457 {
458 return Arcane::Impl::subViewInterval<ThatClass>(*this, index, nb_interval);
459 }
460
461 //! Sub-view corresponding to the interval \a index over \a nb_interval
462 constexpr SubSpanType subPartInterval(SizeType index, SizeType nb_interval) const
463 {
464 return Arcane::Impl::subViewInterval<ThatClass>(*this, index, nb_interval);
465 }
466
467 /*!
468 * \brief Copies the array \a copy_array into the instance.
469 *
470 * Since no memory allocation is performed, the
471 * number of elements in \a copy_array must be less than or equal to the
472 * current number of elements. If it is smaller, the elements of the
473 * current array located at the end of the array remain unchanged.
474 */
475 template <class U> ARCCORE_HOST_DEVICE void copy(const U& copy_array)
476 {
477 Int64 n = copy_array.size();
478 Int64 size_as_int64 = m_size.m_size;
479 arccoreCheckAt(n, size_as_int64 + 1);
480 const_pointer copy_begin = copy_array.data();
481 pointer to_ptr = m_ptr;
482 // We are sure that \a fits into a 'SizeType' because it is smaller
483 // than \a m_size
484 SizeType n_as_sizetype = static_cast<SizeType>(n);
485 for (SizeType i = 0; i < n_as_sizetype; ++i)
486 to_ptr[i] = copy_begin[i];
487 }
488
489 //! Returns \a true if the array is empty (zero dimension)
490 constexpr ARCCORE_HOST_DEVICE bool empty() const noexcept { return m_size.m_size == 0; }
491 //! Returns \a true if the array contains the element with value \a v
492 ARCCORE_HOST_DEVICE bool contains(const_reference v) const
493 {
494 for (SizeType i = 0; i < m_size.m_size; ++i) {
495 if (m_ptr[i] == v)
496 return true;
497 }
498 return false;
499 }
500
501 /*!
502 * /brief Position of the first element with value \a v
503 *
504 * /param v The value to find.
505 * /return The position of the first element with value \a v if present, std::nullopt otherwise.
506 */
507 std::optional<SizeType> findFirst(const_reference v) const
508 {
509 for (SizeType i = 0; i < m_size.m_size; ++i) {
510 if (m_ptr[i] == v)
511 return i;
512 }
513 return std::nullopt;
514 }
515
516 public:
517
518 constexpr ARCCORE_HOST_DEVICE void setArray(const ArrayView<T>& v) noexcept
519 {
520 m_ptr = v.m_ptr;
521 m_size = v.m_size;
522 }
523 constexpr ARCCORE_HOST_DEVICE void setArray(const Span<T>& v) noexcept
524 {
525 m_ptr = v.m_ptr;
526 m_size = v.m_size;
527 }
528
529 /*!
530 * \brief Pointer to the start of the view.
531 *
532 * \warning Accesses via the returned pointer cannot be
533 * checked by Arcane, unlike accesses via
534 * operator[](): no overflow checking is possible,
535 * even in check mode.
536 */
537 constexpr ARCCORE_HOST_DEVICE pointer data() const noexcept { return m_ptr; }
538
539 //! Equality operator (valid if T is const but not X)
540 template <typename X, SizeType Extent2, typename = std::enable_if_t<std::is_same_v<X, value_type>>> friend bool
542 {
543 return Arcane::Impl::areEqual(SpanImpl<T, SizeType>(rhs), SpanImpl<T, SizeType>(lhs));
544 }
545
546 //! Inequality operator (valid if T is const but not X)
547 template <typename X, SizeType Extent2, typename = std::enable_if_t<std::is_same_v<X, value_type>>> friend bool
549 {
550 return !operator==(rhs, lhs);
551 }
552
553 //! Equality operator
554 template <SizeType Extent2> friend bool
556 {
557 return Arcane::Impl::areEqual(SpanImpl<T, SizeType>(rhs), SpanImpl<T, SizeType>(lhs));
558 }
559
560 //! Inequality operator
561 template <SizeType Extent2> friend bool
563 {
564 return !operator==(rhs, lhs);
565 }
566
567 friend inline std::ostream& operator<<(std::ostream& o, const ThatClass& val)
568 {
569 Arcane::Impl::dumpArray(o, Span<const T, DynExtent>(val.data(), val.size()), 500);
570 return o;
571 }
572
573 protected:
574
575 /*!
576 * \brief Modifies the array pointer and size.
577 *
578 * It is up to the derived class to verify the consistency between the allocated pointer
579 * and the given dimension.
580 */
581 constexpr void _setArray(pointer v, SizeType s) noexcept
582 {
583 m_ptr = v;
584 m_size = s;
585 }
586
587 /*!
588 * \brief Modifies the array start pointer.
589 *
590 * It is up to the derived class to verify the consistency between the allocated pointer
591 * and the given dimension.
592 */
593 constexpr void _setPtr(pointer v) noexcept { m_ptr = v; }
594
595 /*!
596 * \brief Modifies the array size.
597 *
598 * It is up to the derived class to verify the consistency between the allocated pointer
599 * and the given dimension.
600 */
601 constexpr void _setSize(SizeType s) noexcept { m_size = ExtentStorageType(s); }
602
603 private:
604
605 pointer m_ptr; //!< Pointer to the array
606 //! Number of elements in the array
607 ARCCORE_NO_UNIQUE_ADDRESS ExtentStorageType m_size;
608
609 private:
610
611 static constexpr SizeType _min(SizeType a, SizeType b)
612 {
613 return ((a < b) ? a : b);
614 }
615};
616
617/*---------------------------------------------------------------------------*/
618/*---------------------------------------------------------------------------*/
619
620/*!
621 * \ingroup Collection
622 * \brief View of an array of elements of type \a T.
623 *
624 * The view is non-modifiable if the template argument is of type 'const T'.
625 Cette class allows accessing and using an array of elements of type \a T in
626 the same way as a standard C array. It is similar to ArrayView, except that
627 the number of elements is stored as an 'Int64' and can therefore exceed 2GB.
628 It is designed to be similar to the C++20 std::span class.
629*/
630template <typename T, Int64 Extent>
631class Span
632: public SpanImpl<T, Int64, Extent>
633{
634 public:
635
636 using ThatClass = Span<T, Extent>;
637 using BaseClass = SpanImpl<T, Int64, Extent>;
638 using size_type = Int64;
639 using value_type = typename BaseClass::value_type;
640 using pointer = typename BaseClass::pointer;
641 template <typename X>
642 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>>;
643 static constexpr bool IsDynamic = (Extent == DynExtent);
644
645 public:
646
647 //! Constructs an empty view.
648 Span() = default;
649 //! Copy constructor from another view
650 constexpr ARCCORE_HOST_DEVICE Span(const ArrayView<value_type>& from) noexcept
651 : BaseClass(from.m_ptr, from.m_size)
652 {}
653 // Constructor from a ConstArrayView. This is only allowed
654 // if T is const.
655 template <typename X, typename = std::enable_if_t<std::is_same_v<X, value_type>>>
656 constexpr ARCCORE_HOST_DEVICE Span(const ConstArrayView<X>& from) noexcept
657 : BaseClass(from.m_ptr, from.m_size)
658 {}
659 // For a Span<const T>, we are allowed to construct from a Span<T>
660 template <typename X, Int64 XExtent, typename = std::enable_if_t<std::is_same_v<const X, T>>>
661 constexpr ARCCORE_HOST_DEVICE Span(const Span<X, XExtent>& from) noexcept
662 : BaseClass(from)
663 {}
664 // For a Span<const T>, we are allowed to construct from a SmallSpan<T>
665 template <typename X, Int32 XExtent, typename = std::enable_if_t<std::is_same_v<const X, T>>>
666 constexpr ARCCORE_HOST_DEVICE Span(const SmallSpan<X, XExtent>& from) noexcept
667 : BaseClass(from.data(), from.size())
668 {}
669 template <Int64 XExtent>
670 constexpr ARCCORE_HOST_DEVICE Span(const SpanImpl<T, Int64, XExtent>& from) noexcept
671 : BaseClass(from)
672 {}
673 template <Int32 XExtent>
674 constexpr ARCCORE_HOST_DEVICE Span(const SpanImpl<T, Int32, XExtent>& from) noexcept
675 : BaseClass(from.data(), from.size())
676 {}
677
678 //! Constructs a view on a memory area starting at \a ptr and containing
679 //! \a asize elements.
680 constexpr ARCCORE_HOST_DEVICE Span(pointer ptr, Int64 asize) noexcept
681 : BaseClass(ptr, asize)
682 {}
683
684 //! Constructs a view from a std::array.
685 template <std::size_t N, typename X, typename = is_same_const_type<X>>
686 constexpr ARCCORE_HOST_DEVICE Span(std::array<X, N>& from) noexcept
687 : BaseClass(from.data(), from.size())
688 {}
689
690 //! Constructs a view from a pointer with a fixed size
691 explicit constexpr ARCCORE_HOST_DEVICE Span(T* ptr) requires(!IsDynamic)
692 : BaseClass(ptr)
693 {}
694
695 //! Copy assignment operator
696 template <std::size_t N, typename X, typename = is_same_const_type<X>>
697 constexpr ARCCORE_HOST_DEVICE ThatClass& operator=(std::array<X, N>& from) noexcept
698 {
699 this->_setPtr(from.data());
700 this->_setSize(from.size());
701 return (*this);
702 }
703
704 public:
705
706 //! Constructs a view on a memory area starting at \a ptr and
707 // containing \a asize elements.
708 static constexpr ThatClass create(pointer ptr, size_type asize) noexcept
709 {
710 return ThatClass(ptr, asize);
711 }
712
713 public:
714
715 /*!
716 * \brief Sub-view starting from element \a abegin
717 * and containing \a asize elements.
718 *
719 * If `(abegin+asize` is greater than the size of the array,
720 * the view is truncated to this size, potentially returning an empty view.
721 */
722 constexpr ARCCORE_HOST_DEVICE Span<T, DynExtent> subspan(Int64 abegin, Int64 asize) const
723 {
724 return BaseClass::subspan(abegin, asize);
725 }
726
727 /*!
728 * \brief Sub-view starting from element \a abegin
729 * and containing \a asize elements.
730 *
731 * If `(abegin+asize)` is greater than the size of the array,
732 * the view is truncated to this size, potentially returning an empty view.
733 */
734 constexpr ARCCORE_HOST_DEVICE Span<T, DynExtent> subSpan(Int64 abegin, Int64 asize) const
735 {
736 return BaseClass::subSpan(abegin, asize);
737 }
738
739 /*!
740 * \brief Sub-view starting from element \a abegin
741 * and containing \a asize elements.
742 *
743 * If `(abegin+asize)` is greater than the size of the array,
744 * the view is truncated to this size, potentially returning an empty view.
745 */
746 constexpr ARCCORE_HOST_DEVICE Span<T, DynExtent> subPart(Int64 abegin, Int64 asize) const
747 {
748 return BaseClass::subPart(abegin, asize);
749 }
750
751 //! Sub-view corresponding to the interval \a index over \a nb_interval
752 constexpr ARCCORE_HOST_DEVICE Span<T, DynExtent> subSpanInterval(Int64 index, Int64 nb_interval) const
753 {
754 return Arcane::Impl::subViewInterval<ThatClass>(*this, index, nb_interval);
755 }
756
757 //! Sub-view corresponding to the interval \a index over \a nb_interval
758 constexpr ARCCORE_HOST_DEVICE Span<T, DynExtent> subPartInterval(Int64 index, Int64 nb_interval) const
759 {
760 return Arcane::Impl::subViewInterval<ThatClass>(*this, index, nb_interval);
761 }
762
763 /*!
764 * \brief Sub-view starting from element \a abegin
765 * and containing \a asize elements.
766 *
767 * If `(abegin+asize)` is greater than the size of the array,
768 * the view is truncated to this size, potentially returning an empty view.
769 */
770 ARCCORE_DEPRECATED_REASON("Y2023: use subSpan() instead")
771 constexpr ARCCORE_HOST_DEVICE Span<T> subView(Int64 abegin, Int64 asize) const
772 {
773 return subspan(abegin, asize);
774 }
775
776 //! Sub-view corresponding to the interval \a index over \a nb_interval
777 ARCCORE_DEPRECATED_REASON("Y2023: use subSpanInterval() instead")
778 constexpr ARCCORE_HOST_DEVICE Span<T> subViewInterval(Int64 index, Int64 nb_interval) const
779 {
780 return Arcane::Impl::subViewInterval<ThatClass>(*this, index, nb_interval);
781 }
782};
783
784/*---------------------------------------------------------------------------*/
785/*---------------------------------------------------------------------------*/
786
787/*!
788 * \ingroup Collection
789 * \brief View of an array of elements of type \a T.
790 *
791 * The view is non-modifiable if the template argument is of type 'const T'.
792 *
793 * This class allows accessing and using an array of elements of type \a T
794 * in the same way as a standard C array. It is similar to Span, except
795 * that the number of elements is stored as an 'Int32'.
796 *
797 * \note To be valid, the number of bytes associated with the view
798 * (sizeBytes()) must also fit within an \a Int32.
799 */
800template <typename T, Int32 Extent>
802: public SpanImpl<T, Int32, Extent>
803{
804 public:
805
806 using ThatClass = SmallSpan<T, Extent>;
807 using BaseClass = SpanImpl<T, Int32, Extent>;
808 using size_type = Int32;
809 using value_type = typename BaseClass::value_type;
810 using pointer = typename BaseClass::pointer;
811 template <typename X>
812 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>>;
813 static constexpr bool IsDynamic = (Extent == DynExtent);
814
815 public:
816
817 //! Constructs an empty view.
818 SmallSpan() = default;
819
820 //! Copy constructor from another view
821 constexpr ARCCORE_HOST_DEVICE SmallSpan(const ArrayView<value_type>& from) noexcept
822 : BaseClass(from.m_ptr, from.m_size)
823 {}
824
825 // Constructor from a ConstArrayView. This is only allowed
826 // if T is const.
827 template <typename X, typename = std::enable_if_t<std::is_same<X, value_type>::value>>
828 constexpr ARCCORE_HOST_DEVICE SmallSpan(const ConstArrayView<X>& from) noexcept
829 : BaseClass(from.m_ptr, from.m_size)
830 {}
831
832 // For a Span<const T>, we are allowed to construct from a Span<T>
833 template <typename X, typename = std::enable_if_t<std::is_same<X, value_type>::value>>
834 constexpr ARCCORE_HOST_DEVICE SmallSpan(const SmallSpan<X>& from) noexcept
835 : BaseClass(from)
836 {}
837
838 template <Int32 XExtent>
839 constexpr ARCCORE_HOST_DEVICE SmallSpan(const SpanImpl<T, Int32, XExtent>& from) noexcept
840 : BaseClass(from)
841 {}
842
843 //! Constructs a view over a memory region starting at \a ptr and
844 //! containing \a asize elements.
845 constexpr ARCCORE_HOST_DEVICE SmallSpan(pointer ptr, Int32 asize) noexcept
846 : BaseClass(ptr, asize)
847 {}
848
849 template <std::size_t N, typename X, typename = is_same_const_type<X>>
850 constexpr ARCCORE_HOST_DEVICE SmallSpan(std::array<X, N>& from)
851 : BaseClass(from)
852 {}
853
854 //! Constructs a view from a pointer with a fixed size
855 explicit constexpr ARCCORE_HOST_DEVICE SmallSpan(T* ptr) requires(!IsDynamic)
856 : BaseClass(ptr)
857 {}
858
859 //! Copy assignment operator
860 template <std::size_t N, typename X, typename = is_same_const_type<X>>
861 constexpr ARCCORE_HOST_DEVICE ThatClass& operator=(std::array<X, N>& from)
862 {
864 return (*this);
865 }
866
867 public:
868
869 //! Constructs a view over a memory region starting at \a ptr and
870 // containing \a asize elements.
871 static constexpr ThatClass create(pointer ptr, size_type asize) noexcept
872 {
873 return ThatClass(ptr, asize);
874 }
875
876 public:
877
878 /*!
879 * \brief Sub-view starting from element \a abegin
880 * and containing \a asize elements.
881 *
882 * If `(abegin+asize` is greater than the array size,
883 * the view is truncated to that size, possibly returning an empty view.
884 */
885 constexpr ARCCORE_HOST_DEVICE SmallSpan<T, DynExtent> subspan(Int32 abegin, Int32 asize) const
886 {
887 return BaseClass::subspan(abegin, asize);
888 }
889
890 /*!
891 * \brief Sub-view starting from element \a abegin
892 * and containing \a asize elements.
893 *
894 * If `(abegin+asize)` is greater than the array size,
895 * the view is truncated to that size, possibly returning an empty view.
896 */
897 constexpr ARCCORE_HOST_DEVICE SmallSpan<T, DynExtent> subSpan(Int32 abegin, Int32 asize) const
898 {
899 return BaseClass::subSpan(abegin, asize);
900 }
901
902 /*!
903 * \brief Sub-view starting from element \a abegin
904 * and containing \a asize elements.
905 *
906 * If `(abegin+asize)` is greater than the array size,
907 * the view is truncated to that size, possibly returning an empty view.
908 */
909 constexpr ARCCORE_HOST_DEVICE SmallSpan<T, DynExtent> subPart(Int32 abegin, Int32 asize) const
910 {
911 return BaseClass::subSpan(abegin, asize);
912 }
913
914 //! Sub-view corresponding to the interval \a index over \a nb_interval
915 constexpr ARCCORE_HOST_DEVICE SmallSpan<T, DynExtent> subSpanInterval(Int32 index, Int32 nb_interval) const
916 {
917 return Arcane::Impl::subViewInterval<ThatClass>(*this, index, nb_interval);
918 }
919
920 //! Sub-view corresponding to the interval \a index over \a nb_interval
921 constexpr ARCCORE_HOST_DEVICE ThatClass subPartInterval(Int32 index, Int32 nb_interval) const
922 {
923 return subSpanInterval(index, nb_interval);
924 }
925
926 /*!
927 * \brief Sub-view starting from element \a abegin
928 * and containing \a asize elements.
929 *
930 * If `(abegin+asize)` is greater than the array size,
931 * the view is truncated to that size, possibly returning an empty view.
932 */
933 ARCCORE_DEPRECATED_REASON("Y2023: use subPart() instead")
934 constexpr ARCCORE_HOST_DEVICE SmallSpan<T> subView(Int32 abegin, Int32 asize) const
935 {
936 return subspan(abegin, asize);
937 }
938
939 //! Sub-view corresponding to the interval \a index over \a nb_interval
940 ARCCORE_DEPRECATED_REASON("Y2023: use subPartInterval() instead")
941 constexpr ARCCORE_HOST_DEVICE SmallSpan<T> subViewInterval(Int32 index, Int32 nb_interval) const
942 {
943 return Arcane::Impl::subViewInterval<ThatClass>(*this, index, nb_interval);
944 }
945};
946
947/*---------------------------------------------------------------------------*/
948/*---------------------------------------------------------------------------*/
949
950/*!
951 * \brief Prints the values of the array \a val to the stream \a o.
952 *
953 * If \a max_print is positive, at most \a max_print values
954 * are printed. If the array size is greater than
955 * \a max_print, then the first (max_print/2) and last
956 * elements are printed.
957 */
958template <typename T, typename SizeType> inline void
959dumpArray(std::ostream& o, SpanImpl<const T, SizeType> val, int max_print)
960{
961 Arcane::Impl::dumpArray(o, val, max_print);
962}
963
964/*---------------------------------------------------------------------------*/
965/*---------------------------------------------------------------------------*/
966
967/*!
968 * \brief Extracts a sub-array from a list of indices.
969 *
970 * Fills \a result with the values from the array \a values
971 * corresponding to the indices \a indexes.
972 *
973 * \pre results.size() >= indexes.size();
974 */
975template <typename DataType, typename IntegerType, typename SizeType> inline void
979{
980 const Int64 result_size = indexes.size();
981 [[maybe_unused]] const Int64 my_size = values.size();
982 const DataType* ptr = values.data();
983 for (Int64 i = 0; i < result_size; ++i) {
984 IntegerType index = indexes[i];
985 ARCCORE_CHECK_AT(index, my_size);
986 result[i] = ptr[index];
987 }
988}
989
990/*---------------------------------------------------------------------------*/
991/*---------------------------------------------------------------------------*/
992
993/*!
994 * \brief Extracts a sub-array from a list of indices.
995 *
996 * Fills \a result with the values from the array \a values
997 * corresponding to the indices \a indexes.
998 *
999 * \pre results.size() >= indexes.size();
1000 */
1001template <typename DataType> inline void
1003{
1004 _sampleSpan<DataType, Int64, Int64>(values, indexes, result);
1005}
1006
1007/*---------------------------------------------------------------------------*/
1008/*---------------------------------------------------------------------------*/
1009
1010/*!
1011 * \brief Extracts a sub-array from a list of indices.
1012 *
1013 * The result is stored in \a result, whose size must be at least
1014 * equal to that of \a indexes.
1015 */
1016template <typename DataType> inline void
1018{
1019 _sampleSpan<DataType, Int32, Int64>(values, indexes, result);
1020}
1021
1022/*---------------------------------------------------------------------------*/
1023/*---------------------------------------------------------------------------*/
1024
1025/*!
1026 * \brief Converts the view into an array of non-modifiable bytes.
1027 */
1028template <typename DataType, typename SizeType, SizeType Extent>
1029inline typename Impl::SpanTypeFromSize<const std::byte, SizeType>::SpanType
1031{
1032 return { reinterpret_cast<const std::byte*>(s.data()), s.sizeBytes() };
1033}
1034
1035/*!
1036 * \brief Converts the view into an array of non-modifiable bytes.
1037 */
1038template <typename DataType>
1039inline SmallSpan<const std::byte>
1041{
1042 return asBytes(SmallSpan<DataType>(s));
1043}
1044
1045/*!
1046 * \brief Converts the view into an array of non-modifiable bytes.
1047 */
1048template <typename DataType>
1049inline SmallSpan<const std::byte>
1054
1055/*---------------------------------------------------------------------------*/
1056/*---------------------------------------------------------------------------*/
1057
1058/*!
1059 * \brief Converts the view into an array of modifiable bytes.
1060 *
1061 * This method is only accessible if \a DataType is not `const`.
1062 */
1063template <typename DataType, typename SizeType, SizeType Extent,
1064 typename std::enable_if_t<!std::is_const<DataType>::value, int> = 0>
1065inline typename Impl::SpanTypeFromSize<std::byte, SizeType>::SpanType
1067{
1068 return { reinterpret_cast<std::byte*>(s.data()), s.sizeBytes() };
1069}
1070
1071/*!
1072 * \brief Converts the view into an array of modifiable bytes.
1073 *
1074 * This method is only accessible if \a DataType is not `const`.
1075 */
1076template <typename DataType> inline SmallSpan<std::byte>
1081
1082/*---------------------------------------------------------------------------*/
1083/*---------------------------------------------------------------------------*/
1084
1085namespace Impl
1086{
1087 template <typename ByteType, typename DataType, Int64 Extent> inline Span<DataType>
1088 asSpanInternal(Span<ByteType, Extent> bytes)
1089 {
1090 Int64 size = bytes.size();
1091 if (size == 0)
1092 return {};
1093 static constexpr Int64 data_type_size = static_cast<Int64>(sizeof(DataType));
1094 static_assert(data_type_size > 0, "Bad datatype size");
1095 ARCCORE_ASSERT((size % data_type_size) == 0, ("Size is not a multiple of sizeof(DataType)"));
1096 auto* ptr = reinterpret_cast<DataType*>(bytes.data());
1097 return { ptr, size / data_type_size };
1098 }
1099
1100 template <typename ByteType, typename DataType, Int32 Extent> inline SmallSpan<DataType>
1101 asSmallSpanInternal(SmallSpan<ByteType, Extent> bytes)
1102 {
1103 Int32 size = bytes.size();
1104 if (size == 0)
1105 return {};
1106 static constexpr Int32 data_type_size = static_cast<Int32>(sizeof(DataType));
1107 static_assert(data_type_size > 0, "Bad datatype size");
1108 ARCCORE_ASSERT((size % data_type_size) == 0, ("Size is not a multiple of sizeof(DataType)"));
1109 auto* ptr = reinterpret_cast<DataType*>(bytes.data());
1110 return { ptr, size / data_type_size };
1111 }
1112} // namespace Impl
1113
1114/*---------------------------------------------------------------------------*/
1115/*---------------------------------------------------------------------------*/
1116
1117/*!
1118 * \brief Converts a Span<std::byte> into a Span<DataType>.
1119 * \pre bytes.size() % sizeof(DataType) == 0;
1120 */
1121template <typename DataType, Int64 Extent> inline Span<DataType>
1123{
1124 return Arcane::Impl::asSpanInternal<std::byte, DataType, Extent>(bytes);
1125}
1126
1127/*!
1128 * \brief Converts a Span<std::byte> into a Span<const DataType>.
1129 * \pre bytes.size() % sizeof(DataType) == 0;
1130 */
1131template <typename DataType, Int64 Extent> inline Span<const DataType>
1133{
1134 return Arcane::Impl::asSpanInternal<const std::byte, const DataType, Extent>(bytes);
1135}
1136
1137/*!
1138 * \brief Converts a SmallSpan<std::byte> into a SmallSpan<DataType>.
1139 * \pre bytes.size() % sizeof(DataType) == 0;
1140 */
1141template <typename DataType, Int32 Extent> inline SmallSpan<DataType>
1143{
1144 return Arcane::Impl::asSmallSpanInternal<std::byte, DataType, Extent>(bytes);
1145}
1146
1147/*!
1148 * \brief Converts a SmallSpan<const std::byte> into a SmallSpan<const DataType>.
1149 * \pre bytes.size() % sizeof(DataType) == 0;
1150 */
1151template <typename DataType, Int32 Extent> inline SmallSpan<const DataType>
1153{
1154 return Arcane::Impl::asSmallSpanInternal<const std::byte, const DataType, Extent>(bytes);
1155}
1156
1157/*---------------------------------------------------------------------------*/
1158/*---------------------------------------------------------------------------*/
1159
1160/*!
1161 * \brief Returns a Span associated with std::array.
1162 */
1163template <typename DataType, size_t SizeType> inline Span<DataType, SizeType>
1164asSpan(std::array<DataType, SizeType>& s)
1165{
1166 Int64 size = static_cast<Int64>(s.size());
1167 return { s.data(), size };
1168}
1169
1170/*!
1171 * \brief Returns a SmallSpan associated with std::array.
1172 */
1173template <typename DataType, size_t SizeType> inline SmallSpan<DataType, SizeType>
1174asSmallSpan(std::array<DataType, SizeType>& s)
1175{
1176 Int32 size = static_cast<Int32>(s.size());
1177 return { s.data(), size };
1178}
1179
1180/*---------------------------------------------------------------------------*/
1181/*---------------------------------------------------------------------------*/
1182
1183/*!
1184 * \brief Writes the content of \a bytes to the stream \a ostr in binary format.
1185 *
1186 * This is equivalent to calling ostr.write(bytes.data(),bytes.size());
1187 */
1188extern "C++" ARCCORE_BASE_EXPORT void
1189binaryWrite(std::ostream& ostr, const Span<const std::byte>& bytes);
1190
1191/*!
1192 * \brief Reads the content of \a bytes from the stream \a istr in binary format.
1193 *
1194 * This is equivalent to calling istr.read(bytes.data(),bytes.size());
1195 */
1196extern "C++" ARCCORE_BASE_EXPORT void
1197binaryRead(std::istream& istr, const Span<std::byte>& bytes);
1198
1199/*---------------------------------------------------------------------------*/
1200/*---------------------------------------------------------------------------*/
1201
1202} // namespace Arcane
1203
1204/*---------------------------------------------------------------------------*/
1205/*---------------------------------------------------------------------------*/
1206
1207namespace Arccore
1208{
1209using Arcane::asBytes;
1211using Arcane::asSpan;
1213using Arcane::binaryRead;
1215using Arcane::sampleSpan;
1216} // namespace Arccore
1217
1218/*---------------------------------------------------------------------------*/
1219/*---------------------------------------------------------------------------*/
1220
1221#endif
Types and functions associated with the classes ArrayView and ConstArrayView.
Iterator over Arccore array classes.
Interval over Arccore array classes.
Modifiable view of an array of type T.
Constant view of an array of type T.
Specialization for the compile-time known number of elements.
Definition Span.h:107
To have the type (SmallSpan or Span) depending on the size (Int32 or Int64).
Definition Span.h:50
View of an array of elements of type T.
Definition Span.h:803
constexpr __host__ __device__ SmallSpan< T, DynExtent > subspan(Int32 abegin, Int32 asize) const
Sub-view starting from element abegin and containing asize elements.
Definition Span.h:885
constexpr __host__ __device__ SmallSpan< Pointer > subViewInterval(Int32 index, Int32 nb_interval) const
Definition Span.h:941
constexpr __host__ __device__ ThatClass & operator=(std::array< X, N > &from)
Copy assignment operator.
Definition Span.h:861
constexpr __host__ __device__ SmallSpan< T, DynExtent > subSpanInterval(Int32 index, Int32 nb_interval) const
Sub-view corresponding to the interval index over nb_interval.
Definition Span.h:915
constexpr __host__ __device__ SmallSpan< T, DynExtent > subPart(Int32 abegin, Int32 asize) const
Sub-view starting from element abegin and containing asize elements.
Definition Span.h:909
SmallSpan()=default
Constructs an empty view.
constexpr __host__ __device__ SmallSpan(const ArrayView< value_type > &from) noexcept
Copy constructor from another view.
Definition Span.h:821
constexpr __host__ __device__ SmallSpan(pointer ptr, Int32 asize) noexcept
Definition Span.h:845
constexpr __host__ __device__ SmallSpan< Pointer > subView(Int32 abegin, Int32 asize) const
Definition Span.h:934
constexpr __host__ __device__ SmallSpan(T *ptr)
Constructs a view from a pointer with a fixed size.
Definition Span.h:855
static constexpr ThatClass create(pointer ptr, size_type asize) noexcept
Constructs a view over a memory region starting at ptr and.
Definition Span.h:871
constexpr __host__ __device__ SmallSpan< T, DynExtent > subSpan(Int32 abegin, Int32 asize) const
Sub-view starting from element abegin and containing asize elements.
Definition Span.h:897
constexpr __host__ __device__ ThatClass subPartInterval(Int32 index, Int32 nb_interval) const
Sub-view corresponding to the interval index over nb_interval.
Definition Span.h:921
View of an array of elements of type T.
Definition Span.h:189
constexpr __host__ __device__ SpanImpl(pointer ptr, SizeType asize) noexcept
Definition Span.h:243
constexpr __host__ __device__ SpanImpl(const SpanImpl< X, SizeType, XExtent > &from) noexcept
Copy constructor from another view.
Definition Span.h:230
constexpr view_type smallView()
Constant view of this view.
Definition Span.h:390
__host__ __device__ void copy(const U &copy_array)
Copies the array copy_array into the instance.
Definition Span.h:475
constexpr SubSpanType subView(SizeType abegin, SizeType asize) const
Definition Span.h:437
friend bool operator==(const SpanImpl< T, SizeType, Extent > &rhs, const SpanImpl< X, SizeType, Extent2 > &lhs)
Equality operator (valid if T is const but not X).
Definition Span.h:541
constexpr __host__ __device__ SpanImpl(std::array< X, N > &from)
Constructs a view from a std::array.
Definition Span.h:250
std::optional< SizeType > findFirst(const_reference v) const
Definition Span.h:507
constexpr void _setArray(pointer v, SizeType s) noexcept
Modifies the array pointer and size.
Definition Span.h:581
constexpr __host__ __device__ SpanImpl(T *ptr)
Constructs a view from a pointer with a fixed size.
Definition Span.h:256
constexpr __host__ __device__ pointer data() const noexcept
Definition Span.h:537
constexpr __host__ __device__ SizeType length() const noexcept
Number of elements in the array.
Definition Span.h:333
constexpr __host__ __device__ iterator begin() const noexcept
Iterator for the first element of the array.
Definition Span.h:338
__host__ __device__ void fill(T o)
Fills the array with the value o.
Definition Span.h:381
constexpr __host__ __device__ pointer ptrAt(SizeType index) const
Address of the index-th element.
Definition Span.h:360
constexpr __host__ __device__ reference operator()(SizeType i) const
i-th element of the array.
Definition Span.h:296
constexpr __host__ __device__ reference operator[](SizeType i) const
i-th element of the array.
Definition Span.h:285
ArrayRange< pointer > range() const
Definition Span.h:352
constexpr __host__ __device__ bool empty() const noexcept
Returns true if the array is empty (zero dimension).
Definition Span.h:490
constexpr SubSpanType subViewInterval(SizeType index, SizeType nb_interval) const
Definition Span.h:450
constexpr __host__ __device__ SubSpanType subSpan(SizeType abegin, SizeType asize) const
Sub-view starting from element abegin and containing asize elements.
Definition Span.h:412
constexpr __host__ __device__ reference item(SizeType i) const
i-th element of the array.
Definition Span.h:307
constexpr ConstArrayView< value_type > constSmallView() const
Constant view of this view.
Definition Span.h:399
friend bool operator==(const SpanImpl< T, SizeType, Extent > &rhs, const SpanImpl< T, SizeType, Extent2 > &lhs)
Equality operator.
Definition Span.h:555
constexpr SubSpanType subPartInterval(SizeType index, SizeType nb_interval) const
Sub-view corresponding to the interval index over nb_interval.
Definition Span.h:462
__host__ __device__ bool contains(const_reference v) const
Returns true if the array contains the element with value v.
Definition Span.h:492
constexpr __host__ __device__ ThatClass & operator=(std::array< X, N > &from)
Copy assignment operator.
Definition Span.h:262
constexpr __host__ __device__ iterator end() const noexcept
Iterator for the element after the end of the array.
Definition Span.h:342
constexpr void _setPtr(pointer v) noexcept
Modifies the array start pointer.
Definition Span.h:593
friend bool operator!=(const SpanImpl< T, SizeType, Extent > &rhs, const SpanImpl< X, SizeType, Extent2 > &lhs)
Inequality operator (valid if T is const but not X).
Definition Span.h:548
constexpr __host__ __device__ reverse_iterator rend() const noexcept
Reverse iterator for the element after the end of the array.
Definition Span.h:346
constexpr __host__ __device__ SizeType size() const noexcept
Definition Span.h:325
constexpr __host__ __device__ SizeType sizeBytes() const noexcept
Returns the size of the array in bytes.
Definition Span.h:327
constexpr __host__ __device__ reverse_iterator rbegin() const noexcept
Reverse iterator for the first element of the array.
Definition Span.h:344
friend bool operator!=(const SpanImpl< T, SizeType, Extent > &rhs, const SpanImpl< T, SizeType, Extent2 > &lhs)
Inequality operator.
Definition Span.h:562
constexpr void _setSize(SizeType s) noexcept
Modifies the array size.
Definition Span.h:601
constexpr __host__ __device__ SubSpanType subspan(SizeType abegin, SizeType asize) const
For C++20 compatibility.
Definition Span.h:443
constexpr __host__ __device__ SubSpanType subPart(SizeType abegin, SizeType asize) const
Sub-view starting from element abegin and containing asize elements.
Definition Span.h:424
constexpr __host__ __device__ SpanImpl() noexcept
Constructs an empty view.
Definition Span.h:222
constexpr SubSpanType subSpanInterval(SizeType index, SizeType nb_interval) const
Sub-view corresponding to the interval index over nb_interval.
Definition Span.h:456
constexpr __host__ __device__ void setItem(SizeType i, const_reference v) noexcept
Sets the i-th element of the array.
Definition Span.h:318
static constexpr ThatClass create(pointer ptr, SizeType asize) noexcept
Constructs a view on a memory region starting at ptr and.
Definition Span.h:273
std::enable_if_t< std::is_same_v< X, T >||std::is_same_v< std::add_const_t< X >, T > > is_same_const_type
Definition Span.h:215
View of an array of elements of type T.
Definition Span.h:633
constexpr __host__ __device__ Span< T, DynExtent > subPart(Int64 abegin, Int64 asize) const
Sub-view starting from element abegin and containing asize elements.
Definition Span.h:746
constexpr __host__ __device__ Span< T, DynExtent > subSpanInterval(Int64 index, Int64 nb_interval) const
Sub-view corresponding to the interval index over nb_interval.
Definition Span.h:752
static constexpr ThatClass create(pointer ptr, size_type asize) noexcept
Constructs a view on a memory area starting at ptr and.
Definition Span.h:708
constexpr __host__ __device__ Span(std::array< X, N > &from) noexcept
Constructs a view from a std::array.
Definition Span.h:686
constexpr __host__ __device__ Span< DataType > subView(Int64 abegin, Int64 asize) const
Definition Span.h:771
constexpr __host__ __device__ Span(pointer ptr, Int64 asize) noexcept
Definition Span.h:680
constexpr __host__ __device__ ThatClass & operator=(std::array< X, N > &from) noexcept
Copy assignment operator.
Definition Span.h:697
constexpr __host__ __device__ Span(T *ptr)
Constructs a view from a pointer with a fixed size.
Definition Span.h:691
constexpr __host__ __device__ Span(const ArrayView< value_type > &from) noexcept
Copy constructor from another view.
Definition Span.h:650
Span()=default
Constructs an empty view.
constexpr __host__ __device__ Span< DataType > subViewInterval(Int64 index, Int64 nb_interval) const
Definition Span.h:778
constexpr __host__ __device__ Span< T, DynExtent > subPartInterval(Int64 index, Int64 nb_interval) const
Sub-view corresponding to the interval index over nb_interval.
Definition Span.h:758
constexpr __host__ __device__ Span< T, DynExtent > subSpan(Int64 abegin, Int64 asize) const
Sub-view starting from element abegin and containing asize elements.
Definition Span.h:734
constexpr __host__ __device__ Span< T, DynExtent > subspan(Int64 abegin, Int64 asize) const
Sub-view starting from element abegin and containing asize elements.
Definition Span.h:722
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
constexpr __host__ __device__ Integer arccoreCheckArraySize(unsigned long long size)
Checks that size can be converted into an 'Integer' to serve as an array size. If possible,...
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
constexpr Int32 DynExtent
Constant to indicate that an array dimension is dynamic.
Definition BaseTypes.h:53
__host__ __device__ void arccoreCheckAt(Int64 i, Int64 max_size)
Checks for potential array overflow.
void dumpArray(std::ostream &o, ConstArrayView< T > val, int max_print)
Displays the values of array val to the stream o.
void sampleSpan(Span< const DataType > values, Span< const Int64 > indexes, Span< DataType > result)
Extracts a sub-array from a list of indices.
Definition Span.h:1002
SmallSpan< DataType > asSmallSpan(SmallSpan< std::byte, Extent > bytes)
Converts a SmallSpan<std::byte> into a SmallSpan<DataType>.
Definition Span.h:1142
Span< DataType > asSpan(Span< std::byte, Extent > bytes)
Converts a Span<std::byte> into a Span<DataType>.
Definition Span.h:1122
void binaryRead(std::istream &istr, const Span< std::byte > &bytes)
Reads the content of bytes from the stream istr in binary format.
Definition ArrayView.cc:102
Impl::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converts the view into an array of non-modifiable bytes.
Definition Span.h:1030
Impl::SpanTypeFromSize< std::byte, SizeType >::SpanType asWritableBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converts the view into an array of modifiable bytes.
Definition Span.h:1066
void binaryWrite(std::ostream &ostr, const Span< const std::byte > &bytes)
Writes the content of bytes to the stream ostr in binary format.
Definition ArrayView.cc:93
void _sampleSpan(SpanImpl< const DataType, SizeType > values, SpanImpl< const IntegerType, SizeType > indexes, SpanImpl< DataType, SizeType > result)
Extracts a sub-array from a list of indices.
Definition Span.h:976
std::ostream & operator<<(std::ostream &ostr, eItemKind item_kind)
Output operator for a stream.
std::int32_t Int32
Signed integer type of 32 bits.
Namespace of Arccore.