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 constexpr (std::copy_constructible <ElementType>)
76 if (std::is_constant_evaluated())
78 if constexpr (extent > 0)
79 Vctr::storage.fill (value_type());
85 constexpr Array (ElementType initialValue)
88 Vctr::storage.fill (initialValue);
92 template <std::convertible_to<ElementType> T>
93 constexpr Array (T&& initialValue)
94 requires (extent == 1)
95 :
Vctr (StdArrayType { initialValue }) {}
98 template <is::suitableInitializerForElementType<ElementType>... T>
99 requires (
sizeof...(T) > 1)
100 constexpr Array (T&&... initialValues) :
Vctr (StdArrayType { std::forward<T> (initialValues)... })
104 template <
class OtherElementType,
size_t otherSize>
105 constexpr Array (std::array<OtherElementType, otherSize>&& other) :
Vctr (std::move (other)) {}
116 template <is::triviallyCopyableWithDataAndSize OtherContainer>
117 requires (std::same_as<value_type, ValueType<OtherContainer>> && ! std::same_as<Array, OtherContainer>)
118 constexpr Array (
const OtherContainer& other)
120 if (std::is_constant_evaluated())
122 for (
size_t i = 0; i < extent; ++i)
123 Vctr::storage[i] = other[i];
127 Vctr::copyFrom (other.data(), other.size());
138 template <is::iteratorCopyable OtherContainer>
139 constexpr Array (
const OtherContainer& other) :
Array (other.begin(), other.end()) {}
142 constexpr Array (
const ElementType* data,
size_t size)
144 Vctr::copyFrom (data, size);
148 template <is::inputIteratorToConstructValuesOfType<ElementType> Iterator, std::sentinel_for<Iterator> Sentinel>
149 constexpr Array (Iterator first, [[maybe_unused]] Sentinel last)
151 for (
size_t i = 0; i < extent; ++i, ++first)
152 Vctr::storage[i] = *first;
154 if (! std::is_constant_evaluated())
157 VCTR_ASSERT (first == last);
166 template <is::suitableInitializerFunctionForElementType<ElementType> Fn>
167 constexpr Array (Fn&& initializerFunction) :
Array (std::forward<Fn> (initializerFunction), std::make_index_sequence<extent>()) {}
177 template <is::expression Expression>
180 VCTR_ASSERT (e.size() == extent);
181 Vctr::assignExpressionTemplate (std::forward<Expression> (e));
188 template <has::sizeAndDataWithElementType<ElementType> Container>
189 constexpr Array& operator= (Container&& containerToCopyDataFrom)
191 if constexpr (Vctr::template shouldMoveFromOtherContainer<Container>)
193 VCTR_ASSERT (containerToCopyDataFrom.size() == Vctr::size());
194 std::copy (std::make_move_iterator (containerToCopyDataFrom.begin()), std::make_move_iterator (containerToCopyDataFrom.end()), Vctr::storage.begin());
198 Vctr::copyFrom (containerToCopyDataFrom.data(), containerToCopyDataFrom.size());
205 constexpr Array& operator= (std::initializer_list<ElementType> elementsToAssign)
207 Vctr::assign (std::move (elementsToAssign));
215 template <is::expression E>
216 constexpr void operator= (
const E& expression)
218 if (! std::is_constant_evaluated())
219 VCTR_ASSERT (expression.size() == extent);
221 Vctr::assignExpressionTemplate (expression);
227 constexpr Array (Fn&& initializerFunction, std::index_sequence<i...>) : Vctr (StdArrayType { initializerFunction (i)... }) {}
231template <
class OwnedElementType,
size_t extent>
255template <
class OtherElementType,
size_t otherSize>
256Array (std::array<OtherElementType, otherSize>&&) -> Array<OtherElementType, otherSize, otherSize>;
258template <
class First, is::suitableInitializerForElementType<std::remove_cvref_t<First>>... Other>
259Array (First&&, Other&&...) -> Array<std::remove_cvref_t<First>,
sizeof...(Other) + 1>;
267struct SingleArgDeductionHelper
269 using Type = std::remove_cvref_t<T>;
270 static constexpr size_t extent = 1;
273template <has::size T>
274struct SingleArgDeductionHelper<T>
277 static constexpr size_t extent = extentOf<T>;
282template <
class SingleArg>
283Array (SingleArg&&) -> Array<typename detail::SingleArgDeductionHelper<SingleArg>::Type, detail::SingleArgDeductionHelper<SingleArg>::extent>;
285template <
class Po
inter, std::same_as<Po
inter>... Po
inters>
286OwnedArray (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:85
constexpr Array(std::array< OtherElementType, otherSize > &&other)
Creates an Array by moving a std::array into it.
Definition: Array.h:105
constexpr Array(T &&initialValue)
Creates an Array with extent 1 from an initial value.
Definition: Array.h:93
constexpr Array(Fn &&initializerFunction)
Creates a vector of the given size and initialises all elements by calling initializerFunction with t...
Definition: Array.h:167
constexpr Array(T &&... initialValues)
Creates an Array from a list of at least two initial values.
Definition: Array.h:100
constexpr Array(Expression &&e)
Creates an Array from an expression template.
Definition: Array.h:178
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:149
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:142
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:139
A handy shortcut for Array<std::unique_ptr<OwnedElementType>, n>.
Definition: Array.h:233
OwnedArray(Args &&... args)
Forwards every other constructor call to the base class constructor.
Definition: Array.h:248
OwnedArray(Pointer... elementsToOwn)
Creates an OwnedArray from a list of raw pointers that will be owned by the Array.
Definition: Array.h:244
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:363
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