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___ITERATOR_BACK_INSERT_ITERATOR_H 11 #define _LIBCPP___ITERATOR_BACK_INSERT_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_PUSH_MACROS 25 #include <__undef_macros> 26 27 _LIBCPP_BEGIN_NAMESPACE_STD 28 29 _LIBCPP_SUPPRESS_DEPRECATED_PUSH 30 template <class _Container> 31 class _LIBCPP_TEMPLATE_VIS back_insert_iterator 32 #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) 33 : public iterator<output_iterator_tag, void, void, void, void> 34 #endif 35 { 36 _LIBCPP_SUPPRESS_DEPRECATED_POP 37 38 protected: 39 _Container* container; 40 41 public: 42 typedef output_iterator_tag iterator_category; 43 typedef void value_type; 44 #if _LIBCPP_STD_VER >= 20 45 typedef ptrdiff_t difference_type; 46 #else 47 typedef void difference_type; 48 #endif 49 typedef void pointer; 50 typedef void reference; 51 typedef _Container container_type; 52 53 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit back_insert_iterator(_Container& __x) 54 : container(std::addressof(__x)) {} 55 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 back_insert_iterator& 56 operator=(const typename _Container::value_type& __value) { 57 container->push_back(__value); 58 return *this; 59 } 60 #ifndef _LIBCPP_CXX03_LANG 61 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 back_insert_iterator& 62 operator=(typename _Container::value_type&& __value) { 63 container->push_back(std::move(__value)); 64 return *this; 65 } 66 #endif // _LIBCPP_CXX03_LANG 67 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 back_insert_iterator& operator*() { return *this; } 68 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 back_insert_iterator& operator++() { return *this; } 69 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 back_insert_iterator operator++(int) { return *this; } 70 71 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Container* __get_container() const { return container; } 72 }; 73 _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(back_insert_iterator); 74 75 template <class _Container> 76 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 back_insert_iterator<_Container> 77 back_inserter(_Container& __x) { 78 return back_insert_iterator<_Container>(__x); 79 } 80 81 _LIBCPP_END_NAMESPACE_STD 82 83 _LIBCPP_POP_MACROS 84 85 #endif // _LIBCPP___ITERATOR_BACK_INSERT_ITERATOR_H 86