summaryrefslogtreecommitdiffstats
path: root/src/common/scratch_buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/scratch_buffer.h')
-rw-r--r--src/common/scratch_buffer.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/common/scratch_buffer.h b/src/common/scratch_buffer.h
index 1245a5086..6fe907953 100644
--- a/src/common/scratch_buffer.h
+++ b/src/common/scratch_buffer.h
@@ -3,6 +3,9 @@
#pragma once
+#include <iterator>
+
+#include "common/concepts.h"
#include "common/make_unique_for_overwrite.h"
namespace Common {
@@ -16,6 +19,12 @@ namespace Common {
template <typename T>
class ScratchBuffer {
public:
+ using iterator = T*;
+ using const_iterator = const T*;
+ using value_type = T;
+ using element_type = T;
+ using iterator_category = std::contiguous_iterator_tag;
+
ScratchBuffer() = default;
explicit ScratchBuffer(size_t initial_capacity)
@@ -23,6 +32,10 @@ public:
buffer{Common::make_unique_for_overwrite<T[]>(initial_capacity)} {}
~ScratchBuffer() = default;
+ ScratchBuffer(const ScratchBuffer&) = delete;
+ ScratchBuffer& operator=(const ScratchBuffer&) = delete;
+ ScratchBuffer(ScratchBuffer&&) = default;
+ ScratchBuffer& operator=(ScratchBuffer&&) = default;
/// This will only grow the buffer's capacity if size is greater than the current capacity.
/// The previously held data will remain intact.
@@ -86,6 +99,12 @@ public:
return buffer_capacity;
}
+ void swap(ScratchBuffer& other) noexcept {
+ std::swap(last_requested_size, other.last_requested_size);
+ std::swap(buffer_capacity, other.buffer_capacity);
+ std::swap(buffer, other.buffer);
+ }
+
private:
size_t last_requested_size{};
size_t buffer_capacity{};