[libcxx-commits] [libcxx] be54341 - [libc++] Split std::raw_storage_iterator out of <memory>

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 13 05:22:31 PDT 2021


Author: Louis Dionne
Date: 2021-04-13T08:21:35-04:00
New Revision: be54341cd2ffc970391b637de90aa05b134d9e89

URL: https://github.com/llvm/llvm-project/commit/be54341cd2ffc970391b637de90aa05b134d9e89
DIFF: https://github.com/llvm/llvm-project/commit/be54341cd2ffc970391b637de90aa05b134d9e89.diff

LOG: [libc++] Split std::raw_storage_iterator out of <memory>

Differential Revision: https://reviews.llvm.org/D100318

Added: 
    libcxx/include/__memory/raw_storage_iterator.h

Modified: 
    libcxx/include/CMakeLists.txt
    libcxx/include/memory

Removed: 
    


################################################################################
diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 0e0fdd324845..0d2718970257 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -19,6 +19,7 @@ set(files
   __memory/base.h
   __memory/compressed_pair.h
   __memory/pointer_traits.h
+  __memory/raw_storage_iterator.h
   __memory/temporary_buffer.h
   __memory/utilities.h
   __mutex_base

diff  --git a/libcxx/include/__memory/raw_storage_iterator.h b/libcxx/include/__memory/raw_storage_iterator.h
new file mode 100644
index 000000000000..52818755676c
--- /dev/null
+++ b/libcxx/include/__memory/raw_storage_iterator.h
@@ -0,0 +1,59 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H
+#define _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H
+
+#include <__config>
+#include <__memory/base.h> // addressof
+#include <cstddef>
+#include <iterator>
+#include <utility>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _OutputIterator, class _Tp>
+class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
+    : public iterator<output_iterator_tag,
+                      _Tp,                                         // purposefully not C++03
+                      ptr
diff _t,                                   // purposefully not C++03
+                      _Tp*,                                        // purposefully not C++03
+                      raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
+{
+private:
+    _OutputIterator __x_;
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
+    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
+    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
+        {::new ((void*)_VSTD::addressof(*__x_)) _Tp(__element); return *this;}
+#if _LIBCPP_STD_VER >= 14
+    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
+        {::new ((void*)_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;}
+#endif
+    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
+    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator  operator++(int)
+        {raw_storage_iterator __t(*this); ++__x_; return __t;}
+#if _LIBCPP_STD_VER >= 14
+    _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
+#endif
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif  // _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H

diff  --git a/libcxx/include/memory b/libcxx/include/memory
index fcfc10b01315..01cbced19315 100644
--- a/libcxx/include/memory
+++ b/libcxx/include/memory
@@ -685,6 +685,7 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
 #include <__memory/base.h>
 #include <__memory/compressed_pair.h>
 #include <__memory/pointer_traits.h>
+#include <__memory/raw_storage_iterator.h>
 #include <__memory/temporary_buffer.h>
 #include <__memory/utilities.h>
 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
@@ -813,33 +814,6 @@ void __construct_backward_with_exception_guarantees(_Alloc&, _Tp* __begin1, _Tp*
         _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
 }
 
-template <class _OutputIterator, class _Tp>
-class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
-    : public iterator<output_iterator_tag,
-                      _Tp,                                         // purposefully not C++03
-                      ptr
diff _t,                                   // purposefully not C++03
-                      _Tp*,                                        // purposefully not C++03
-                      raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
-{
-private:
-    _OutputIterator __x_;
-public:
-    _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
-    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
-    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
-        {::new ((void*)_VSTD::addressof(*__x_)) _Tp(__element); return *this;}
-#if _LIBCPP_STD_VER >= 14
-    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
-        {::new ((void*)_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;}
-#endif
-    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
-    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator  operator++(int)
-        {raw_storage_iterator __t(*this); ++__x_; return __t;}
-#if _LIBCPP_STD_VER >= 14
-    _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
-#endif
-};
-
 // default_delete
 
 template <class _Tp>


        


More information about the libcxx-commits mailing list