#ifndef STATIC_VECTOR_HH
#define STATIC_VECTOR_HH

#include <cassert>
#include <cstddef>

// This is a _very_ minimal implementation of the following (we can easily
// extend this when the need arises).
//
//    static_vector
//    A dynamically-resizable vector with fixed capacity and embedded storage
//    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0843r2.html
//
// For us the main purpose of this class is to use it during constexpr
// (compile-time) calculations. Because for now, it's no yet possible to use
// heap memory in constexpr functions (there are proposals to loosen this
// restriction in future C++ standards).

template<typename T, size_t N>
class static_vector
{
	T data[N] = {};
	size_t sz = 0;

public:
	constexpr static_vector() = default;

	[[nodiscard]] constexpr const T* begin() const noexcept { return data; }
	[[nodiscard]] constexpr const T* end()   const noexcept { return data + sz; }

	[[nodiscard]] constexpr size_t size() const { return sz; }

	[[nodiscard]] constexpr       T& operator[](size_t index)       { return data[index]; }
	[[nodiscard]] constexpr const T& operator[](size_t index) const { return data[index]; }

	constexpr void push_back(const T& a) { assert(sz < N); data[sz++] = a; }

	constexpr void clear() { sz = 0; }
};

#endif
