BAN: Add Formatter specialization for Vector

This commit is contained in:
Bananymous 2023-02-10 02:58:14 +02:00
parent f68ae01d0c
commit 4f8fcf0bd7
1 changed files with 30 additions and 1 deletions

View File

@ -25,6 +25,7 @@ namespace BAN
Vector() = default; Vector() = default;
Vector(Vector<T>&&); Vector(Vector<T>&&);
Vector(const Vector<T>&); Vector(const Vector<T>&);
Vector(size_type, const T& = T());
~Vector(); ~Vector();
Vector<T>& operator=(Vector<T>&&); Vector<T>& operator=(Vector<T>&&);
@ -105,6 +106,8 @@ namespace BAN
bool operator==(const VectorIterator<T, CONST>& other) const { return m_data == other.m_data; } bool operator==(const VectorIterator<T, CONST>& other) const { return m_data == other.m_data; }
bool operator!=(const VectorIterator<T, CONST>& other) const { return !(*this == other); } bool operator!=(const VectorIterator<T, CONST>& other) const { return !(*this == other); }
operator bool() const { return m_data; }
private: private:
VectorIterator(data_type* data) : m_data(data) { } VectorIterator(data_type* data) : m_data(data) { }
@ -138,6 +141,15 @@ namespace BAN
m_size = other.m_size; m_size = other.m_size;
} }
template<typename T>
Vector<T>::Vector(size_type size, const T& value)
{
MUST(ensure_capacity(size));
for (size_type i = 0; i < size; i++)
new (m_data + i) T(value);
m_size = size;
}
template<typename T> template<typename T>
Vector<T>::~Vector() Vector<T>::~Vector()
{ {
@ -382,3 +394,20 @@ namespace BAN
} }
} }
namespace BAN::Formatter
{
template<typename F, typename T>
void print_argument_impl(F putc, const Vector<T>& vector, const ValueFormat& format)
{
putc('[');
for (typename Vector<T>::size_type i = 0; i < vector.size(); i++)
{
if (i != 0) putc(',');
print_argument_impl(putc, vector[i], format);
}
putc(']');
}
}