1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H 11 #define _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H 12 13 #include <__config> 14 #include <__iterator/iterator.h> 15 #include <__iterator/iterator_traits.h> 16 #include <__memory/addressof.h> 17 #include <__utility/move.h> 18 #include <cstddef> 19 20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 21 # pragma GCC system_header 22 #endif 23 24 _LIBCPP_BEGIN_NAMESPACE_STD 25 26 #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR) 27 28 _LIBCPP_SUPPRESS_DEPRECATED_PUSH 29 template <class _OutputIterator, class _Tp> 30 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 raw_storage_iterator 31 #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) 32 : public iterator<output_iterator_tag, void, void, void, void> 33 #endif 34 { 35 _LIBCPP_SUPPRESS_DEPRECATED_POP 36 private: 37 _OutputIterator __x_; 38 public: 39 typedef output_iterator_tag iterator_category; 40 typedef void value_type; 41 #if _LIBCPP_STD_VER > 17 42 typedef ptrdiff_t difference_type; 43 #else 44 typedef void difference_type; 45 #endif 46 typedef void pointer; 47 typedef void reference; 48 49 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} 50 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;} 51 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element) 52 {::new ((void*)_VSTD::addressof(*__x_)) _Tp(__element); return *this;} 53 #if _LIBCPP_STD_VER >= 14 54 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element) 55 {::new ((void*)_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;} 56 #endif 57 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} 58 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) 59 {raw_storage_iterator __t(*this); ++__x_; return __t;} 60 #if _LIBCPP_STD_VER >= 14 61 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; } 62 #endif 63 }; 64 65 #endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR) 66 67 _LIBCPP_END_NAMESPACE_STD 68 69 #endif // _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H 70