upgrade util::Buffer

This commit is contained in:
MihailRis 2024-10-24 09:56:57 +03:00
parent cbbc04edcf
commit d41ec3a019

View File

@ -2,6 +2,7 @@
#include <memory>
#include <cstring>
#include <initializer_list>
namespace util {
/// @brief Template similar to std::unique_ptr stores a buffer with its size
@ -26,6 +27,19 @@ namespace util {
std::memcpy(ptr.get(), src, length);
}
Buffer(std::initializer_list<T> values)
: ptr(std::make_unique<T>(values)), length(values.size()) {}
Buffer(std::nullptr_t) noexcept : ptr(nullptr), length(0) {}
inline bool operator==(std::nullptr_t) const noexcept {
return ptr == nullptr;
}
inline bool operator!=(std::nullptr_t) const noexcept {
return ptr != nullptr;
}
T& operator[](long long index) {
return ptr[index];
}