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