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 <__cstddef/ptrdiff_t.h>
15#include <__iterator/iterator.h>
16#include <__iterator/iterator_traits.h>
17#include <__memory/addressof.h>
18#include <__utility/move.h>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22#endif
23
24_LIBCPP_PUSH_MACROS
25#include <__undef_macros>
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR)
30
31template <class _OutputIterator, class _Tp>
32class _LIBCPP_DEPRECATED_IN_CXX17 raw_storage_iterator
33 : public __iterator_base<raw_storage_iterator<_OutputIterator, _Tp>, output_iterator_tag, void, void, void, void> {
34private:
35 _OutputIterator __x_;
36
37public:
38 typedef output_iterator_tag iterator_category;
39 typedef void value_type;
40# if _LIBCPP_STD_VER >= 20
41 typedef ptrdiff_t difference_type;
42# else
43 typedef void difference_type;
44# endif
45 typedef void pointer;
46 typedef void reference;
47
48 _LIBCPP_HIDE_FROM_ABI explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
49 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI raw_storage_iterator& operator*() { return *this; }
50 _LIBCPP_HIDE_FROM_ABI raw_storage_iterator& operator=(const _Tp& __element) {
51 ::new ((void*)std::addressof(*__x_)) _Tp(__element);
52 return *this;
53 }
54# if _LIBCPP_STD_VER >= 14
55 _LIBCPP_HIDE_FROM_ABI raw_storage_iterator& operator=(_Tp&& __element) {
56 ::new ((void*)std::addressof(*__x_)) _Tp(std::move(__element));
57 return *this;
58 }
59# endif
60 _LIBCPP_HIDE_FROM_ABI raw_storage_iterator& operator++() {
61 ++__x_;
62 return *this;
63 }
64 _LIBCPP_HIDE_FROM_ABI raw_storage_iterator operator++(int) {
65 raw_storage_iterator __t(*this);
66 ++__x_;
67 return __t;
68 }
69# if _LIBCPP_STD_VER >= 14
70 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _OutputIterator base() const { return __x_; }
71# endif
72};
73
74#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR)
75
76_LIBCPP_END_NAMESPACE_STD
77
78_LIBCPP_POP_MACROS
79
80#endif // _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H