5 #include <initializer_list>
18 template <
typename T,
int N,
typename TCounter = Size>
29 if (!std::is_trivially_default_constructible<T>::value) {
30 for (TCounter i = 0; i <
N; ++i) {
52 for (
auto& i : list) {
61 for (TCounter i = 0; i < other.size(); ++i) {
63 data[actSize++].
emplace(std::forward<T>(other[i]));
69 if (!std::is_trivially_destructible<T>::value) {
70 for (TCounter i = 0; i < actSize; ++i) {
82 template <typename U, typename = std::enable_if_t<std::is_default_constructible<T>::value, U>>
84 this->
resize(other.size());
85 for (TCounter i = 0; i < other.size(); ++i) {
87 (*this)[i] = std::forward<T>(other[i]);
98 template <typename U, int M, typename = std::enable_if_t<std::is_lvalue_reference<T>::value, U>>
101 for (TCounter i = 0; i < other.size(); ++i) {
102 (*this)[i] = std::forward<U>(other[i]);
112 for (TCounter i = 0; i < actSize; ++i) {
113 cloned.
push(data[i].get());
122 for (TCounter i = 0; i < actSize; ++i) {
123 data[i].
get() = value;
129 SPH_ASSERT(idx >= 0 && idx < actSize, idx, actSize);
130 return data[idx].
get();
135 SPH_ASSERT(idx >= 0 && idx < actSize, idx, actSize);
136 return data[idx].
get();
161 template <typename U, typename = std::enable_if_t<std::is_constructible<StorageType, U>::value>>
164 data[actSize++].
emplace(std::forward<U>(value));
172 T value = data[actSize - 1];
184 if (!std::is_trivially_default_constructible<T>::value) {
185 if (newSize > actSize) {
186 for (TCounter i = actSize; i < newSize; ++i) {
190 for (TCounter i = newSize; i < actSize; ++i) {
231 if (actSize != other.actSize) {
234 for (TCounter i = 0; i < actSize; ++i) {
235 if (data[i].get() != other.data[i].
get()) {
243 return !(*
this == other);
249 template <
typename TStream>
251 for (
const T& t : array) {
252 stream << t << std::endl;
258 INLINE StorageType* rawData() {
259 return reinterpret_cast<StorageType*
>(data);
262 INLINE const StorageType* rawData()
const {
263 return reinterpret_cast<const StorageType*
>(data);
271 template <
typename T0,
typename... TArgs>
273 return StaticArray<T0,
sizeof...(TArgs) + 1>({ std::forward<T0>(t0), std::forward<TArgs>(rest)... });
280 template <
typename T0,
typename... TArgs>
282 return StaticArray<T0&,
sizeof...(TArgs) + 1>({ t0, rest... });
286 template <
typename T>
291 template <
typename T, Size N>
297 template <
typename... TArgs>
299 : data{
std::forward<TArgs>(args)... } {}
Base class for utility wrappers (Optional, Variant, ...)
Simple non-owning view of a container.
#define SPH_ASSERT(x,...)
uint32_t Size
Integral type used to index arrays (by default).
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
StaticArray< T0, sizeof...(TArgs)+1 > makeStatic(T0 &&t0, TArgs &&... rest)
Creates a static array from a list of parameters.
StaticArray< T0 &, sizeof...(TArgs)+1 > tie(T0 &t0, TArgs &... rest)
Creates a static array from a list of l-value references.
NAMESPACE_SPH_BEGIN const struct EmptyArray EMPTY_ARRAY
typename WrapReferenceType< T >::Type WrapReference
INLINE void emplace(TArgs &&... rest)
constexpr INLINE Type & get() noexcept
Return the reference to the stored value.
Object providing safe access to continuous memory of data.
Container similar to StaticArray, but with constexpr constructors and getters.
constexpr const T & operator[](const Size idx) const
constexpr T & operator[](const Size idx)
constexpr ConstexprArray(TArgs &&... args)
Simple (forward) iterator over continuous array of objects of type T.
Array with fixed number of allocated elements.
INLINE T & operator[](const TCounter idx) noexcept
Returns the element with given index.
~StaticArray()
Destructor, destroys all constructed elements in the array.
void resize(const TCounter newSize)
Changes size of the array.
StaticArray & operator=(StaticArray< U, N > &&other)
Move operator for arrays holding default-constructible types.
bool operator!=(const StaticArray &other) const
void fill(const T &value)
Assigns a value to all constructed elements of the array.
StaticArray & operator=(StaticArray< U, M > &&other)
Special assignment operator for array of references on left-hand side.
INLINE Iterator< const StorageType > cbegin() const
INLINE Iterator< const StorageType > begin() const
StaticArray clone() const
Clones the array, calling copy constructor on all elements.
bool operator==(const StaticArray &other) const
friend TStream & operator<<(TStream &stream, const StaticArray &array)
Prints content of array to stream.
INLINE Iterator< StorageType > end()
StaticArray(const StaticArray &other)=delete
INLINE void push(U &&value)
Inserts a value to the end of the array using copy/move constructor.
StaticArray(const EmptyArray &)
Initialize an empty array.
StaticArray(StaticArray &&other)
StaticArray(std::initializer_list< StorageType > list)
Initialize using initializer_list.
INLINE Iterator< const StorageType > cend() const
constexpr INLINE TCounter maxSize() const noexcept
Returns the maximum allowed size of the array.
INLINE Iterator< const StorageType > end() const
INLINE const T & operator[](const TCounter idx) const noexcept
Returns the element with given index.
StaticArray()
Default constructor, calls default constructor on all elements.
INLINE T pop()
Removes and destroys element from the end of the array.
INLINE Iterator< StorageType > begin()
INLINE TCounter size() const
Returns the current size of the array (number of constructed elements).
INLINE bool empty() const
Return true if the array is empty.
StaticArray & operator=(const StaticArray &other)=delete
Overload of std::swap for Sph::Array.