What do people do when they want to pass around little arrays on the audio thread when the arrays donβt have a fixed size? Something like this?
template<class T>
class MiniStackArray
{
public:
MiniStackArray(const std::initializer_list<T>& itemsToHold)
{
jassert(itemsToHold.size() < max_size);
auto limit{ std::min(itemsToHold.size(), max_size) };
auto iter{ itemsToHold.begin() };
for (auto i = 0; i < limit; i++)
{
items[i] = *iter++;
}
};
// Never have to implement iterators??
constexpr auto getSpan() { return std::span{ items, size }; }
private:
constexpr static size_t max_size{ 10 };
T items[max_size] {};
int size{};
};
I havenβt tested itβ¦ Is there a standard solution out there already?
Just answering my own question in case anyone searches the forum for the same thing:
1 Like
Thereβs also std::array which has a compile time size.
https://en.cppreference.com/w/cpp/container/array
Yeah, I saw an implementation where the βsmallVectorβ was indexing into a std::array actually.