diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-06-24 11:15:37 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-06-24 11:15:37 +0200 |
commit | aabb1b516a89366247bad3b8b927ab33bd9114d0 (patch) | |
tree | 8614a3ab176b4aa306b93019cd50e674fc9a21ff | |
parent | 3bd426dce9d6c9e37dc08e9591a2caa6fa1fdb20 (diff) |
Make small_vector_allocator compatible with VC15u3 iterator debug mode
-rw-r--r-- | libbutl/small-vector.hxx | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/libbutl/small-vector.hxx b/libbutl/small-vector.hxx index f910ad9..84c25e8 100644 --- a/libbutl/small-vector.hxx +++ b/libbutl/small-vector.hxx @@ -48,6 +48,16 @@ namespace butl explicit small_vector_allocator (buffer_type* b) noexcept: buf_ (b) {} + // Required by VC15u3 when _ITERATOR_DEBUG_LEVEL is not 0. It allocates + // some extra stuff which cannot possibly come from the static buffer. + // +#if defined(_MSC_VER) && _MSC_VER >= 1911 + template <typename U> + explicit + small_vector_allocator (const small_vector_allocator<U, N>&) noexcept + : buf_ (nullptr) {} +#endif + // Allocator interface. // public: @@ -56,21 +66,25 @@ namespace butl T* allocate(std::size_t n) { - assert (n >= N); // We should never be asked for less than N. - - if (n <= N) + if (buf_ != nullptr) { - buf_->free_ = false; - return reinterpret_cast<T*> (buf_->data_); + assert (n >= N); // We should never be asked for less than N. + + if (n <= N) + { + buf_->free_ = false; + return reinterpret_cast<T*> (buf_->data_); + } + // Fall through. } - else - return static_cast<T*> (::operator new (sizeof (T) * n)); + + return static_cast<T*> (::operator new (sizeof (T) * n)); } void deallocate (void* p, std::size_t) noexcept { - if (p == buf_->data_) + if (buf_ != nullptr && p == buf_->data_) buf_->free_ = true; else ::operator delete (p); |