diff --git a/CMakeLists.txt b/CMakeLists.txt index e3c388f..d49806f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 0.18.14) +set(BLT_VERSION 0.18.15) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/arg_parse_variant_map.drawio b/arg_parse_variant_map.drawio index ac232d8..509f3a5 100644 --- a/arg_parse_variant_map.drawio +++ b/arg_parse_variant_map.drawio @@ -4,7 +4,7 @@ - + @@ -12,7 +12,7 @@ - + @@ -23,25 +23,25 @@ - + - + - + - + - + @@ -56,13 +56,13 @@ - + - + - + diff --git a/include/blt/std/memory.h b/include/blt/std/memory.h index 164e2da..69a9909 100644 --- a/include/blt/std/memory.h +++ b/include/blt/std/memory.h @@ -376,14 +376,14 @@ namespace blt constexpr inline T& operator[](size_t index) { if (index >= size()) - expand(index); + allocate_for(index); return buffer_[index]; } constexpr inline const T& operator[](size_t index) const { if (index >= size()) - expand(index); + allocate_for(index); return buffer_[index]; } @@ -461,13 +461,10 @@ namespace blt { delete_this(buffer_, size()); } - - private: - void expand(blt::size_t size) + + void expand(blt::size_t new_size) { - size = std::max(size_, size); - size = blt::mem::next_byte_allocation(size); - T* new_buffer = new T[size]; + T* new_buffer = new T[new_size]; if (buffer_ != nullptr) { if constexpr (std::is_trivially_copyable_v) @@ -486,7 +483,15 @@ namespace blt delete[] buffer_; } buffer_ = new_buffer; - size_ = size; + size_ = new_size; + } + + private: + void allocate_for(blt::size_t accessing_index) + { + accessing_index = std::max(size_, accessing_index); + accessing_index = blt::mem::next_byte_allocation(accessing_index); + expand(accessing_index); } inline void delete_this(T* buffer, blt::size_t)