2023-01-10 17:52:00 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-01-10 19:11:27 +02:00
|
|
|
#include <BAN/Errors.h>
|
2023-03-20 13:26:42 +02:00
|
|
|
#include <BAN/Iterators.h>
|
2023-03-20 13:28:01 +02:00
|
|
|
#include <BAN/Span.h>
|
2023-01-10 19:11:27 +02:00
|
|
|
|
2023-01-10 17:52:00 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
namespace BAN
|
|
|
|
{
|
|
|
|
|
|
|
|
template<typename T, size_t S>
|
|
|
|
class Array
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using size_type = decltype(S);
|
|
|
|
using value_type = T;
|
2023-03-20 13:26:42 +02:00
|
|
|
using iterator = IteratorSimple<T, Array>;
|
|
|
|
using const_iterator = ConstIteratorSimple<T, Array>;
|
2023-01-10 17:52:00 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
Array();
|
|
|
|
Array(const T&);
|
|
|
|
|
2023-03-20 13:26:42 +02:00
|
|
|
iterator begin() { return iterator(m_data); }
|
|
|
|
iterator end() { return iterator(m_data + size()); }
|
|
|
|
const_iterator begin() const { return const_iterator(m_data); }
|
|
|
|
const_iterator end() const { return const_iterator(m_data + size()); }
|
|
|
|
|
2023-01-10 17:52:00 +02:00
|
|
|
const T& operator[](size_type) const;
|
|
|
|
T& operator[](size_type);
|
|
|
|
|
2023-02-01 21:05:44 +02:00
|
|
|
const T& back() const;
|
|
|
|
T& back();
|
|
|
|
const T& front() const;
|
|
|
|
T& front();
|
2023-01-10 17:52:00 +02:00
|
|
|
|
2023-03-20 13:28:01 +02:00
|
|
|
Span<T> span() { return Span(m_data, size()); }
|
|
|
|
const Span<T> span() const { return Span(m_data, size()); }
|
|
|
|
|
2023-02-01 21:05:44 +02:00
|
|
|
constexpr size_type size() const;
|
2023-01-10 17:52:00 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
T m_data[S];
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T, size_t S>
|
|
|
|
Array<T, S>::Array()
|
|
|
|
{
|
|
|
|
for (size_type i = 0; i < S; i++)
|
|
|
|
m_data[i] = T();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, size_t S>
|
|
|
|
Array<T, S>::Array(const T& value)
|
|
|
|
{
|
|
|
|
for (size_type i = 0; i < S; i++)
|
|
|
|
m_data[i] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, size_t S>
|
|
|
|
const T& Array<T, S>::operator[](size_type index) const
|
|
|
|
{
|
|
|
|
ASSERT(index < S);
|
|
|
|
return m_data[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, size_t S>
|
|
|
|
T& Array<T, S>::operator[](size_type index)
|
|
|
|
{
|
|
|
|
ASSERT(index < S);
|
|
|
|
return m_data[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, size_t S>
|
2023-02-01 21:05:44 +02:00
|
|
|
const T& Array<T, S>::back() const
|
2023-01-10 17:52:00 +02:00
|
|
|
{
|
|
|
|
ASSERT(S != 0);
|
|
|
|
return m_data[S - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, size_t S>
|
2023-02-01 21:05:44 +02:00
|
|
|
T& Array<T, S>::back()
|
2023-01-10 17:52:00 +02:00
|
|
|
{
|
|
|
|
ASSERT(S != 0);
|
|
|
|
return m_data[S - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, size_t S>
|
2023-02-01 21:05:44 +02:00
|
|
|
const T& Array<T, S>::front() const
|
2023-01-10 17:52:00 +02:00
|
|
|
{
|
|
|
|
ASSERT(S != 0);
|
|
|
|
return m_data[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, size_t S>
|
2023-02-01 21:05:44 +02:00
|
|
|
T& Array<T, S>::front()
|
2023-01-10 17:52:00 +02:00
|
|
|
{
|
|
|
|
ASSERT(S != 0);
|
|
|
|
return m_data[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, size_t S>
|
2023-02-01 21:05:44 +02:00
|
|
|
constexpr typename Array<T, S>::size_type Array<T, S>::size() const
|
2023-01-10 17:52:00 +02:00
|
|
|
{
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|