31template <
class ElementType>
49template <
class ElementType,
size_t extent = std::dynamic_extent,
class StorageInfoType = StorageInfoWithMemberAlignment<alignof (std::span<ElementType, extent>), StorageInfo<std::span<ElementType, extent> > > >
50class Span :
public VctrBase<ElementType, std::span<ElementType, extent>, extent, StorageInfoType>
56 using StdSpanType = std::span<ElementType, extent>;
60 using value_type =
typename Vctr::value_type;
62 using element_type = ElementType;
72 VCTR_ASSERT (extent ==
size || extent == std::dynamic_extent);
80 template <
bool isDataSIMDAligned,
bool isStorageSIMDExtended>
81 constexpr Span (ElementType* ptr,
size_t size,
const StaticStorageInfo<isDataSIMDAligned, isStorageSIMDExtended,
alignof (StdSpanType)>& info)
82 :
Vctr (StdSpanType (ptr,
size), info)
84 VCTR_ASSERT (extent ==
size || extent == std::dynamic_extent);
86 if constexpr (isDataSIMDAligned)
90 VCTR_ASSERT (detail::isPtrAligned (ptr));
98 template <has::sizeAndDataWithElementType<ElementType> Container>
99 constexpr Span (Container&& containerToView)
100 :
Vctr (StdSpanType (containerToView.
data(), containerToView.
size()), makeStorageInfo (containerToView))
102 VCTR_ASSERT (extent == containerToView.
size() || extent == std::dynamic_extent);
109 Span& operator= (
const Span&) =
delete;
112 template <has::sizeAndDataWithElementType<ElementType> Container>
113 constexpr Span& operator= (Container&& containerToCopyDataFrom)
115 if constexpr (Vctr::template shouldMoveFromOtherContainer<Container>)
117 VCTR_ASSERT (containerToCopyDataFrom.size() ==
Vctr::size());
118 std::copy (std::make_move_iterator (containerToCopyDataFrom.begin()), std::make_move_iterator (containerToCopyDataFrom.end()), Vctr::storage.begin());
122 Vctr::copyFrom (containerToCopyDataFrom.data(), containerToCopyDataFrom.size());
129 constexpr Span& operator= (std::initializer_list<ElementType> elementsToAssign)
139 template <is::expression E>
140 constexpr void operator= (
const E& expression)
142 VCTR_ASSERT (expression.size() ==
Vctr::size());
144 Vctr::assignExpressionTemplate (expression);
149 template <has::sizeAndData Container>
150 static constexpr auto makeStorageInfo (
const Container& container)
152 constexpr size_t memberAlignment =
alignof (StdSpanType);
156 const auto& info = container.getStorageInfo();
161 return StorageInfoWithMemberAlignment<memberAlignment, StorageInfo<Container>>().init (container.data(), container.size());
170template <
class ElementType,
bool isDataSIMDAligned,
bool isStorageSIMDExtended>
171Span (ElementType*,
size_t,
const StaticStorageInfo<isDataSIMDAligned, isStorageSIMDExtended,
alignof (std::span<ElementType>)>&) -> Span<ElementType, std::dynamic_extent, StaticStorageInfo<isDataSIMDAligned, isStorageSIMDExtended,
alignof (std::span<ElementType>)>>;
173template <
class Container>
174Span (Container&&) -> Span<DataType<Container>, extentOf<Container>, StorageInfoWithMemberAlignment<
alignof (std::span<DataType<Container>, extentOf<Container>>), StorageInfoType<Container>>>;
177template <
class ElementType>
182 VCTR_ASSERT (detail::isPtrAligned (data));
184 return Span<ElementType, std::dynamic_extent,
StaticStorageInfo<
true,
false,
alignof (std::span<ElementType>)>> (data, size);
188template <
size_t extent,
class ElementType>
189requires (extent != std::dynamic_extent)
194 VCTR_ASSERT (detail::isPtrAligned (data));
196 return Span<ElementType, extent,
StaticStorageInfo<
true,
false,
alignof (std::span<ElementType>)>> (data, extent);
The view type.
Definition: Span.h:51
constexpr Span(ElementType *ptr, size_t size, const StaticStorageInfo< isDataSIMDAligned, isStorageSIMDExtended, alignof(StdSpanType)> &info)
Creates a Span with a given size that views externally managed data, accessed by ptr.
Definition: Span.h:81
constexpr Span(ElementType *ptr, size_t size)
Creates a Span with a given size that views externally managed data, accessed by ptr.
Definition: Span.h:69
constexpr Span(Container &&containerToView)
Creates a Span that acts as a view to the given container.
Definition: Span.h:99
The base class to all one dimensional containers and views in the VCTR project.
Definition: VctrBase.h:38
constexpr size_t size() const noexcept
Returns the number of elements.
Definition: VctrBase.h:61
constexpr void assign(std::initializer_list< ElementType > elements)
Assigns elements from the initializer list to this instance.
Definition: VctrBase.h:262
constexpr void copyFrom(const ElementType *otherData, size_t otherSize)
Copies the content from otherData to this instance.
Definition: VctrBase.h:281
VCTR_FORCEDINLINE constexpr auto * data()
Returns a raw pointer to the underlying storage.
Definition: VctrBase.h:123
Constrains a type to be any derived instance of VctrBase.
Definition: ContainerAndExpressionConcepts.h:192
The main namespace of the VCTR project.
Definition: Array.h:24
typename detail::StorageInfoType< std::remove_cvref_t< T > >::Type StorageInfoType
If t is a type derived from VctrBase, this will equal the return value of T::getStorageInfo,...
Definition: Traits.h:227
auto makeSimdAlignedSpan(ElementType *data, size_t size)
Creates a span with dynamic extent pointing to a memory location that is expected to be SIMD aligned.
Definition: Span.h:178
consteval auto simdAlignedSpanStorageInfo()
Creates a StaticStorageInfo instance suitable to be passed to a Span constructor.
Definition: Span.h:32
A storage info type especially used to pass compile time constant traits when viewing externally owne...
Definition: SIMDHelpers.h:150
A storage info type especially used for vctr::Span.
Definition: SIMDHelpers.h:164