about summary refs log tree commit diff
path: root/absl/memory/memory.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/memory/memory.h')
-rw-r--r--absl/memory/memory.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/absl/memory/memory.h b/absl/memory/memory.h
index cd818cff4ffa..c43e156682fd 100644
--- a/absl/memory/memory.h
+++ b/absl/memory/memory.h
@@ -636,6 +636,39 @@ struct default_allocator_is_nothrow : std::true_type {};
 struct default_allocator_is_nothrow : std::false_type {};
 #endif
 
+namespace memory_internal {
+// TODO(b110200014): Implement proper backports
+template <typename ForwardIt>
+void DefaultConstruct(ForwardIt it) {
+  using value_type = typename std::iterator_traits<ForwardIt>::value_type;
+  ::new (static_cast<void*>(std::addressof(*it))) value_type;
+}  // namespace memory_internal
+
+#ifdef ABSL_HAVE_EXCEPTIONS
+template <typename ForwardIt, typename Size>
+void uninitialized_default_construct_n(ForwardIt first, Size size) {
+  for (ForwardIt cur = first; size > 0; static_cast<void>(++cur), --size) {
+    try {
+      absl::memory_internal::DefaultConstruct(cur);
+    } catch (...) {
+      using value_type = typename std::iterator_traits<ForwardIt>::value_type;
+      for (; first != cur; ++first) {
+        first->~value_type();
+      }
+      throw;
+    }
+  }
+}
+#else   // ABSL_HAVE_EXCEPTIONS
+template <typename ForwardIt, typename Size>
+void uninitialized_default_construct_n(ForwardIt first, Size size) {
+  for (; size > 0; static_cast<void>(++first), --size) {
+    absl::memory_internal::DefaultConstruct(first);
+  }
+}
+#endif  // ABSL_HAVE_EXCEPTIONS
+}  // namespace memory_internal
+
 }  // namespace absl
 
 #endif  // ABSL_MEMORY_MEMORY_H_