29template <
class T,
size_t e>
32 static constexpr size_t extent = e;
35template <is::number T,
size_t e>
36struct StorageExtent<T, e>
38 static constexpr size_t extent = nextMultipleOf<Config::maxSIMDRegisterSize /
sizeof (T)> (e);
50template <class ElementType, size_t extent, size_t storageExtent = detail::StorageExtent<ElementType, extent>::extent>
51requires (extent != std::dynamic_extent && extent <= storageExtent)
52class Array :
public VctrBase<ElementType, std::array<ElementType, storageExtent>, extent>
57 using StdArrayType = std::array<ElementType, storageExtent>;
61 using value_type =
typename Vctr::value_type;
74 if (std::is_constant_evaluated())
75 Vctr::storage.fill (value_type());
79 constexpr Array (ElementType initialValue)
82 Vctr::storage.fill (initialValue);
86 template <is::suitableInitializerForElementType<ElementType>... T>
87 requires (
sizeof...(T) > 1)
88 constexpr Array (T&&... initialValues) :
Vctr (StdArrayType { std::forward<T> (initialValues)... })
92 template <std::convertible_to<ElementType> T>
93 constexpr Array (T&& initialValues) :
Vctr (StdArrayType { initialValues }) {}
96 template <
class OtherElementType,
size_t otherSize>
97 constexpr Array (std::array<OtherElementType, otherSize>&& other) :
Vctr (std::move (other)) {}
108 template <is::triviallyCopyableWithDataAndSize OtherContainer>
109 requires (std::same_as<value_type, ValueType<OtherContainer>> && ! std::same_as<Array, OtherContainer>)
110 constexpr Array (
const OtherContainer& other)
112 if (std::is_constant_evaluated())
114 for (
size_t i = 0; i < extent; ++i)
115 Vctr::storage[i] = other[i];
119 Vctr::copyFrom (other.data(), other.size());
130 template <is::iteratorCopyable OtherContainer>
131 constexpr Array (
const OtherContainer& other) :
Array (other.begin(), other.end()) {}
134 constexpr Array (
const ElementType* data,
size_t size)
136 Vctr::copyFrom (data, size);
140 template <is::inputIteratorToConstructValuesOfType<ElementType> Iterator, std::sentinel_for<Iterator> Sentinel>
141 constexpr Array (Iterator first, [[maybe_unused]] Sentinel last)
143 for (
size_t i = 0; i < extent; ++i, ++first)
144 Vctr::storage[i] = *first;
146 if (! std::is_constant_evaluated())
149 VCTR_ASSERT (first == last);
158 template <is::suitableInitializerFunctionForElementType<ElementType> Fn>
159 constexpr Array (Fn&& initializerFunction) :
Array (std::forward<Fn> (initializerFunction), std::make_index_sequence<extent>()) {}
169 template <is::expression Expression>
172 VCTR_ASSERT (e.size() == extent);
173 Vctr::assignExpressionTemplate (std::forward<Expression> (e));
180 template <has::sizeAndDataWithElementType<ElementType> Container>
181 constexpr Array& operator= (Container&& containerToCopyDataFrom)
183 if constexpr (Vctr::template shouldMoveFromOtherContainer<Container>)
185 VCTR_ASSERT (containerToCopyDataFrom.size() == Vctr::size());
186 std::copy (std::make_move_iterator (containerToCopyDataFrom.begin()), std::make_move_iterator (containerToCopyDataFrom.end()), Vctr::storage.begin());
190 Vctr::copyFrom (containerToCopyDataFrom.data(), containerToCopyDataFrom.size());
197 constexpr Array& operator= (std::initializer_list<ElementType> elementsToAssign)
199 Vctr::assign (std::move (elementsToAssign));
207 template <is::expression E>
208 constexpr void operator= (
const E& expression)
210 if (! std::is_constant_evaluated())
211 VCTR_ASSERT (expression.size() == extent);
213 Vctr::assignExpressionTemplate (expression);
219 constexpr Array (Fn&& initializerFunction, std::index_sequence<i...>) : Vctr (StdArrayType { initializerFunction (i)... }) {}
223template <
class OwnedElementType,
size_t extent>
247template <
class OtherElementType,
size_t otherSize>
248Array (std::array<OtherElementType, otherSize>&&) -> Array<OtherElementType, otherSize, otherSize>;
250template <
class First, is::suitableInitializerForElementType<std::remove_cvref_t<First>>... Other>
251Array (First&&, Other&&...) -> Array<std::remove_cvref_t<First>,
sizeof...(Other) + 1>;
259struct SingleArgDeductionHelper
261 using Type = std::remove_cvref_t<T>;
262 static constexpr size_t extent = 1;
265template <has::size T>
266struct SingleArgDeductionHelper<T>
269 static constexpr size_t extent = extentOf<T>;
274template <
class SingleArg>
275Array (SingleArg&&) -> Array<typename detail::SingleArgDeductionHelper<SingleArg>::Type, detail::SingleArgDeductionHelper<SingleArg>::extent>;
277template <
class Po
inter, std::same_as<Po
inter>... Po
inters>
278OwnedArray (Pointer*, Pointers*...) -> OwnedArray<Pointer,
sizeof...(Pointers) + 1>;
The stack-based container type.
Definition: Array.h:53
constexpr Array(ElementType initialValue)
Creates an Array with all elements initialised to initialValue.
Definition: Array.h:79
constexpr Array(T &&initialValues)
Creates an Array with extent 1 from an initial value.
Definition: Array.h:93
constexpr Array(std::array< OtherElementType, otherSize > &&other)
Creates an Array by moving a std::array into it.
Definition: Array.h:97
constexpr Array(Fn &&initializerFunction)
Creates a vector of the given size and initialises all elements by calling initializerFunction with t...
Definition: Array.h:159
constexpr Array(T &&... initialValues)
Creates an Array from a list of at least two initial values.
Definition: Array.h:88
constexpr Array(Expression &&e)
Creates an Array from an expression template.
Definition: Array.h:170
constexpr Array(Iterator first, Sentinel last)
Creates an Array from an iterator and a sentinel by initialising the Array with the content read from...
Definition: Array.h:141
constexpr Array()
Creates an uninitialised Array.
Definition: Array.h:72
constexpr Array(const ElementType *data, size_t size)
Copies size elements from the memory location pointed to by data.
Definition: Array.h:134
constexpr Array(const OtherContainer &other)
This constructor will create an Array instance of the same size as OtherContainer and will copy its v...
Definition: Array.h:131
A handy shortcut for Array<std::unique_ptr<OwnedElementType>, n>.
Definition: Array.h:225
OwnedArray(Args &&... args)
Forwards every other constructor call to the base class constructor.
Definition: Array.h:240
OwnedArray(Pointer... elementsToOwn)
Creates an OwnedArray from a list of raw pointers that will be owned by the Array.
Definition: Array.h:236
The base class to all one dimensional containers and views in the VCTR project.
Definition: VctrBase.h:38
Constrains a type to be no pointer of a reference to a pointer.
Definition: GenericConcepts.h:96
Constrains a type to be a pointer of a reference to a pointer.
Definition: GenericConcepts.h:92
Constrains the type to be a function suitable for initializing the nth element of a Vctr,...
Definition: ContainerAndExpressionConcepts.h:345
The main namespace of the VCTR project.
Definition: Array.h:24
typename detail::ValueType< std::remove_cvref_t< T > >::Type ValueType
If T is an expression template, it equals its return type, if it's a type that defines value_type as ...
Definition: Traits.h:201