Replace std::array with C array

This commit is contained in:
King_DuckZ 2021-06-07 21:54:46 +02:00
parent c9b2d36491
commit 180f79fae9

View file

@ -18,7 +18,6 @@
#ifndef idFC25566D624140559C54B39FFFE52F04
#define idFC25566D624140559C54B39FFFE52F04
#include <array>
#include <type_traits>
#include <stdexcept>
#if !defined(INT_CONV_WITHOUT_HELPERS)
@ -36,7 +35,7 @@ namespace dhandy {
public:
constexpr static const std::size_t capacity = S;
using iterator = typename std::array<T, S>::iterator;
using iterator = T*;
constexpr ReversedSizedArray() = default;
~ReversedSizedArray() = default;
@ -45,11 +44,11 @@ namespace dhandy {
constexpr const T operator[] (std::size_t idx) const { if (idx >= size()) throw std::out_of_range("Out of bound array access"); return m_data[idx + m_curr + 1]; }
constexpr T& operator[] (std::size_t idx) { if (idx >= size()) throw std::out_of_range("Out of bound array access"); return m_data[idx + m_curr + 1]; }
constexpr void push_front (const T& itm) { if (size() == S) throw std::length_error("ReversedSizedArray is full"); m_data[m_curr--] = itm; }
constexpr const T* data() const { return m_data.data() + m_curr + 1; }
constexpr const T* base_ptr() const { return m_data.data(); }
constexpr iterator begin() { return m_data.begin() + m_curr + 1; }
constexpr iterator end() { return m_data.end(); }
constexpr const T& back() const { return *(m_data.data() + S - 1); }
constexpr const T* data() const { return m_data + m_curr + 1; }
constexpr const T* base_ptr() const { return m_data; }
constexpr iterator begin() { return m_data + m_curr + 1; }
constexpr iterator end() { return m_data + S; }
constexpr const T& back() const { return *(m_data + S - 1); }
template <typename V>
constexpr V to() const { return V(data(), size() - (not empty() and not back() ? 1 : 0)); }
@ -68,13 +67,13 @@ namespace dhandy {
#endif
private:
std::array<T, S> m_data {};
T m_data[S];
std::size_t m_curr {S - 1};
};
namespace implem {
template <typename T, std::size_t S, std::size_t... Indices>
constexpr auto elements_or_empty_to_tuple (const std::array<T, S>& elems, std::size_t from_idx, std::index_sequence<Indices...>) {
constexpr auto elements_or_empty_to_tuple (const T (&elems)[S], std::size_t from_idx, std::index_sequence<Indices...>) {
return std::make_tuple((from_idx + Indices < S ? elems[from_idx + Indices] : T{})...);
}
} //namespace implem