From d41ec3a0196c285ac9d2b5c45f714eae89a3a815 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 24 Oct 2024 09:56:57 +0300 Subject: [PATCH] upgrade util::Buffer --- src/util/Buffer.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/util/Buffer.hpp b/src/util/Buffer.hpp index a721e646..cfc5451f 100644 --- a/src/util/Buffer.hpp +++ b/src/util/Buffer.hpp @@ -2,6 +2,7 @@ #include #include +#include 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 values) + : ptr(std::make_unique(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]; }