diff options
author | Abseil Team <absl-team@google.com> | 2019-02-25T19·52-0800 |
---|---|---|
committer | Jon Cohen <cohenjon@google.com> | 2019-02-25T20·03-0500 |
commit | 308ce31528a7edfa39f5f6d36142278a0ae1bf45 (patch) | |
tree | 403fb7710f1ffecbc2851fa51009c651e49c3e25 /absl/container/inlined_vector.h | |
parent | 93d155bc4414f6c121bb1f19dba9fdb27c8943bc (diff) |
Export of internal Abseil changes.
-- e4e4a3460b64ba0571be217b04ec286bfac6b6bf by Tom Manshreck <shreck@google.com>: Internal change PiperOrigin-RevId: 235573160 -- 200323f1243e20c201d20bdab4c15a20346a27e5 by CJ Johnson <johnsoncj@google.com>: Removed unneded template parameter from InlinedVector internal functions PiperOrigin-RevId: 234910222 -- 2f1bba53c9ca40d0718c4c1edfcfea40edd5049e by CJ Johnson <johnsoncj@google.com>: Add comment highlighting the fact that the InlinedVector(&&, alloc) move constructor overload will still commit pointer theft in one case PiperOrigin-RevId: 234899890 GitOrigin-RevId: e4e4a3460b64ba0571be217b04ec286bfac6b6bf Change-Id: I0aabbabb96e9a057a55ed6b42591ea43b4609efe
Diffstat (limited to 'absl/container/inlined_vector.h')
-rw-r--r-- | absl/container/inlined_vector.h | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/absl/container/inlined_vector.h b/absl/container/inlined_vector.h index 5c9e6d97a420..e8daf6af248a 100644 --- a/absl/container/inlined_vector.h +++ b/absl/container/inlined_vector.h @@ -156,11 +156,11 @@ class InlinedVector { std::copy(first, last, std::back_inserter(*this)); } - // Creates a copy of `other` using `other`'s allocator. + // Creates a copy of an `other` inlined vector using `other`'s allocator. InlinedVector(const InlinedVector& other) : InlinedVector(other, other.allocator()) {} - // Creates a copy of `other` but with a specified allocator. + // Creates a copy of an `other` inlined vector using a specified allocator. InlinedVector(const InlinedVector& other, const allocator_type& alloc) : allocator_and_tag_(alloc) { reserve(other.size()); @@ -173,14 +173,19 @@ class InlinedVector { } } - // Creates an inlined vector by moving in the contents of `other`. + // Creates an inlined vector by moving in the contents of an `other` inlined + // vector without performing any allocations. If `other` contains allocated + // memory, the newly-created instance will take ownership of that memory + // (leaving `other` itself empty). However, if `other` does not contain any + // allocated memory, the new inlined vector will will perform element-wise + // move construction of `other`s elements. // - // NOTE: This move constructor does not allocate and only moves the underlying - // objects, so its `noexcept` specification depends on whether moving the - // underlying objects can throw or not. We assume: - // a) move constructors should only throw due to allocation failure and - // b) if `value_type`'s move constructor allocates, it uses the same - // allocation function as the `InlinedVector`'s allocator, so the move + // NOTE: since no allocation is performed for the inlined vector in either + // case, the `noexcept(...)` specification depends on whether moving the + // underlying objects can throw. We assume: + // a) Move constructors should only throw due to allocation failure. + // b) If `value_type`'s move constructor allocates, it uses the same + // allocation function as the `InlinedVector`'s allocator. Thus, the move // constructor is non-throwing if the allocator is non-throwing or // `value_type`'s move constructor is specified as `noexcept`. InlinedVector(InlinedVector&& other) noexcept( @@ -202,14 +207,19 @@ class InlinedVector { } } - // Creates an inlined vector by moving in the contents of `other`. + // Creates an inlined vector by moving in the contents of an `other` inlined + // vector, performing allocations with the specified `alloc` allocator. If + // `other`'s allocator is not equal to `alloc` and `other` contains allocated + // memory, this move constructor will create a new allocation. // - // NOTE: This move constructor allocates and subsequently moves the underlying - // objects, so its `noexcept` specification depends on whether the allocation - // can throw and whether moving the underlying objects can throw. Based on the - // same assumptions as above, the `noexcept` specification is dominated by - // whether the allocation can throw regardless of whether `value_type`'s move - // constructor is specified as `noexcept`. + // NOTE: since allocation is performed in this case, this constructor can + // only be `noexcept` if the specified allocator is also `noexcept`. If this + // is the case, or if `other` contains allocated memory, this constructor + // performs element-wise move construction of its contents. + // + // Only in the case where `other`'s allocator is equal to `alloc` and `other` + // contains allocated memory will the newly created inlined vector take + // ownership of `other`'s allocated memory. InlinedVector(InlinedVector&& other, const allocator_type& alloc) noexcept( absl::allocator_is_nothrow<allocator_type>::value) : allocator_and_tag_(alloc) { @@ -1110,9 +1120,9 @@ class InlinedVector { } } - template <typename ForwardIterator> - void AssignForwardRange(ForwardIterator first, ForwardIterator last) { - static_assert(IsAtLeastForwardIterator<ForwardIterator>::value, ""); + template <typename ForwardIt> + void AssignForwardRange(ForwardIt first, ForwardIt last) { + static_assert(IsAtLeastForwardIterator<ForwardIt>::value, ""); auto length = std::distance(first, last); @@ -1134,9 +1144,9 @@ class InlinedVector { } } - template <typename ForwardIterator> - void AppendForwardRange(ForwardIterator first, ForwardIterator last) { - static_assert(IsAtLeastForwardIterator<ForwardIterator>::value, ""); + template <typename ForwardIt> + void AppendForwardRange(ForwardIt first, ForwardIt last) { + static_assert(IsAtLeastForwardIterator<ForwardIt>::value, ""); auto length = std::distance(first, last); reserve(size() + length); @@ -1162,10 +1172,10 @@ class InlinedVector { return it_pair.first; } - template <typename ForwardIterator> - iterator InsertWithForwardRange(const_iterator position, - ForwardIterator first, ForwardIterator last) { - static_assert(IsAtLeastForwardIterator<ForwardIterator>::value, ""); + template <typename ForwardIt> + iterator InsertWithForwardRange(const_iterator position, ForwardIt first, + ForwardIt last) { + static_assert(IsAtLeastForwardIterator<ForwardIt>::value, ""); assert(position >= begin() && position <= end()); if (ABSL_PREDICT_FALSE(first == last)) |