From be54341cd2ffc970391b637de90aa05b134d9e89 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Fri, 9 Apr 2021 14:45:18 -0400 Subject: [PATCH] [libc++] Split std::raw_storage_iterator out of Differential Revision: https://reviews.llvm.org/D100318 --- libcxx/include/CMakeLists.txt | 1 + libcxx/include/__memory/raw_storage_iterator.h | 59 ++++++++++++++++++++++++++ libcxx/include/memory | 28 +----------- 3 files changed, 61 insertions(+), 27 deletions(-) create mode 100644 libcxx/include/__memory/raw_storage_iterator.h diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt index 0e0fdd3..0d27189 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 0000000..5281875 --- /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 +#include +#include + +#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 _LIBCPP_TEMPLATE_VIS raw_storage_iterator + : public iterator&> // 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 fcfc10b..01cbced 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 _LIBCPP_TEMPLATE_VIS raw_storage_iterator - : public iterator&> // 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 -- 2.7.4