2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___ITERATOR_FRONT_INSERT_ITERATOR_H
11 #define _LIBCPP___ITERATOR_FRONT_INSERT_ITERATOR_H
14 #include <__iterator/iterator.h>
15 #include <__iterator/iterator_traits.h>
16 #include <__memory/addressof.h>
17 #include <__utility/move.h>
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 # pragma GCC system_header
25 #include <__undef_macros>
27 _LIBCPP_BEGIN_NAMESPACE_STD
29 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
30 template <class _Container
>
31 class _LIBCPP_TEMPLATE_VIS front_insert_iterator
32 #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
33 : public iterator
<output_iterator_tag
, void, void, void, void>
36 _LIBCPP_SUPPRESS_DEPRECATED_POP
38 _Container
* container
;
40 typedef output_iterator_tag iterator_category
;
41 typedef void value_type
;
42 #if _LIBCPP_STD_VER >= 20
43 typedef ptrdiff_t difference_type
;
45 typedef void difference_type
;
48 typedef void reference
;
49 typedef _Container container_type
;
51 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
explicit front_insert_iterator(_Container
& __x
) : container(_VSTD::addressof(__x
)) {}
52 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator
& operator=(const typename
_Container::value_type
& __value
)
53 {container
->push_front(__value
); return *this;}
54 #ifndef _LIBCPP_CXX03_LANG
55 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator
& operator=(typename
_Container::value_type
&& __value
)
56 {container
->push_front(_VSTD::move(__value
)); return *this;}
57 #endif // _LIBCPP_CXX03_LANG
58 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator
& operator*() {return *this;}
59 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator
& operator++() {return *this;}
60 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 front_insert_iterator
operator++(int) {return *this;}
62 _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(front_insert_iterator
);
64 template <class _Container
>
65 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
66 front_insert_iterator
<_Container
>
67 front_inserter(_Container
& __x
)
69 return front_insert_iterator
<_Container
>(__x
);
72 _LIBCPP_END_NAMESPACE_STD
76 #endif // _LIBCPP___ITERATOR_FRONT_INSERT_ITERATOR_H