mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
upgrade util::Buffer
This commit is contained in:
parent
cbbc04edcf
commit
d41ec3a019
1 changed files with 14 additions and 0 deletions
|
|
@ -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];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue