xref: /netbsd-src/external/apache2/llvm/dist/libcxx/include/__memory/raw_storage_iterator.h (revision 4d6fc14bc9b0c5bf3e30be318c143ee82cadd108)
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 <__memory/addressof.h>
15 #include <cstddef>
16 #include <iterator>
17 #include <utility>
18 
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 #pragma GCC system_header
21 #endif
22 
23 _LIBCPP_PUSH_MACROS
24 #include <__undef_macros>
25 
26 _LIBCPP_BEGIN_NAMESPACE_STD
27 
28 #if _LIBCPP_STD_VER <= 17
29 
30 template <class _OutputIterator, class _Tp>
31 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 raw_storage_iterator
32     : public iterator<output_iterator_tag,
33                       _Tp,                                         // purposefully not C++03
34                       ptrdiff_t,                                   // purposefully not C++03
35                       _Tp*,                                        // purposefully not C++03
36                       raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
37 {
38 private:
39     _OutputIterator __x_;
40 public:
raw_storage_iterator(_OutputIterator __x)41     _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
42     _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
43     _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
44         {::new ((void*)_VSTD::addressof(*__x_)) _Tp(__element); return *this;}
45 #if _LIBCPP_STD_VER >= 14
46     _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
47         {::new ((void*)_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;}
48 #endif
49     _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
50     _LIBCPP_INLINE_VISIBILITY raw_storage_iterator  operator++(int)
51         {raw_storage_iterator __t(*this); ++__x_; return __t;}
52 #if _LIBCPP_STD_VER >= 14
base()53     _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
54 #endif
55 };
56 
57 #endif // _LIBCPP_STD_VER <= 17
58 
59 _LIBCPP_END_NAMESPACE_STD
60 
61 _LIBCPP_POP_MACROS
62 
63 #endif // _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H
64