diff options
Diffstat (limited to 'src/common/scratch_buffer.h')
| -rw-r--r-- | src/common/scratch_buffer.h | 19 |
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 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <iterator> | ||
| 7 | |||
| 8 | #include "common/concepts.h" | ||
| 6 | #include "common/make_unique_for_overwrite.h" | 9 | #include "common/make_unique_for_overwrite.h" |
| 7 | 10 | ||
| 8 | namespace Common { | 11 | namespace Common { |
| @@ -16,6 +19,12 @@ namespace Common { | |||
| 16 | template <typename T> | 19 | template <typename T> |
| 17 | class ScratchBuffer { | 20 | class ScratchBuffer { |
| 18 | public: | 21 | public: |
| 22 | using iterator = T*; | ||
| 23 | using const_iterator = const T*; | ||
| 24 | using value_type = T; | ||
| 25 | using element_type = T; | ||
| 26 | using iterator_category = std::contiguous_iterator_tag; | ||
| 27 | |||
| 19 | ScratchBuffer() = default; | 28 | ScratchBuffer() = default; |
| 20 | 29 | ||
| 21 | explicit ScratchBuffer(size_t initial_capacity) | 30 | explicit ScratchBuffer(size_t initial_capacity) |
| @@ -23,6 +32,10 @@ public: | |||
| 23 | buffer{Common::make_unique_for_overwrite<T[]>(initial_capacity)} {} | 32 | buffer{Common::make_unique_for_overwrite<T[]>(initial_capacity)} {} |
| 24 | 33 | ||
| 25 | ~ScratchBuffer() = default; | 34 | ~ScratchBuffer() = default; |
| 35 | ScratchBuffer(const ScratchBuffer&) = delete; | ||
| 36 | ScratchBuffer& operator=(const ScratchBuffer&) = delete; | ||
| 37 | ScratchBuffer(ScratchBuffer&&) = default; | ||
| 38 | ScratchBuffer& operator=(ScratchBuffer&&) = default; | ||
| 26 | 39 | ||
| 27 | /// This will only grow the buffer's capacity if size is greater than the current capacity. | 40 | /// This will only grow the buffer's capacity if size is greater than the current capacity. |
| 28 | /// The previously held data will remain intact. | 41 | /// The previously held data will remain intact. |
| @@ -86,6 +99,12 @@ public: | |||
| 86 | return buffer_capacity; | 99 | return buffer_capacity; |
| 87 | } | 100 | } |
| 88 | 101 | ||
| 102 | void swap(ScratchBuffer& other) noexcept { | ||
| 103 | std::swap(last_requested_size, other.last_requested_size); | ||
| 104 | std::swap(buffer_capacity, other.buffer_capacity); | ||
| 105 | std::swap(buffer, other.buffer); | ||
| 106 | } | ||
| 107 | |||
| 89 | private: | 108 | private: |
| 90 | size_t last_requested_size{}; | 109 | size_t last_requested_size{}; |
| 91 | size_t buffer_capacity{}; | 110 | size_t buffer_capacity{}; |