From fefc83638fb69395d259ed245699310610429064 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 21 Aug 2018 08:05:11 -0700 Subject: Export of internal Abseil changes. -- b01400905d2ba23ec9f4541153532eefcfb0d5f5 by Mark Barolak : Tweak the comment for WebSafeBase64Unescape to make it match the style of the other comments in escaping.h. PiperOrigin-RevId: 209596034 -- dd35c55ee538ed458bb32494d87996d6624676df by Abseil Team : Migrate FixedArray from allocator pointers to references. Also updates the name to be more generic as nothing about the implementation was specific to FixedArray's StorageElement* PiperOrigin-RevId: 209438135 GitOrigin-RevId: b01400905d2ba23ec9f4541153532eefcfb0d5f5 Change-Id: I27304e4609708ec24fb19dce1e33215d7e4b5ae9 --- absl/memory/memory.h | 56 ++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 26 deletions(-) (limited to 'absl/memory') diff --git a/absl/memory/memory.h b/absl/memory/memory.h index c7caf8b..a80aab0 100644 --- a/absl/memory/memory.h +++ b/absl/memory/memory.h @@ -641,55 +641,59 @@ struct default_allocator_is_nothrow : std::false_type {}; #endif namespace memory_internal { -#ifdef ABSL_HAVE_EXCEPTIONS -template -void ConstructStorage(Allocator* alloc, StorageElement* first, - StorageElement* last, const Args&... args) { - for (StorageElement* cur = first; cur != last; ++cur) { +#ifdef ABSL_HAVE_EXCEPTIONS // ConstructRange +template +void ConstructRange(Allocator& alloc, Iterator first, Iterator last, + const Args&... args) { + for (Iterator cur = first; cur != last; ++cur) { try { - std::allocator_traits::construct(*alloc, cur, args...); + std::allocator_traits::construct(alloc, cur, args...); } catch (...) { while (cur != first) { --cur; - std::allocator_traits::destroy(*alloc, cur); + std::allocator_traits::destroy(alloc, cur); } throw; } } } -template -void CopyToStorageFromRange(Allocator* alloc, StorageElement* destination, - Iterator first, Iterator last) { - for (StorageElement* cur = destination; first != last; +#else // ABSL_HAVE_EXCEPTIONS // ConstructRange +template +void ConstructRange(Allocator& alloc, Iterator first, Iterator last, + const Args&... args) { + for (; first != last; ++first) { + std::allocator_traits::construct(alloc, first, args...); + } +} +#endif // ABSL_HAVE_EXCEPTIONS // ConstructRange + +#ifdef ABSL_HAVE_EXCEPTIONS // CopyRange +template +void CopyRange(Allocator& alloc, Iterator destination, InputIterator first, + InputIterator last) { + for (Iterator cur = destination; first != last; static_cast(++cur), static_cast(++first)) { try { - std::allocator_traits::construct(*alloc, cur, *first); + std::allocator_traits::construct(alloc, cur, *first); } catch (...) { while (cur != destination) { --cur; - std::allocator_traits::destroy(*alloc, cur); + std::allocator_traits::destroy(alloc, cur); } throw; } } } -#else // ABSL_HAVE_EXCEPTIONS -template -void ConstructStorage(Allocator* alloc, StorageElement* first, - StorageElement* last, const Args&... args) { - for (; first != last; ++first) { - std::allocator_traits::construct(*alloc, first, args...); - } -} -template -void CopyToStorageFromRange(Allocator* alloc, StorageElement* destination, - Iterator first, Iterator last) { +#else // ABSL_HAVE_EXCEPTIONS // CopyRange +template +void CopyRange(Allocator& alloc, Iterator destination, InputIterator first, + InputIterator last) { for (; first != last; static_cast(++destination), static_cast(++first)) { - std::allocator_traits::construct(*alloc, destination, *first); + std::allocator_traits::construct(alloc, destination, *first); } } -#endif // ABSL_HAVE_EXCEPTIONS +#endif // ABSL_HAVE_EXCEPTIONS // CopyRange } // namespace memory_internal } // namespace absl -- cgit v1.2.3