20 #ifndef PLAYRHO_COMMON_ARRAYLIST_HPP
21 #define PLAYRHO_COMMON_ARRAYLIST_HPP
27 #include <initializer_list>
28 #include <type_traits>
33 template <
typename VALUE_TYPE, std::
size_t MAXSIZE,
typename SIZE_TYPE = std::
size_t>
62 template <std::
size_t COPY_MAXSIZE,
typename COPY_SIZE_TYPE,
typename = std::enable_if_t< COPY_MAXSIZE <= MAXSIZE >>
63 PLAYRHO_CONSTEXPR inline explicit ArrayList(const ArrayList<VALUE_TYPE, COPY_MAXSIZE, SIZE_TYPE>& copy):
65 m_elements{data(copy)}
71 template <std::
size_t COPY_MAXSIZE,
typename COPY_SIZE_TYPE,
typename = std::enable_if_t< COPY_MAXSIZE <= MAXSIZE >>
72 ArrayList& operator= (const ArrayList<VALUE_TYPE, COPY_MAXSIZE, COPY_SIZE_TYPE>& copy)
74 m_size = static_cast<SIZE_TYPE>(size(copy));
75 m_elements = data(copy);
79 template <std::
size_t SIZE,
typename = std::enable_if_t< SIZE <= MAXSIZE >>
80 explicit ArrayList(value_type (&value)[SIZE]) noexcept
82 for (auto&& elem: value)
88 ArrayList(std::initializer_list<value_type> list)
90 for (auto&& elem: list)
96 PLAYRHO_CONSTEXPR inline ArrayList& Append(const value_type& value)
102 PLAYRHO_CONSTEXPR inline
void push_back(const value_type& value) noexcept
104 assert(m_size < MAXSIZE);
105 m_elements[m_size] = value;
109 void size(
size_type value) noexcept
111 assert(value <= MAXSIZE);
115 void clear() noexcept
120 bool empty() const noexcept { return m_size == 0; }
122 bool add(value_type value) noexcept
124 if (m_size < MAXSIZE)
126 m_elements[m_size] = value;
133 reference operator[](
size_type index) noexcept
135 assert(index < MAXSIZE);
136 return m_elements[index];
139 PLAYRHO_CONSTEXPR inline const_reference operator[](
size_type index) const noexcept
141 assert(index < MAXSIZE);
142 return m_elements[index];
149 PLAYRHO_CONSTEXPR inline
size_type size() const noexcept { return m_size; }
153 PLAYRHO_CONSTEXPR inline
size_type max_size() const noexcept { return MAXSIZE; }
155 auto data() const noexcept { return m_elements.data(); }
157 po
inter begin() noexcept { return m_elements.data(); }
158 po
inter end() noexcept { return m_elements.data() + m_size; }
160 const_po
inter begin() const noexcept { return m_elements.data(); }
161 const_po
inter end() const noexcept { return m_elements.data() + m_size; }
164 size_type m_size =
size_type{0};
165 std::array<value_type,MAXSIZE> m_elements;
169 template <
typename T, std::
size_t S>
177 template <
typename T, std::
size_t S>
189 template<
class T, std::
size_t N,
typename SIZE_TYPE >
190 class tuple_size< playrho::ArrayList<T, N, SIZE_TYPE> >:
public integral_constant<std::size_t, N>
197 #endif // PLAYRHO_COMMON_ARRAYLIST_HPP